summaryrefslogtreecommitdiffstats
path: root/src/test/java/com/thinkaurelius/titan/diskstorage/cassandra/AbstractCassandraStoreTest.java
blob: 623a7428b2003b367c190dd49e9a2356322483bf (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
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
package com.thinkaurelius.titan.diskstorage.cassandra;

import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;

import java.util.Collections;
import java.util.Map;

import com.thinkaurelius.titan.diskstorage.BackendException;
import com.thinkaurelius.titan.diskstorage.configuration.Configuration;
import com.thinkaurelius.titan.diskstorage.configuration.ModifiableConfiguration;
import org.junit.Test;
import org.junit.experimental.categories.Category;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.google.common.collect.ImmutableMap;
import com.thinkaurelius.titan.diskstorage.KeyColumnValueStoreTest;
import com.thinkaurelius.titan.diskstorage.keycolumnvalue.StoreFeatures;
import com.thinkaurelius.titan.testcategory.OrderedKeyStoreTests;
import com.thinkaurelius.titan.testcategory.UnorderedKeyStoreTests;

public abstract class AbstractCassandraStoreTest extends KeyColumnValueStoreTest {

    private static final Logger log =
            LoggerFactory.getLogger(AbstractCassandraStoreTest.class);
    private static final String TEST_CF_NAME = "testcf";
    private static final String DEFAULT_COMPRESSOR_PACKAGE = "org.apache.cassandra.io.compress";

    public abstract ModifiableConfiguration getBaseStorageConfiguration();

    public abstract AbstractCassandraStoreManager openStorageManager(Configuration c) throws BackendException;

    @Test
    @Category({ UnorderedKeyStoreTests.class })
    public void testUnorderedConfiguration() {
        if (!manager.getFeatures().hasUnorderedScan()) {
            log.warn(
                "Can't test key-unordered features on incompatible store.  "
                + "This warning could indicate reduced test coverage and "
                + "a broken JUnit configuration.  Skipping test {}.",
                name.getMethodName());
            return;
        }

        StoreFeatures features = manager.getFeatures();
        assertFalse(features.isKeyOrdered());
        assertFalse(features.hasLocalKeyPartition());
    }

    @Test
    @Category({ OrderedKeyStoreTests.class })
    public void testOrderedConfiguration() {
        if (!manager.getFeatures().hasOrderedScan()) {
            log.warn(
                "Can't test key-ordered features on incompatible store.  "
                + "This warning could indicate reduced test coverage and "
                + "a broken JUnit configuration.  Skipping test {}.",
                name.getMethodName());
            return;
        }

        StoreFeatures features = manager.getFeatures();
        assertTrue(features.isKeyOrdered());
    }

    @Test
    public void testDefaultCFCompressor() throws BackendException {

        final String cf = TEST_CF_NAME + "_snappy";

        AbstractCassandraStoreManager mgr = openStorageManager();

        mgr.openDatabase(cf);

        Map<String, String> defaultCfCompressionOps =
                new ImmutableMap.Builder<String, String>()
                .put("sstable_compression", DEFAULT_COMPRESSOR_PACKAGE + "." + AbstractCassandraStoreManager.CF_COMPRESSION_TYPE.getDefaultValue())
                .put("chunk_length_kb", "64")
                .build();

        assertEquals(defaultCfCompressionOps, mgr.getCompressionOptions(cf));
    }

    @Test
    public void testCustomCFCompressor() throws BackendException {

        final String cname = "DeflateCompressor";
        final int ckb = 128;
        final String cf = TEST_CF_NAME + "_gzip";

        ModifiableConfiguration config = getBaseStorageConfiguration();
        config.set(AbstractCassandraStoreManager.CF_COMPRESSION_TYPE,cname);
        config.set(AbstractCassandraStoreManager.CF_COMPRESSION_BLOCK_SIZE,ckb);

        AbstractCassandraStoreManager mgr = openStorageManager(config);

        // N.B.: clearStorage() truncates CFs but does not delete them
        mgr.openDatabase(cf);

        final Map<String, String> expected = ImmutableMap
                .<String, String> builder()
                .put("sstable_compression",
                        DEFAULT_COMPRESSOR_PACKAGE + "." + cname)
                .put("chunk_length_kb", String.valueOf(ckb)).build();

        assertEquals(expected, mgr.getCompressionOptions(cf));
    }

    @Test
    public void testDisableCFCompressor() throws BackendException {

        final String cf = TEST_CF_NAME + "_nocompress";

        ModifiableConfiguration config = getBaseStorageConfiguration();
        config.set(AbstractCassandraStoreManager.CF_COMPRESSION,false);
        AbstractCassandraStoreManager mgr = openStorageManager(config);

        // N.B.: clearStorage() truncates CFs but does not delete them
        mgr.openDatabase(cf);

        assertEquals(Collections.emptyMap(), mgr.getCompressionOptions(cf));
    }

    @Test
    public void testTTLSupported() throws Exception {
        StoreFeatures features = manager.getFeatures();
        assertTrue(features.hasCellTTL());
    }

    @Override
    public AbstractCassandraStoreManager openStorageManager() throws BackendException {
        return openStorageManager(getBaseStorageConfiguration());
    }
}