aboutsummaryrefslogtreecommitdiffstats
path: root/src/test/java/org/onap/music/unittests/TestCassaLockStore.java
blob: ff048b336c8ee38884fbb96187960b551edd68f7 (plain)
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
package org.onap.music.unittests;

import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

import com.datastax.driver.core.Cluster;
import com.datastax.driver.core.Session;
import org.onap.music.datastore.CassandraClusterBuilder;
import org.onap.music.datastore.MusicDataStore;
import org.onap.music.datastore.PreparedQueryObject;
import org.onap.music.exceptions.MusicQueryException;
import org.onap.music.exceptions.MusicServiceException;
import org.onap.music.lockingservice.cassandra.CassaLockStore;
import org.onap.music.main.MusicCore;
import org.onap.music.main.MusicUtil;

public class TestCassaLockStore {
	
	
	public static void main(String[] args) {
		
		
		try {
			Cluster cluster = CassandraClusterBuilder.connectSmart(MusicUtil.getMyCassaHost());
			Session session = cluster.connect();
			CassaLockStore lockStore = new CassaLockStore(new MusicDataStore(cluster, session));
			String keyspace = "ks_testLockStore";
			String table = "table_testLockStore";

			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");

            
            queryObject = new PreparedQueryObject();
            queryObject.appendQueryString("CREATE TABLE " + keyspace + "." + table + " (name text PRIMARY KEY, count varint);");
            MusicCore.createTable(keyspace, table, queryObject, "eventual");              

			
			lockStore.createLockQueue(keyspace, table);
			
			String lockRefb1 = lockStore.genLockRefandEnQueue(keyspace, table, "bharath");
			
			
			
			String lockRefc1 = lockStore.genLockRefandEnQueue(keyspace, table, "cat");

			String lockRefc2 = lockStore.genLockRefandEnQueue(keyspace, table, "cat");


			assert(lockStore.peekLockQueue(keyspace, table, "cat").equals(lockRefc1));
			
			assert(!lockStore.peekLockQueue(keyspace, table, "cat").equals(lockRefc2));

			
			assert(lockStore.peekLockQueue(keyspace, table, "bharath").equals(lockRefb1));
			
			
			lockStore.deQueueLockRef(keyspace, table, "cat", lockRefc1);
			
			assert(lockStore.peekLockQueue(keyspace, table, "cat").equals(lockRefc2));

		} catch (MusicServiceException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} catch (MusicQueryException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}


}