DATACASS-198: Upgrade for Cassandra 2.1 Support
Task-Url: https://jira.spring.io/browse/DATACASS-198
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2015 the original author or authors.
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -21,8 +21,6 @@ import java.util.UUID;
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.thrift.transport.TTransportException;
|
||||
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -36,7 +34,6 @@ import com.datastax.driver.core.Session;
|
||||
* Abstract base integration test class that starts an embedded Cassandra instance.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class AbstractEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@@ -55,11 +52,12 @@ public class AbstractEmbeddedCassandraIntegrationTest {
|
||||
/**
|
||||
* The session connected to the system keyspace.
|
||||
*/
|
||||
protected Session system;
|
||||
protected static Session system;
|
||||
|
||||
/**
|
||||
* The {@link Cluster} that'session connected to Cassandra.
|
||||
* The {@link Cluster} that's connected to Cassandra.
|
||||
*/
|
||||
protected Cluster cluster;
|
||||
protected static Cluster cluster;
|
||||
|
||||
public static String randomKeyspaceName() {
|
||||
return Utils.randomKeyspaceName();
|
||||
@@ -76,17 +74,22 @@ public class AbstractEmbeddedCassandraIntegrationTest {
|
||||
return Cluster.builder().addContactPoint(CASSANDRA_HOST).withPort(CASSANDRA_NATIVE_PORT).build();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void connect() {
|
||||
/**
|
||||
* Ensures that the cluster is created and that the session {@link #SYSTEM} is connected to it.
|
||||
*/
|
||||
public static void ensureClusterConnection() {
|
||||
|
||||
this.cluster = cluster();
|
||||
this.system = cluster.connect();
|
||||
// check cluster
|
||||
if (cluster == null) {
|
||||
cluster = cluster();
|
||||
}
|
||||
|
||||
if (system == null) {
|
||||
system = cluster.connect();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void disconnect() {
|
||||
|
||||
this.system.close();
|
||||
this.cluster.close();
|
||||
public AbstractEmbeddedCassandraIntegrationTest() {
|
||||
ensureClusterConnection();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -93,23 +93,23 @@ public class CqlTableSpecificationAssertions {
|
||||
|
||||
switch (tableOption) {
|
||||
|
||||
case BLOOM_FILTER_FP_CHANCE:
|
||||
case READ_REPAIR_CHANCE:
|
||||
case DCLOCAL_READ_REPAIR_CHANCE:
|
||||
assertEquals((Double) expected, (Double) actual, DELTA);
|
||||
return;
|
||||
case BLOOM_FILTER_FP_CHANCE:
|
||||
case READ_REPAIR_CHANCE:
|
||||
case DCLOCAL_READ_REPAIR_CHANCE:
|
||||
assertEquals((Double) expected, (Double) actual, DELTA);
|
||||
return;
|
||||
|
||||
case CACHING:
|
||||
assertEquals(((String) expected).toUpperCase(), ((String) actual).toUpperCase());
|
||||
return;
|
||||
case CACHING:
|
||||
assertCaching((Map<String, Object>) expected, (Map<String, String>) actual);
|
||||
return;
|
||||
|
||||
case COMPACTION:
|
||||
assertCompaction((Map<String, Object>) expected, (Map<String, String>) actual);
|
||||
return;
|
||||
case COMPACTION:
|
||||
assertCompaction((Map<String, Object>) expected, (Map<String, String>) actual);
|
||||
return;
|
||||
|
||||
case COMPRESSION:
|
||||
assertCompression((Map<String, Object>) expected, (Map<String, String>) actual);
|
||||
return;
|
||||
case COMPRESSION:
|
||||
assertCompression((Map<String, Object>) expected, (Map<String, String>) actual);
|
||||
return;
|
||||
}
|
||||
|
||||
log.info(actual.getClass().getName());
|
||||
@@ -118,6 +118,10 @@ public class CqlTableSpecificationAssertions {
|
||||
tableOption.quotesValue() && !(actual instanceof CharSequence) ? CqlStringUtils.singleQuote(actual) : actual);
|
||||
}
|
||||
|
||||
public static void assertCaching(Map<String, Object> expected, Map<String, String> actual) {
|
||||
// TODO
|
||||
}
|
||||
|
||||
public static void assertCompaction(Map<String, Object> expected, Map<String, String> actual) {
|
||||
// TODO
|
||||
}
|
||||
@@ -137,26 +141,24 @@ public class CqlTableSpecificationAssertions {
|
||||
@SuppressWarnings("unchecked")
|
||||
public static <T> T getOptionFor(TableOption option, Class<?> type, Options options) {
|
||||
switch (option) {
|
||||
case BLOOM_FILTER_FP_CHANCE:
|
||||
return (T) (Double) options.getBloomFilterFalsePositiveChance();
|
||||
case CACHING:
|
||||
return (T) CqlStringUtils.singleQuote(options.getCaching());
|
||||
case COMMENT:
|
||||
return (T) CqlStringUtils.singleQuote(options.getComment());
|
||||
case COMPACTION:
|
||||
return (T) options.getCompaction();
|
||||
case COMPACT_STORAGE:
|
||||
throw new Error(); // TODO: figure out
|
||||
case COMPRESSION:
|
||||
return (T) options.getCompression();
|
||||
case DCLOCAL_READ_REPAIR_CHANCE:
|
||||
return (T) (Double) options.getLocalReadRepairChance();
|
||||
case GC_GRACE_SECONDS:
|
||||
return (T) new Long(options.getGcGraceInSeconds());
|
||||
case READ_REPAIR_CHANCE:
|
||||
return (T) (Double) options.getReadRepairChance();
|
||||
case REPLICATE_ON_WRITE:
|
||||
return (T) (Boolean) options.getReplicateOnWrite();
|
||||
case BLOOM_FILTER_FP_CHANCE:
|
||||
return (T) (Double) options.getBloomFilterFalsePositiveChance();
|
||||
case CACHING:
|
||||
return (T) options.getCaching();
|
||||
case COMMENT:
|
||||
return (T) CqlStringUtils.singleQuote(options.getComment());
|
||||
case COMPACTION:
|
||||
return (T) options.getCompaction();
|
||||
case COMPACT_STORAGE:
|
||||
throw new Error(); // TODO: figure out
|
||||
case COMPRESSION:
|
||||
return (T) options.getCompression();
|
||||
case DCLOCAL_READ_REPAIR_CHANCE:
|
||||
return (T) (Double) options.getLocalReadRepairChance();
|
||||
case GC_GRACE_SECONDS:
|
||||
return (T) new Long(options.getGcGraceInSeconds());
|
||||
case READ_REPAIR_CHANCE:
|
||||
return (T) (Double) options.getReadRepairChance();
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
@@ -34,7 +34,6 @@ public class BookListener extends TestListener implements AsynchronousQueryListe
|
||||
|
||||
@Override
|
||||
public void onQueryComplete(ResultSetFuture rsf) {
|
||||
countDown();
|
||||
|
||||
Row row;
|
||||
try {
|
||||
@@ -49,6 +48,8 @@ public class BookListener extends TestListener implements AsynchronousQueryListe
|
||||
book.setPages(row.getInt("pages"));
|
||||
|
||||
done = true;
|
||||
|
||||
countDown();
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -11,7 +11,7 @@ class BasicListener extends TestListener implements AsynchronousQueryListener {
|
||||
|
||||
@Override
|
||||
public void onQueryComplete(ResultSetFuture rsf) {
|
||||
countDown();
|
||||
this.rsf = rsf;
|
||||
countDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -12,13 +12,13 @@ public class MapListener extends TestListener implements QueryForMapListener {
|
||||
|
||||
@Override
|
||||
public void onQueryComplete(Map<String, Object> results) {
|
||||
countDown();
|
||||
this.result = results;
|
||||
countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Exception x) {
|
||||
countDown();
|
||||
this.exception = x;
|
||||
countDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -10,13 +10,13 @@ class ObjectListener<T> extends TestListener implements QueryForObjectListener<T
|
||||
|
||||
@Override
|
||||
public void onQueryComplete(T result) {
|
||||
countDown();
|
||||
this.result = result;
|
||||
countDown();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onException(Exception x) {
|
||||
countDown();
|
||||
this.exception = x;
|
||||
countDown();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.cassandra.core.keyspace.TableOption;
|
||||
import org.springframework.cassandra.core.keyspace.TableOption.CachingOption;
|
||||
import org.springframework.cassandra.core.keyspace.TableOption.CompactionOption;
|
||||
import org.springframework.cassandra.core.keyspace.TableOption.CompressionOption;
|
||||
import org.springframework.cassandra.core.keyspace.TableOption.KeyCachingOption;
|
||||
|
||||
import com.datastax.driver.core.DataType;
|
||||
|
||||
@@ -57,7 +58,8 @@ public class AlterTableCqlGeneratorTests {
|
||||
* Convenient base class that other test classes can use so as not to repeat the generics declarations.
|
||||
*/
|
||||
public static abstract class AlterTableTest extends
|
||||
TableOperationCqlGeneratorTest<AlterTableSpecification, AlterTableCqlGenerator> {}
|
||||
TableOperationCqlGeneratorTest<AlterTableSpecification, AlterTableCqlGenerator> {
|
||||
}
|
||||
|
||||
public static class BasicTest extends AlterTableTest {
|
||||
|
||||
@@ -112,6 +114,7 @@ public class AlterTableCqlGeneratorTests {
|
||||
public String comment = "This is My Table";
|
||||
public Map<Option, Object> compactionMap = new LinkedHashMap<Option, Object>();
|
||||
public Map<Option, Object> compressionMap = new LinkedHashMap<Option, Object>();
|
||||
public Map<Option, Object> cachingMap = new LinkedHashMap<Option, Object>();
|
||||
|
||||
@Override
|
||||
public AlterTableSpecification specification() {
|
||||
@@ -123,6 +126,9 @@ public class AlterTableCqlGeneratorTests {
|
||||
compressionMap.put(CompressionOption.SSTABLE_COMPRESSION, "SnappyCompressor");
|
||||
compressionMap.put(CompressionOption.CHUNK_LENGTH_KB, 128);
|
||||
compressionMap.put(CompressionOption.CRC_CHECK_CHANCE, 0.75);
|
||||
// Caching
|
||||
cachingMap.put(CachingOption.KEYS, KeyCachingOption.ALL);
|
||||
cachingMap.put(CachingOption.ROWS_PER_PARTITION, "10");
|
||||
|
||||
return AlterTableSpecification
|
||||
.alterTable()
|
||||
@@ -130,8 +136,8 @@ public class AlterTableCqlGeneratorTests {
|
||||
// .with(TableOption.COMPACT_STORAGE)
|
||||
.with(TableOption.READ_REPAIR_CHANCE, readRepairChance).with(TableOption.COMPACTION, compactionMap)
|
||||
.with(TableOption.COMPRESSION, compressionMap).with(TableOption.BLOOM_FILTER_FP_CHANCE, bloomFilterFpChance)
|
||||
.with(TableOption.CACHING, CachingOption.KEYS_ONLY).with(TableOption.REPLICATE_ON_WRITE, replcateOnWrite)
|
||||
.with(TableOption.COMMENT, comment).with(TableOption.DCLOCAL_READ_REPAIR_CHANCE, dcLocalReadRepairChance)
|
||||
.with(TableOption.CACHING, cachingMap).with(TableOption.COMMENT, comment)
|
||||
.with(TableOption.DCLOCAL_READ_REPAIR_CHANCE, dcLocalReadRepairChance)
|
||||
.with(TableOption.GC_GRACE_SECONDS, gcGraceSeconds);
|
||||
}
|
||||
|
||||
|
||||
@@ -37,6 +37,7 @@ import org.springframework.cassandra.core.keyspace.TableOption;
|
||||
import org.springframework.cassandra.core.keyspace.TableOption.CachingOption;
|
||||
import org.springframework.cassandra.core.keyspace.TableOption.CompactionOption;
|
||||
import org.springframework.cassandra.core.keyspace.TableOption.CompressionOption;
|
||||
import org.springframework.cassandra.core.keyspace.TableOption.KeyCachingOption;
|
||||
|
||||
import com.datastax.driver.core.DataType;
|
||||
|
||||
@@ -220,6 +221,7 @@ public class CreateTableCqlGeneratorTests {
|
||||
public String comment = "This is My Table";
|
||||
public Map<Option, Object> compactionMap = new LinkedHashMap<Option, Object>();
|
||||
public Map<Option, Object> compressionMap = new LinkedHashMap<Option, Object>();
|
||||
public Map<Option, Object> cachingMap = new LinkedHashMap<Option, Object>();
|
||||
|
||||
@Override
|
||||
public CreateTableSpecification specification() {
|
||||
@@ -231,13 +233,15 @@ public class CreateTableCqlGeneratorTests {
|
||||
compressionMap.put(CompressionOption.SSTABLE_COMPRESSION, "SnappyCompressor");
|
||||
compressionMap.put(CompressionOption.CHUNK_LENGTH_KB, 128);
|
||||
compressionMap.put(CompressionOption.CRC_CHECK_CHANCE, 0.75);
|
||||
// Caching
|
||||
cachingMap.put(CachingOption.KEYS, KeyCachingOption.ALL);
|
||||
cachingMap.put(CachingOption.ROWS_PER_PARTITION, "NONE");
|
||||
|
||||
return CreateTableSpecification.createTable().name(name).partitionKeyColumn(partitionKey0, partitionKeyType0)
|
||||
.partitionKeyColumn(partitionKey1, partitionKeyType1).column(column1, columnType1)
|
||||
.with(TableOption.COMPACT_STORAGE).with(TableOption.READ_REPAIR_CHANCE, readRepairChance)
|
||||
.with(TableOption.COMPACTION, compactionMap).with(TableOption.COMPRESSION, compressionMap)
|
||||
.with(TableOption.BLOOM_FILTER_FP_CHANCE, bloomFilterFpChance)
|
||||
.with(TableOption.CACHING, CachingOption.KEYS_ONLY).with(TableOption.REPLICATE_ON_WRITE, replcateOnWrite)
|
||||
.with(TableOption.BLOOM_FILTER_FP_CHANCE, bloomFilterFpChance).with(TableOption.CACHING, cachingMap)
|
||||
.with(TableOption.COMMENT, comment).with(TableOption.DCLOCAL_READ_REPAIR_CHANCE, dcLocalReadRepairChance)
|
||||
.with(TableOption.GC_GRACE_SECONDS, gcGraceSeconds);
|
||||
}
|
||||
@@ -257,8 +261,6 @@ public class CreateTableCqlGeneratorTests {
|
||||
assertDoubleOption(TableOption.READ_REPAIR_CHANCE.getName(), readRepairChance, cql);
|
||||
assertDoubleOption(TableOption.DCLOCAL_READ_REPAIR_CHANCE.getName(), dcLocalReadRepairChance, cql);
|
||||
assertDoubleOption(TableOption.BLOOM_FILTER_FP_CHANCE.getName(), bloomFilterFpChance, cql);
|
||||
assertStringOption(TableOption.CACHING.getName(), CachingOption.KEYS_ONLY.getValue(), cql);
|
||||
assertStringOption(TableOption.REPLICATE_ON_WRITE.getName(), replcateOnWrite.toString(), cql);
|
||||
assertStringOption(TableOption.COMMENT.getName(), comment, cql);
|
||||
assertLongOption(TableOption.GC_GRACE_SECONDS.getName(), gcGraceSeconds, cql);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user