aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/music/unittests/TestCassaLockStore.java
diff options
context:
space:
mode:
authorTschaen, Brendan <ctschaen@att.com>2018-10-16 20:22:35 -0400
committerTschaen, Brendan <ctschaen@att.com>2018-10-16 20:27:37 -0400
commit46350c084766789ea59e83f1917c57c81d653048 (patch)
tree3463279fcee9c26d190d854324bbd7f86422fe2e /src/test/java/org/onap/music/unittests/TestCassaLockStore.java
parent287bdcbb5482f94df091c3b7b766fed0007efa2e (diff)
Include Cassandra locking
Change-Id: I085acf8336d5f27782ee12768846a5befd3ee60d Issue-ID: MUSIC-148 Signed-off-by: Tschaen, Brendan <ctschaen@att.com>
Diffstat (limited to 'src/test/java/org/onap/music/unittests/TestCassaLockStore.java')
-rw-r--r--src/test/java/org/onap/music/unittests/TestCassaLockStore.java71
1 files changed, 71 insertions, 0 deletions
diff --git a/src/test/java/org/onap/music/unittests/TestCassaLockStore.java b/src/test/java/org/onap/music/unittests/TestCassaLockStore.java
new file mode 100644
index 00000000..bf058121
--- /dev/null
+++ b/src/test/java/org/onap/music/unittests/TestCassaLockStore.java
@@ -0,0 +1,71 @@
+package org.onap.music.unittests;
+
+import java.util.HashMap;
+import java.util.Map;
+import java.util.UUID;
+
+import org.onap.music.datastore.CassaLockStore;
+import org.onap.music.datastore.PreparedQueryObject;
+import org.onap.music.exceptions.MusicQueryException;
+import org.onap.music.exceptions.MusicServiceException;
+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();
+ }
+ }
+
+
+}