1 package com.thinkaurelius.titan.diskstorage.cassandra;
3 import static org.junit.Assert.assertEquals;
4 import static org.junit.Assert.assertFalse;
5 import static org.junit.Assert.assertTrue;
7 import java.util.Collections;
10 import com.thinkaurelius.titan.diskstorage.BackendException;
11 import com.thinkaurelius.titan.diskstorage.configuration.Configuration;
12 import com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration;
13 import org.junit.Test;
14 import org.junit.experimental.categories.Category;
15 import org.slf4j.Logger;
16 import org.slf4j.LoggerFactory;
18 import com.google.common.collect.ImmutableMap;
19 import com.thinkaurelius.titan.diskstorage.KeyColumnValueStoreTest;
20 import com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreFeatures;
21 import com.thinkaurelius.titan.testcategory.OrderedKeyStoreTests;
22 import com.thinkaurelius.titan.testcategory.UnorderedKeyStoreTests;
24 public abstract class AbstractCassandraStoreTest extends KeyColumnValueStoreTest {
26 private static final Logger log =
27 LoggerFactory.getLogger(AbstractCassandraStoreTest.class);
28 private static final String TEST_CF_NAME = "testcf";
29 private static final String DEFAULT_COMPRESSOR_PACKAGE = "org.apache.cassandra.io.compress";
31 public abstract ModifiableConfiguration getBaseStorageConfiguration();
33 public abstract AbstractCassandraStoreManager openStorageManager(Configuration c) throws BackendException;
36 @Category({ UnorderedKeyStoreTests.class })
37 public void testUnorderedConfiguration() {
38 if (!manager.getFeatures().hasUnorderedScan()) {
40 "Can't test key-unordered features on incompatible store. "
41 + "This warning could indicate reduced test coverage and "
42 + "a broken JUnit configuration. Skipping test {}.",
43 name.getMethodName());
47 StoreFeatures features = manager.getFeatures();
48 assertFalse(features.isKeyOrdered());
49 assertFalse(features.hasLocalKeyPartition());
53 @Category({ OrderedKeyStoreTests.class })
54 public void testOrderedConfiguration() {
55 if (!manager.getFeatures().hasOrderedScan()) {
57 "Can't test key-ordered features on incompatible store. "
58 + "This warning could indicate reduced test coverage and "
59 + "a broken JUnit configuration. Skipping test {}.",
60 name.getMethodName());
64 StoreFeatures features = manager.getFeatures();
65 assertTrue(features.isKeyOrdered());
69 public void testDefaultCFCompressor() throws BackendException {
71 final String cf = TEST_CF_NAME + "_snappy";
73 AbstractCassandraStoreManager mgr = openStorageManager();
77 Map<String, String> defaultCfCompressionOps =
78 new ImmutableMap.Builder<String, String>()
79 .put("sstable_compression", DEFAULT_COMPRESSOR_PACKAGE + "." + AbstractCassandraStoreManager.CF_COMPRESSION_TYPE.getDefaultValue())
80 .put("chunk_length_kb", "64")
83 assertEquals(defaultCfCompressionOps, mgr.getCompressionOptions(cf));
87 public void testCustomCFCompressor() throws BackendException {
89 final String cname = "DeflateCompressor";
91 final String cf = TEST_CF_NAME + "_gzip";
93 ModifiableConfiguration config = getBaseStorageConfiguration();
94 config.set(AbstractCassandraStoreManager.CF_COMPRESSION_TYPE,cname);
95 config.set(AbstractCassandraStoreManager.CF_COMPRESSION_BLOCK_SIZE,ckb);
97 AbstractCassandraStoreManager mgr = openStorageManager(config);
99 // N.B.: clearStorage() truncates CFs but does not delete them
100 mgr.openDatabase(cf);
102 final Map<String, String> expected = ImmutableMap
103 .<String, String> builder()
104 .put("sstable_compression",
105 DEFAULT_COMPRESSOR_PACKAGE + "." + cname)
106 .put("chunk_length_kb", String.valueOf(ckb)).build();
108 assertEquals(expected, mgr.getCompressionOptions(cf));
112 public void testDisableCFCompressor() throws BackendException {
114 final String cf = TEST_CF_NAME + "_nocompress";
116 ModifiableConfiguration config = getBaseStorageConfiguration();
117 config.set(AbstractCassandraStoreManager.CF_COMPRESSION,false);
118 AbstractCassandraStoreManager mgr = openStorageManager(config);
120 // N.B.: clearStorage() truncates CFs but does not delete them
121 mgr.openDatabase(cf);
123 assertEquals(Collections.emptyMap(), mgr.getCompressionOptions(cf));
127 public void testTTLSupported() throws Exception {
128 StoreFeatures features = manager.getFeatures();
129 assertTrue(features.hasCellTTL());
133 public AbstractCassandraStoreManager openStorageManager() throws BackendException {
134 return openStorageManager(getBaseStorageConfiguration());