DATACASS-239 - Upgraded to latest Cassandra, Cassandra unit and Dse driver.
Updated Cassandra-Unit, DSE Driver and Cassandra version to latest stable version. Changed the Test Cases to support the API changes on the driver by DataStax. They changed the exception hierarchy for failed replication factor quorum. The embedded spring-cassandra.yaml files were tuned to turn of unneeded features that were causing overhead in the testing. Marked new test dependencies as test scope. Original pull request: #43.
This commit is contained in:
committed by
Oliver Gierke
parent
b398ddab2e
commit
237ac88bc5
@@ -18,15 +18,20 @@ package org.springframework.cassandra.test.integration;
|
||||
import org.junit.After;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cassandra.core.CqlOperations;
|
||||
import org.springframework.cassandra.core.CqlTemplate;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.datastax.driver.core.Host;
|
||||
import com.datastax.driver.core.KeyspaceMetadata;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.Session.State;
|
||||
|
||||
/**
|
||||
* Abstract base integration test class that creates a keyspace
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author David Webb
|
||||
*/
|
||||
public abstract class AbstractKeyspaceCreatingIntegrationTest extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@@ -81,7 +86,7 @@ public abstract class AbstractKeyspaceCreatingIntegrationTest extends AbstractEm
|
||||
if (kmd == null) { // then create keyspace
|
||||
|
||||
String cql = "CREATE KEYSPACE " + keyspace
|
||||
+ " WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};";
|
||||
+ " WITH durable_writes = false AND replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};";
|
||||
log.info("creating keyspace {} via CQL [{}]", keyspace, cql);
|
||||
|
||||
system.execute(cql);
|
||||
@@ -99,15 +104,42 @@ public abstract class AbstractKeyspaceCreatingIntegrationTest extends AbstractEm
|
||||
|
||||
} else {
|
||||
|
||||
debugSession();
|
||||
|
||||
log.info("session already connected to a keyspace; attempting to change to use {}", keyspace);
|
||||
|
||||
String cql = "USE " + (keyspace == null ? "system" : keyspace) + ";";
|
||||
session.execute(cql);
|
||||
|
||||
log.debug(cql);
|
||||
|
||||
getTemplate().execute(cql);
|
||||
|
||||
log.info("now using keyspace " + keyspace);
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
protected static CqlOperations getTemplate() {
|
||||
|
||||
return new CqlTemplate(session);
|
||||
}
|
||||
|
||||
protected static void debugSession() {
|
||||
if (session == null) {
|
||||
log.warn("Session is null...cannot debug that");
|
||||
return;
|
||||
}
|
||||
|
||||
State state = session.getState();
|
||||
|
||||
for (Host h : state.getConnectedHosts()) {
|
||||
|
||||
log.debug(String.format("Session Host dc [%s], rack [%s], ver [%s], state [%s]", h.getDatacenter(), h.getRack(),
|
||||
h.getCassandraVersion(), h.getState()));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
if (dropKeyspaceAfterTest() && keyspace != null) {
|
||||
|
||||
@@ -29,13 +29,10 @@ import com.datastax.driver.core.Statement;
|
||||
public class TestLatencyTracker implements LatencyTracker {
|
||||
|
||||
private final static Logger LOG = LoggerFactory.getLogger(TestLatencyTracker.class);
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see com.datastax.driver.core.LatencyTracker#update(com.datastax.driver.core.Host, long)
|
||||
*/
|
||||
|
||||
@Override
|
||||
public void update(Host host, long newLatencyNanos) {
|
||||
public void update(Host host, Statement statement, Exception exception, long newLatencyNanos) {
|
||||
LOG.info("Latency Tracker: " + host.getAddress() + ", " + newLatencyNanos + " nanoseconds.");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -63,7 +63,7 @@ public class CreateIndexCqlGeneratorIntegrationTests {
|
||||
@Rule
|
||||
public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet(
|
||||
"integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest.cql", this.keyspace),
|
||||
CASSANDRA_CONFIG, CASSANDRA_HOST, CASSANDRA_NATIVE_PORT);
|
||||
CASSANDRA_CONFIG);
|
||||
|
||||
@Override
|
||||
public BasicTest unit() {
|
||||
|
||||
@@ -44,7 +44,7 @@ public class IndexLifecycleCqlGeneratorIntegrationTests extends AbstractKeyspace
|
||||
@Rule
|
||||
public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet(
|
||||
"integration/cql/generator/CreateIndexCqlGeneratorIntegrationTests-BasicTest.cql", this.keyspace),
|
||||
CASSANDRA_CONFIG, CASSANDRA_HOST, CASSANDRA_NATIVE_PORT);
|
||||
CASSANDRA_CONFIG);
|
||||
|
||||
@Test
|
||||
public void lifecycleTest() {
|
||||
|
||||
@@ -52,12 +52,9 @@ public class TableLifecycleIntegrationTest extends AbstractKeyspaceCreatingInteg
|
||||
return true;
|
||||
}
|
||||
|
||||
// This only ensures the keyspace exists before each test, while using a static session from the parent object.
|
||||
// TODO - DW Make this better.
|
||||
@Rule
|
||||
public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet(
|
||||
"cassandraOperationsTest-cql-dataload.cql", this.keyspace), CASSANDRA_CONFIG, CASSANDRA_HOST,
|
||||
CASSANDRA_NATIVE_PORT);
|
||||
"cassandraOperationsTest-cql-dataload.cql", this.keyspace), CASSANDRA_CONFIG);
|
||||
|
||||
@Test
|
||||
public void testDrop() {
|
||||
@@ -100,21 +97,24 @@ public class TableLifecycleIntegrationTest extends AbstractKeyspaceCreatingInteg
|
||||
|
||||
// assertTable(alterTest.specification, keyspace, session);
|
||||
|
||||
DropTableTest dropTest = new DropTableTest();
|
||||
dropTest.prepare();
|
||||
|
||||
log.info(dropTest.cql);
|
||||
|
||||
session.execute(dropTest.cql);
|
||||
|
||||
assertNoTable(dropTest.specification, keyspace, session);
|
||||
|
||||
}
|
||||
|
||||
public class DropTableTest extends DropTableCqlGeneratorTests.DropTableTest {
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.test.unit.core.cql.generator.TableOperationCqlGeneratorTest#specification()
|
||||
*/
|
||||
@Override
|
||||
public DropTableSpecification specification() {
|
||||
return DropTableSpecification.dropTable().name(createTableTest.specification.getName());
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
* @see org.springframework.cassandra.test.unit.core.cql.generator.TableOperationCqlGeneratorTest#generator()
|
||||
*/
|
||||
@Override
|
||||
public DropTableCqlGenerator generator() {
|
||||
return new DropTableCqlGenerator(specification);
|
||||
|
||||
@@ -96,8 +96,7 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
*/
|
||||
@Rule
|
||||
public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet(
|
||||
"cassandraOperationsTest-cql-dataload.cql", this.keyspace), CASSANDRA_CONFIG, CASSANDRA_HOST,
|
||||
CASSANDRA_NATIVE_PORT);
|
||||
"cassandraOperationsTest-cql-dataload.cql", this.keyspace), CASSANDRA_CONFIG);
|
||||
|
||||
@Before
|
||||
public void setupTemplate() {
|
||||
|
||||
@@ -22,7 +22,7 @@ import org.springframework.cassandra.core.QueryForMapListener;
|
||||
import org.springframework.cassandra.core.QueryForObjectListener;
|
||||
import org.springframework.cassandra.core.QueryOptions;
|
||||
import org.springframework.cassandra.core.RetryPolicy;
|
||||
import org.springframework.cassandra.support.exception.CassandraInsufficientReplicasAvailableException;
|
||||
import org.springframework.cassandra.support.exception.CassandraConnectionFailureException;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.datastax.driver.core.DataType;
|
||||
@@ -238,7 +238,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest {
|
||||
testString_AsynchronousQueryListener_QueryOptions(ConsistencyLevel.ONE);
|
||||
}
|
||||
|
||||
@Test(expected = CassandraInsufficientReplicasAvailableException.class)
|
||||
@Test(expected = CassandraConnectionFailureException.class)
|
||||
public void testString_AsynchronousQueryListener_QueryOptionsWithConsistencyLevel2() throws InterruptedException {
|
||||
testString_AsynchronousQueryListener_QueryOptions(ConsistencyLevel.TWO);
|
||||
}
|
||||
@@ -284,7 +284,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest {
|
||||
testString_QueryForObjectListener_QueryOptions(ConsistencyLevel.ONE);
|
||||
}
|
||||
|
||||
@Test(expected = CassandraInsufficientReplicasAvailableException.class)
|
||||
@Test(expected = CassandraConnectionFailureException.class)
|
||||
public void testString_QueryForObjectListener_QueryOptionsWithConsistencyLevel2() throws Exception {
|
||||
testString_QueryForObjectListener_QueryOptions(ConsistencyLevel.TWO);
|
||||
}
|
||||
@@ -324,7 +324,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest {
|
||||
testString_QueryForMapListener_QueryOptions(ConsistencyLevel.ONE);
|
||||
}
|
||||
|
||||
@Test(expected = CassandraInsufficientReplicasAvailableException.class)
|
||||
@Test(expected = CassandraConnectionFailureException.class)
|
||||
public void testString_QueryForMapListener_QueryOptionsWithConsistencyLevel2() throws Exception {
|
||||
testString_QueryForMapListener_QueryOptions(ConsistencyLevel.TWO);
|
||||
}
|
||||
@@ -381,7 +381,7 @@ public class AsynchronousTest extends AbstractAsynchronousTest {
|
||||
testString_QueryForListListener_QueryOptions(ConsistencyLevel.ONE);
|
||||
}
|
||||
|
||||
@Test(expected = CassandraInsufficientReplicasAvailableException.class)
|
||||
@Test(expected = CassandraConnectionFailureException.class)
|
||||
public void testString_QueryForListListener_QueryOptionsWithConsistencyLevel2() throws Exception {
|
||||
testString_QueryForListListener_QueryOptions(ConsistencyLevel.TWO);
|
||||
}
|
||||
|
||||
@@ -76,11 +76,20 @@ public class SpringCqlBuildProperties extends Properties {
|
||||
return getInt("build.cassandra.ssl_storage_port");
|
||||
}
|
||||
|
||||
public long getCqlInitializationTimeout() {
|
||||
return getLong("build.cql.init.timeout");
|
||||
}
|
||||
|
||||
public int getInt(String key) {
|
||||
String property = getProperty(key);
|
||||
return Integer.parseInt(property);
|
||||
}
|
||||
|
||||
public long getLong(String key) {
|
||||
String property = getProperty(key);
|
||||
return Long.parseLong(property);
|
||||
}
|
||||
|
||||
public boolean getBoolean(String key) {
|
||||
return Boolean.parseBoolean(getProperty(key));
|
||||
}
|
||||
|
||||
@@ -35,7 +35,8 @@ public class DropKeyspaceCqlGeneratorTests {
|
||||
* Convenient base class that other test classes can use so as not to repeat the generics declarations.
|
||||
*/
|
||||
public static abstract class DropTableTest extends
|
||||
KeyspaceOperationCqlGeneratorTest<DropKeyspaceSpecification, DropKeyspaceCqlGenerator> {}
|
||||
KeyspaceOperationCqlGeneratorTest<DropKeyspaceSpecification, DropKeyspaceCqlGenerator> {
|
||||
}
|
||||
|
||||
public static class BasicTest extends DropTableTest {
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ package org.springframework.cassandra.test.unit.core.cql.generator;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.commons.lang.StringUtils;
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.core.cql.generator.KeyspaceNameCqlGenerator;
|
||||
import org.springframework.cassandra.core.cql.generator.TableNameCqlGenerator;
|
||||
|
||||
Reference in New Issue
Block a user