summaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap
diff options
context:
space:
mode:
authorTschaen, Brendan <ctschaen@att.com>2019-09-25 14:54:46 -0400
committerTschaen, Brendan <ctschaen@att.com>2019-09-26 13:52:01 -0400
commit90d35b7f55d1ea3eb6ccf8218d9ac42412fd0d90 (patch)
tree972d5110063f0f56405ba1c29f0c8534f17f01e8 /src/test/java/org/onap
parentc8adfc5ea25d6ffd45edd5213195ce0c4568b57f (diff)
Read lock promotion
Change-Id: Ib2515c728503fb729e6ecc2e09973bbfa9e2e317 Issue-ID: MUSIC-508 Signed-off-by: Tschaen, Brendan <ctschaen@att.com>
Diffstat (limited to 'src/test/java/org/onap')
-rw-r--r--src/test/java/org/onap/music/unittests/CassandraCQL.java6
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java130
2 files changed, 135 insertions, 1 deletions
diff --git a/src/test/java/org/onap/music/unittests/CassandraCQL.java b/src/test/java/org/onap/music/unittests/CassandraCQL.java
index 32072145..7b116bc8 100644
--- a/src/test/java/org/onap/music/unittests/CassandraCQL.java
+++ b/src/test/java/org/onap/music/unittests/CassandraCQL.java
@@ -42,9 +42,10 @@ import java.util.UUID;
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.PreparedQueryObject;
-
+import org.onap.music.lockingservice.cassandra.LockType;
import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
+import com.datastax.driver.extras.codecs.enums.EnumNameCodec;
public class CassandraCQL {
public static final String createAdminKeyspace = "CREATE KEYSPACE admin WITH REPLICATION = "
@@ -235,6 +236,9 @@ public class CassandraCQL {
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
Cluster cluster = new Cluster.Builder().withoutJMXReporting().withoutMetrics().addContactPoint(address).withPort(9142).build();
cluster.getConfiguration().getSocketOptions().setReadTimeoutMillis(5000);
+ EnumNameCodec<LockType> lockTypeCodec = new EnumNameCodec<LockType>(LockType.class);
+ cluster.getConfiguration().getCodecRegistry().register(lockTypeCodec);
+
Session session = cluster.connect();
return new MusicDataStore(cluster, session);
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
index 5669580a..e9321d25 100644
--- a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
@@ -480,6 +480,136 @@ public class TstRestMusicLockAPI {
assertTrue( ((String)respMapCreate4.get("error")).toLowerCase().indexOf("deadlock") > -1 );
}
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void test_lockPromotion() throws Exception {
+ System.out.println("Testing lock promotion");
+ createAndInsertIntoTable();
+ insertAnotherIntoTable();
+
+ // creates a lock 1
+ JsonLock jsonLock = createJsonLock(LockType.READ);
+ Response responseCreate1 = lock.createLockReference(lockName, "1", "1", authorization,
+ "abcde001-d857-4e90-b1e5-df98a3d40ce6", jsonLock, "process1", appName);
+ Map<String, Object> respMapCreate1 = (Map<String, Object>) responseCreate1.getEntity();
+ String lockRefCreate1 = ((Map<String, String>) respMapCreate1.get("lock")).get("lock");
+
+ Response respMapPromote = lock.promoteLock(lockRefCreate1, "1", "1", authorization);
+ System.out.println("Status: " + respMapPromote.getStatus() + ". Entity " + respMapPromote.getEntity());
+
+ assertEquals(200, respMapPromote.getStatus());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void test_lockPromotionReadWrite() throws Exception {
+ System.out.println("Testing lock promotion with read and writes");
+ createAndInsertIntoTable();
+ insertAnotherIntoTable();
+
+ // creates a lock 1
+ JsonLock jsonLockRead = createJsonLock(LockType.READ);
+ Response responseCreate1 = lock.createLockReference(lockName, "1", "1", authorization,
+ "abcde001-d857-4e90-b1e5-df98a3d40ce6", jsonLockRead, "process1", appName);
+ Map<String, Object> respMapCreate1 = (Map<String, Object>) responseCreate1.getEntity();
+ String lockRefCreate1 = ((Map<String, String>) respMapCreate1.get("lock")).get("lock");
+
+ JsonLock jsonLockWrite = createJsonLock(LockType.WRITE);
+ Response responseCreate2 = lock.createLockReference(lockName, "1", "1", authorization,
+ "abcde001-d857-4e90-b1e5-df98a3d40ce6", jsonLockWrite, "process1", appName);
+ Map<String, Object> respMapCreate2 = (Map<String, Object>) responseCreate2.getEntity();
+ String lockRefCreate2 = ((Map<String, String>) respMapCreate2.get("lock")).get("lock");
+
+ Response respMapPromote = lock.promoteLock(lockRefCreate1, "1", "1", authorization);
+ System.out.println("Status: " + respMapPromote.getStatus() + ". Entity " + respMapPromote.getEntity());
+
+ assertEquals(200, respMapPromote.getStatus());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void test_lockPromotionWriteRead() throws Exception {
+ System.out.println("Testing lock promotion with reads not at top of queue");
+ createAndInsertIntoTable();
+ insertAnotherIntoTable();
+
+ // creates a lock 1
+ JsonLock jsonLockWrite = createJsonLock(LockType.WRITE);
+ Response responseCreate2 = lock.createLockReference(lockName, "1", "1", authorization,
+ "abcde001-d857-4e90-b1e5-df98a3d40ce6", jsonLockWrite, "process1", appName);
+ Map<String, Object> respMapCreate2 = (Map<String, Object>) responseCreate2.getEntity();
+ String lockRefCreate2 = ((Map<String, String>) respMapCreate2.get("lock")).get("lock");
+
+ // creates a lock 2
+ JsonLock jsonLockRead = createJsonLock(LockType.READ);
+ Response responseCreate1 = lock.createLockReference(lockName, "1", "1", authorization,
+ "abcde001-d857-4e90-b1e5-df98a3d40ce6", jsonLockRead, "process1", appName);
+ Map<String, Object> respMapCreate1 = (Map<String, Object>) responseCreate1.getEntity();
+ String lockRefCreate1 = ((Map<String, String>) respMapCreate1.get("lock")).get("lock");
+
+ Response respMapPromote = lock.promoteLock(lockRefCreate1, "1", "1", authorization);
+ System.out.println("Status: " + respMapPromote.getStatus() + ". Entity " + respMapPromote.getEntity());
+
+ assertEquals(200, respMapPromote.getStatus());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void test_lockPromotion2Reads() throws Exception {
+ System.out.println("Testing lock promotion w/ 2 ReadLocks");
+ createAndInsertIntoTable();
+ insertAnotherIntoTable();
+
+ // creates a lock 1
+ JsonLock jsonLockRead = createJsonLock(LockType.READ);
+ Response responseCreate1 = lock.createLockReference(lockName, "1", "1", authorization,
+ "abcde001-d857-4e90-b1e5-df98a3d40ce6", jsonLockRead, "process1", appName);
+ Map<String, Object> respMapCreate1 = (Map<String, Object>) responseCreate1.getEntity();
+ String lockRefCreate1 = ((Map<String, String>) respMapCreate1.get("lock")).get("lock");
+
+ Response responseCreate2 = lock.createLockReference(lockName, "1", "1", authorization,
+ "abcde001-d857-4e90-b1e5-df98a3d40ce6", jsonLockRead, "process1", appName);
+ Map<String, Object> respMapCreate2 = (Map<String, Object>) responseCreate1.getEntity();
+ String lockRefCreate2 = ((Map<String, String>) respMapCreate1.get("lock")).get("lock");
+
+ Response respMapPromote = lock.promoteLock(lockRefCreate1, "1", "1", authorization);
+ System.out.println("Status: " + respMapPromote.getStatus() + ". Entity " + respMapPromote.getEntity());
+
+ assertEquals(400, respMapPromote.getStatus());
+ }
+
+ @SuppressWarnings("unchecked")
+ @Test
+ public void test_2lockPromotions() throws Exception {
+ System.out.println("Testing 2 lock promotions");
+ createAndInsertIntoTable();
+ insertAnotherIntoTable();
+
+ // creates a lock 1
+ JsonLock jsonLockRead = createJsonLock(LockType.READ);
+ Response responseCreate1 = lock.createLockReference(lockName, "1", "1", authorization,
+ "abcde001-d857-4e90-b1e5-df98a3d40ce6", jsonLockRead, "process1", appName);
+ Map<String, Object> respMapCreate1 = (Map<String, Object>) responseCreate1.getEntity();
+ String lockRefCreate1 = ((Map<String, String>) respMapCreate1.get("lock")).get("lock");
+
+ Response responseCreate2 = lock.createLockReference(lockName, "1", "1", authorization,
+ "abcde001-d857-4e90-b1e5-df98a3d40ce6", jsonLockRead, "process1", appName);
+ Map<String, Object> respMapCreate2 = (Map<String, Object>) responseCreate2.getEntity();
+ String lockRefCreate2 = ((Map<String, String>) respMapCreate2.get("lock")).get("lock");
+
+ Response respMapPromote = lock.promoteLock(lockRefCreate1, "1", "1", authorization);
+ System.out.println("Status: " + respMapPromote.getStatus() + ". Entity " + respMapPromote.getEntity());
+
+ assertEquals(400, respMapPromote.getStatus());
+
+ Response respMap2Promote = lock.promoteLock(lockRefCreate2, "1", "1", authorization);
+ System.out.println("Status: " + respMap2Promote.getStatus() + ". Entity " + respMap2Promote.getEntity());
+
+ assertEquals(400, respMapPromote.getStatus());
+ }
+
+
// Ignoring since this is now a duplicate of delete lock ref.
@Test