aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorBrendan Tschaen <ctschaen@att.com>2019-09-23 17:47:47 +0000
committerGerrit Code Review <gerrit@onap.org>2019-09-23 17:47:47 +0000
commitc8adfc5ea25d6ffd45edd5213195ce0c4568b57f (patch)
treed1ce124c5d664b243af10a1e8e963928fae5db90
parentcca9a44dfd587b2dbac873b24b98620160356d9b (diff)
parentc5256c018d0eef9bc9f6831ba60af0584bf01b38 (diff)
Merge "Test case for deadlock detection"
-rw-r--r--src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java60
1 files changed, 60 insertions, 0 deletions
diff --git a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
index 98afe858..5669580a 100644
--- a/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
+++ b/src/test/java/org/onap/music/unittests/TstRestMusicLockAPI.java
@@ -439,6 +439,48 @@ public class TstRestMusicLockAPI {
assertEquals(400, response.getStatus());
}
+ @SuppressWarnings("unchecked")
+ @Test
+ public void test_deadlock() throws Exception {
+ System.out.println("Testing deadlock");
+ createAndInsertIntoTable();
+ insertAnotherIntoTable();
+
+ // Process 1 creates and acquires a lock on row 1
+ JsonLock jsonLock = createJsonLock(LockType.WRITE);
+ 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 responseAcquire1 =
+ lock.accquireLock(lockRefCreate1, "1", "1", authorization, "abc66001-d857-4e90-b1e5-df98a3d40ce6", appName);
+
+ // Process 2 creates and acquires a lock on row 2
+ Response responseCreate2 = lock.createLockReference(lockName + "2", "1", "1", authorization,
+ "abcde002-d857-4e90-b1e5-df98a3d40ce6", jsonLock, "process2", appName);
+ Map<String, Object> respMapCreate2 = (Map<String, Object>) responseCreate2.getEntity();
+ String lockRefCreate2 = ((Map<String, String>) respMapCreate2.get("lock")).get("lock");
+
+ Response responseAcquire2 =
+ lock.accquireLock(lockRefCreate2, "1", "1", authorization, "abc66002-d857-4e90-b1e5-df98a3d40ce6", appName);
+
+ // Process 2 creates a lock on row 1
+ Response responseCreate3 = lock.createLockReference(lockName, "1", "1", authorization,
+ "abcde003-d857-4e90-b1e5-df98a3d40ce6", jsonLock, "process2", appName);
+
+ // Process 1 creates a lock on row 2, causing deadlock
+ Response responseCreate4 = lock.createLockReference(lockName + "2", "1", "1", authorization,
+ "abcde004-d857-4e90-b1e5-df98a3d40ce6", jsonLock, "process1", appName);
+ Map<String, Object> respMapCreate4 = (Map<String, Object>) responseCreate4.getEntity();
+
+ System.out.println("Status: " + responseCreate4.getStatus() + ". Entity " + responseCreate4.getEntity());
+ assertEquals(400, responseCreate4.getStatus());
+ assertTrue(respMapCreate4.containsKey("error"));
+ assertTrue( ((String)respMapCreate4.get("error")).toLowerCase().indexOf("deadlock") > -1 );
+ }
+
+
// Ignoring since this is now a duplicate of delete lock ref.
@Test
@Ignore
@@ -569,6 +611,24 @@ public class TstRestMusicLockAPI {
authorization, jsonInsert, keyspaceName, tableName);
}
+ private void insertAnotherIntoTable() throws Exception {
+ createTable();
+
+ JsonInsert jsonInsert = new JsonInsert();
+ Map<String, String> consistencyInfo = new HashMap<>();
+ Map<String, Object> values = new HashMap<>();
+ values.put("uuid", "cccccccc-d857-4e90-b1e5-df98a3d40cd6");
+ values.put("emp_name", "testname2");
+ values.put("emp_salary", 700);
+ consistencyInfo.put("type", "eventual");
+ jsonInsert.setConsistencyInfo(consistencyInfo);
+ jsonInsert.setKeyspaceName(keyspaceName);
+ jsonInsert.setTableName(tableName);
+ jsonInsert.setValues(values);
+ Response response = data.insertIntoTable("1", "1", "1", "abcdef00-d857-4e90-b1e5-df98a3d40ce6", appName,
+ authorization, jsonInsert, keyspaceName, tableName);
+ }
+
private JsonLock createJsonLock(LockType lockType) {
JsonLock jsonLock = new JsonLock();
jsonLock.setLockType(lockType);