1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
|
package org.onap.music.unittests;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.lockingservice.cassandra.CassaLockStore;
import org.onap.music.main.MusicCore;
public class TestCassaLockStore {
public static void main(String[] args) {
try {
CassaLockStore lockStore = new CassaLockStore();
String keyspace = "ks_testLockStore";
String table = "table_testLockStore";
Map<String,Object> replicationInfo = new HashMap<String, Object>();
replicationInfo.put("'class'", "'SimpleStrategy'");
replicationInfo.put("'replication_factor'", 1);
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject.appendQueryString("CREATE KEYSPACE " + keyspace + " WITH REPLICATION = " + replicationInfo.toString().replaceAll("=", ":"));
MusicCore.nonKeyRelatedPut(queryObject, "eventual");
queryObject = new PreparedQueryObject();
queryObject.appendQueryString("CREATE TABLE " + keyspace + "." + table + " (name text PRIMARY KEY, count varint);");
MusicCore.createTable(keyspace, table, queryObject, "eventual");
lockStore.createLockQueue(keyspace, table);
String lockRefb1 = lockStore.genLockRefandEnQueue(keyspace, table, "bharath");
String lockRefc1 = lockStore.genLockRefandEnQueue(keyspace, table, "cat");
String lockRefc2 = lockStore.genLockRefandEnQueue(keyspace, table, "cat");
assert(lockStore.peekLockQueue(keyspace, table, "cat").equals(lockRefc1));
assert(!lockStore.peekLockQueue(keyspace, table, "cat").equals(lockRefc2));
assert(lockStore.peekLockQueue(keyspace, table, "bharath").equals(lockRefb1));
lockStore.deQueueLockRef(keyspace, table, "cat", lockRefc1);
assert(lockStore.peekLockQueue(keyspace, table, "cat").equals(lockRefc2));
} catch (MusicServiceException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (MusicQueryException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
}
|