aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/music/unittests/MusicLockStoreTest.java
diff options
context:
space:
mode:
Diffstat (limited to 'src/test/java/org/onap/music/unittests/MusicLockStoreTest.java')
-rw-r--r--src/test/java/org/onap/music/unittests/MusicLockStoreTest.java134
1 files changed, 47 insertions, 87 deletions
diff --git a/src/test/java/org/onap/music/unittests/MusicLockStoreTest.java b/src/test/java/org/onap/music/unittests/MusicLockStoreTest.java
index a027fd93..c1348d2f 100644
--- a/src/test/java/org/onap/music/unittests/MusicLockStoreTest.java
+++ b/src/test/java/org/onap/music/unittests/MusicLockStoreTest.java
@@ -24,7 +24,11 @@ package org.onap.music.unittests;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
+import java.util.List;
+
+import org.junit.After;
import org.junit.AfterClass;
+import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Test;
@@ -44,15 +48,19 @@ import com.datastax.driver.core.TableMetadata;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
public class MusicLockStoreTest {
- static CassaDataStore dataStore;
+ static CassaDataStore dataStore;
static CassaLockStore lockStore;
static PreparedQueryObject testObject;
@BeforeClass
- public static void init() {
+ public static void init() throws MusicServiceException, MusicQueryException {
dataStore = CassandraCQL.connectToEmbeddedCassandra();
lockStore = new CassaLockStore(dataStore);
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.createKeySpace);
+ dataStore.executePut(testObject, "eventual");
+ testObject = new PreparedQueryObject();
}
@AfterClass
@@ -64,106 +72,58 @@ public class MusicLockStoreTest {
}
- @Test
- public void Test1_SetUp() throws MusicServiceException, MusicQueryException {
- boolean result = false;
+ @Before
+ public void beforeEachTest() throws MusicServiceException, MusicQueryException {
testObject = new PreparedQueryObject();
testObject.appendQueryString(CassandraCQL.createKeySpace);
- result = dataStore.executePut(testObject, "eventual");;
+ dataStore.executePut(testObject, "eventual");
testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.createTableEmployees);
- result = dataStore.executePut(testObject, "eventual");
- assertEquals(true, result);
-
}
-
- @Test
- public void Test_createLockQueue() throws MusicServiceException, MusicQueryException {
- String keyspace = "testCassa";
- String table = "employees";
- /*
- * above two hard coded since this depends on the keyspace and table created in the
- * CassandraCQL class. Need to change this..
- */
- boolean result = lockStore.createLockQueue(keyspace,table);
- assertEquals(true, result);
- }
-
- @Test
- public void Test3_ExecutePut_critical_insert() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedInsertQueryObject2();
- boolean result = dataStore.executePut(testObject, "Critical");
- assertEquals(true, result);
- }
-
- @Test
- public void Test4_ExecutePut_eventual_update() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedUpdateQueryObject();
- boolean result = false;
- result = dataStore.executePut(testObject, "eventual");
- assertEquals(true, result);
- }
-
- @Test
- public void Test5_ExecuteEventualGet() throws MusicServiceException, MusicQueryException {
+ @After
+ public void afterEachTest() throws MusicServiceException, MusicQueryException {
+ testObject = new PreparedQueryObject();
+ testObject.appendQueryString(CassandraCQL.dropKeyspace);
+ dataStore.executePut(testObject, "eventual");
testObject = new PreparedQueryObject();
- testObject.appendQueryString(CassandraCQL.selectALL);
- boolean result = false;
- int count = 0;
- ResultSet output = null;
- output = dataStore.executeOneConsistencyGet(testObject);
- System.out.println(output);
- ;
- for (Row row : output) {
- count++;
- System.out.println(row.toString());
- }
- if (count == 2) {
- result = true;
- }
- assertEquals(true, result);
}
+
@Test
- public void Test6_ExecuteCriticalGet() throws MusicServiceException, MusicQueryException {
- testObject = CassandraCQL.setPreparedGetQuery();
- boolean result = false;
- int count = 0;
- ResultSet output = null;
- output = dataStore.executeQuorumConsistencyGet(testObject);
- System.out.println(output);
- ;
- for (Row row : output) {
- count++;
- System.out.println(row.toString());
- }
- if (count == 1) {
- result = true;
- }
+ public void Test_createLockQueue() throws MusicServiceException, MusicQueryException {
+ boolean result = lockStore.createLockQueue(CassandraCQL.keyspace,CassandraCQL.table);
assertEquals(true, result);
}
- @Test(expected = NullPointerException.class)
- public void Test7_exception() {
- PreparedQueryObject queryObject = null;
- try {
- dataStore.executePut(queryObject, "critical");
- } catch (MusicQueryException | MusicServiceException e) {
- System.out.println(e.getMessage());
- }
- }
-
@Test
- public void Test8_columnDataType() {
- DataType data = dataStore.returnColumnDataType("testCassa", "employees", "empName");
- String datatype = data.toString();
- assertEquals("text",datatype);
+ public void Test_testGetLockQueue() throws MusicServiceException, MusicQueryException {
+ lockStore.createLockQueue(CassandraCQL.keyspace, CassandraCQL.table);
+ String lockRef = lockStore.genLockRefandEnQueue(CassandraCQL.keyspace, CassandraCQL.table, "test");
+ List<String> lockRefs = lockStore.getLockQueue(CassandraCQL.keyspace, CassandraCQL.table, "test");
+
+ assertEquals(1, lockRefs.size());
+ assertEquals(lockRef, lockRefs.get(0));
+
+ //add more locks
+ for (int i=0; i<20; i++) {
+ lockStore.genLockRefandEnQueue(CassandraCQL.keyspace, CassandraCQL.table, "test");
+ }
+ lockRefs = lockStore.getLockQueue(CassandraCQL.keyspace, CassandraCQL.table, "test");
+ assertEquals(21, lockRefs.size());
+ assertEquals(lockRef, lockRefs.get(0));
}
+
@Test
- public void Test8_columnMetdaData() {
- TableMetadata data = dataStore.returnColumnMetadata("testCassa", "employees");
- assertNotNull(data);
+ public void Test_testGetLockQueueSize() throws MusicServiceException, MusicQueryException {
+ lockStore.createLockQueue(CassandraCQL.keyspace, CassandraCQL.table);
+ String lockRef = lockStore.genLockRefandEnQueue(CassandraCQL.keyspace, CassandraCQL.table, "test");
+ assertEquals(1, lockStore.getLockQueueSize(CassandraCQL.keyspace, CassandraCQL.table, "test"));
+
+ //add more locks
+ for (int i=0; i<20; i++) {
+ lockStore.genLockRefandEnQueue(CassandraCQL.keyspace, CassandraCQL.table, "test");
+ }
+ assertEquals(21, lockStore.getLockQueueSize(CassandraCQL.keyspace, CassandraCQL.table, "test"));
}
}