diff options
author | Tschaen, Brendan <ctschaen@att.com> | 2018-11-27 17:29:52 -0500 |
---|---|---|
committer | Tschaen, Brendan <ctschaen@att.com> | 2018-11-27 17:30:40 -0500 |
commit | 6e7f430bcf94d7f7bd4cd81b886d610b358c024e (patch) | |
tree | e7e72644d93643ff9458a9d4b4c187761d4de532 /src/test | |
parent | 0922e1c8a4e095668707a3973b6e8a5ee2fe3329 (diff) |
Add getLockQueue to music api
Change-Id: Ib7db75a2df76ee7dcca92d69d07c3b947736deab
Issue-ID: MUSIC-204
Signed-off-by: Tschaen, Brendan <ctschaen@att.com>
Diffstat (limited to 'src/test')
-rw-r--r-- | src/test/java/org/onap/music/unittests/CassandraCQL.java | 20 | ||||
-rw-r--r-- | src/test/java/org/onap/music/unittests/MusicLockStoreTest.java | 134 |
2 files changed, 59 insertions, 95 deletions
diff --git a/src/test/java/org/onap/music/unittests/CassandraCQL.java b/src/test/java/org/onap/music/unittests/CassandraCQL.java index a9cbe109..098f5e7a 100644 --- a/src/test/java/org/onap/music/unittests/CassandraCQL.java +++ b/src/test/java/org/onap/music/unittests/CassandraCQL.java @@ -50,32 +50,36 @@ import org.onap.music.datastore.PreparedQueryObject; public class CassandraCQL { + public static final String keyspace = "testCassa"; + + public static final String table = "employees"; + public static final String createKeySpace = - "CREATE KEYSPACE IF NOT EXISTS testCassa WITH replication = " + "CREATE KEYSPACE IF NOT EXISTS " + keyspace + " WITH replication = " +"{'class':'SimpleStrategy','replication_factor':1} AND durable_writes = true;"; - public static final String dropKeyspace = "DROP KEYSPACE IF EXISTS testCassa"; + public static final String dropKeyspace = "DROP KEYSPACE IF EXISTS " + keyspace; public static final String createTableEmployees = - "CREATE TABLE IF NOT EXISTS testCassa.employees " + "CREATE TABLE IF NOT EXISTS " + keyspace + "." + table + " " + "(vector_ts text,empId uuid,empName text,empSalary varint,address Map<text,text>,PRIMARY KEY (empName)) " + "WITH comment='Financial Info of employees' " + "AND compression={'sstable_compression':'DeflateCompressor','chunk_length_kb':64} " + "AND compaction={'class':'SizeTieredCompactionStrategy','min_threshold':6};"; public static final String insertIntoTablePrepared1 = - "INSERT INTO testCassa.employees (vector_ts,empId,empName,empSalary) VALUES (?,?,?,?); "; + "INSERT INTO " + keyspace + "." + table + " (vector_ts,empId,empName,empSalary) VALUES (?,?,?,?); "; public static final String insertIntoTablePrepared2 = - "INSERT INTO testCassa.employees (vector_ts,empId,empName,empSalary,address) VALUES (?,?,?,?,?);"; + "INSERT INTO " + keyspace + "." + table + " (vector_ts,empId,empName,empSalary,address) VALUES (?,?,?,?,?);"; - public static final String selectALL = "SELECT * FROM testCassa.employees;"; + public static final String selectALL = "SELECT * FROM " + keyspace + "." + table + ";"; public static final String selectSpecific = - "SELECT * FROM testCassa.employees WHERE empName= ?;"; + "SELECT * FROM " + keyspace + "." + table + " WHERE empName= ?;"; public static final String updatePreparedQuery = - "UPDATE testCassa.employees SET vector_ts=?,address= ? WHERE empName= ?;"; + "UPDATE " + keyspace + "." + table + " SET vector_ts=?,address= ? WHERE empName= ?;"; public static final String deleteFromTable = " "; 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")); } } |