first commit for new repo
[sdc/sdc-titan-cassandra.git] / src / test / java / com / thinkaurelius / titan / graphdb / CassandraGraphTest.java
1 package com.thinkaurelius.titan.graphdb;
2
3 import com.thinkaurelius.titan.CassandraStorageSetup;
4 import com.thinkaurelius.titan.core.TitanFactory;
5 import com.thinkaurelius.titan.diskstorage.cassandra.AbstractCassandraStoreManager;
6 import com.thinkaurelius.titan.diskstorage.configuration.ConfigElement;
7 import com.thinkaurelius.titan.diskstorage.configuration.WriteConfiguration;
8 import com.thinkaurelius.titan.graphdb.database.StandardTitanGraph;
9 import com.thinkaurelius.titan.graphdb.transaction.StandardTitanTx;
10 import org.junit.BeforeClass;
11 import org.junit.Test;
12
13 import static org.junit.Assert.assertEquals;
14 import static org.junit.Assert.assertTrue;
15 import static com.thinkaurelius.titan.diskstorage.cassandra.AbstractCassandraStoreManager.*;
16
17 /**
18  * @author Joshua Shinavier (http://fortytwo.net)
19  */
20 public abstract class CassandraGraphTest extends TitanGraphTest {
21
22     @BeforeClass
23     public static void startCassandra() {
24         CassandraStorageSetup.startCleanEmbedded();
25     }
26
27     @Override
28     protected boolean isLockingOptimistic() {
29         return true;
30     }
31
32     @Test
33     public void testHasTTL() throws Exception {
34         assertTrue(features.hasCellTTL());
35     }
36
37     @Test
38     public void testGraphConfigUsedByThreadBoundTx() {
39         close();
40         WriteConfiguration wc = getConfiguration();
41         wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
42         wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "LOCAL_QUORUM");
43
44         graph = (StandardTitanGraph) TitanFactory.open(wc);
45
46         StandardTitanTx tx = (StandardTitanTx)graph.getCurrentThreadTx();
47         assertEquals("ALL",
48                 tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
49                         .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
50         assertEquals("LOCAL_QUORUM",
51                 tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
52                         .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
53     }
54
55     @Test
56     public void testGraphConfigUsedByTx() {
57         close();
58         WriteConfiguration wc = getConfiguration();
59         wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "TWO");
60         wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "THREE");
61
62         graph = (StandardTitanGraph) TitanFactory.open(wc);
63
64         StandardTitanTx tx = (StandardTitanTx)graph.newTransaction();
65         assertEquals("TWO",
66                 tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
67                         .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
68         assertEquals("THREE",
69                 tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
70                         .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
71         tx.rollback();
72     }
73
74     @Test
75     public void testCustomConfigUsedByTx() {
76         close();
77         WriteConfiguration wc = getConfiguration();
78         wc.set(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ALL");
79         wc.set(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "ALL");
80
81         graph = (StandardTitanGraph) TitanFactory.open(wc);
82
83         StandardTitanTx tx = (StandardTitanTx)graph.buildTransaction()
84                 .customOption(ConfigElement.getPath(CASSANDRA_READ_CONSISTENCY), "ONE")
85                 .customOption(ConfigElement.getPath(CASSANDRA_WRITE_CONSISTENCY), "TWO").start();
86
87         assertEquals("ONE",
88                 tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
89                         .get(AbstractCassandraStoreManager.CASSANDRA_READ_CONSISTENCY));
90         assertEquals("TWO",
91                 tx.getTxHandle().getBaseTransactionConfig().getCustomOptions()
92                         .get(AbstractCassandraStoreManager.CASSANDRA_WRITE_CONSISTENCY));
93         tx.rollback();
94     }
95 }