1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
|
package org.onap.music.unittests;
import static org.junit.Assert.assertEquals;
import java.util.HashMap;
import java.util.Map;
import org.junit.AfterClass;
import org.junit.BeforeClass;
import org.junit.FixMethodOrder;
import org.junit.Ignore;
import org.junit.Test;
import org.junit.runners.MethodSorters;
import org.onap.music.datastore.CassaDataStore;
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;
import com.datastax.driver.core.ResultSet;
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
@Ignore
public class TestMusicCore {
static PreparedQueryObject testObject;
static CassaDataStore dataStore;
String keyspace = "MusicCoreUnitTestKp";
String table = "SampleTable";
@BeforeClass
public static void init() {
System.out.println("TestMusicCore Init");
try {
MusicCore.mDstoreHandle = CassandraCQL.connectToEmbeddedCassandra();
MusicCore.mLockHandle = new CassaLockStore(MusicCore.mDstoreHandle);
} catch (Exception e) {
e.printStackTrace();
}
}
@AfterClass
public static void close() throws MusicServiceException, MusicQueryException {
System.out.println("After class TestMusicCore");
testObject = new PreparedQueryObject();
testObject.appendQueryString(CassandraCQL.dropKeyspace);
MusicCore.eventualPut(testObject);
MusicCore.mDstoreHandle.close();
}
@Test
public void Test1_createKeyspace() throws MusicServiceException, MusicQueryException {
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");
//check with the system table in cassandra
queryObject = new PreparedQueryObject();
String systemQuery = "SELECT keyspace_name FROM system_schema.keyspaces where keyspace_name='"+keyspace.toLowerCase()+"';";
queryObject.appendQueryString(systemQuery);
ResultSet rs = dataStore.executeOneConsistencyGet(queryObject);
assert rs.all().size()> 0;
}
@Test
public void Test1_createTable() throws MusicServiceException, MusicQueryException {
PreparedQueryObject queryObject = new PreparedQueryObject();
queryObject.appendQueryString(
"CREATE TABLE " + keyspace + "." + table + " (name text PRIMARY KEY, count varint);");
MusicCore.createTable(keyspace, table, queryObject, "eventual");
//check with the system table in cassandra
queryObject = new PreparedQueryObject();
String systemQuery = "SELECT table_name FROM system_schema.tables where keyspace_name='"+keyspace.toLowerCase()+"' and table_name='"+table.toLowerCase()+"';";
queryObject.appendQueryString(systemQuery);
ResultSet rs = dataStore.executeOneConsistencyGet(queryObject);
assert rs.all().size()> 0;
}
}
|