Merge branch 'master' into DATACASS-1
This commit is contained in:
@@ -7,6 +7,9 @@ import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.thrift.transport.TTransportException;
|
||||
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
|
||||
import org.junit.After;
|
||||
import org.junit.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.KeyspaceMetadata;
|
||||
@@ -14,22 +17,30 @@ import com.datastax.driver.core.Session;
|
||||
|
||||
public abstract class AbstractEmbeddedCassandraIntegrationTest {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(AbstractEmbeddedCassandraIntegrationTest.class);
|
||||
|
||||
protected final static String CASSANDRA_CONFIG = "spring-cassandra.yaml";
|
||||
protected final static String CASSANDRA_HOST = "localhost";
|
||||
protected final static int CASSANDRA_NATIVE_PORT = 9042;
|
||||
|
||||
@BeforeClass
|
||||
public static void startCassandra() throws ConfigurationException, TTransportException, IOException,
|
||||
InterruptedException {
|
||||
log.info("Starting Cassandra Embedded Server");
|
||||
EmbeddedCassandraServerHelper.startEmbeddedCassandra(CASSANDRA_CONFIG);
|
||||
}
|
||||
|
||||
public AbstractEmbeddedCassandraIntegrationTest() {
|
||||
try {
|
||||
startCassandra();
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
if (session == null) {
|
||||
connect();
|
||||
}
|
||||
}
|
||||
|
||||
public AbstractEmbeddedCassandraIntegrationTest(String keyspace) {
|
||||
this.keyspace = keyspace;
|
||||
if (session == null) {
|
||||
connect();
|
||||
}
|
||||
connect();
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -48,10 +59,11 @@ public abstract class AbstractEmbeddedCassandraIntegrationTest {
|
||||
* If not <code>null</code>, get a {@link Session} for the from the {@link #cluster}.
|
||||
*/
|
||||
protected String keyspace = "ks" + UUID.randomUUID().toString().replace("-", "");
|
||||
|
||||
/**
|
||||
* The {@link Session} for the {@link #keyspace} from the {@link #cluster}.
|
||||
*/
|
||||
protected Session session;
|
||||
protected static Session session;
|
||||
|
||||
protected String keyspace() {
|
||||
return keyspace;
|
||||
@@ -69,7 +81,11 @@ public abstract class AbstractEmbeddedCassandraIntegrationTest {
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
|
||||
if (connect && !connected()) {
|
||||
|
||||
log.info("Connecting to Cassandra");
|
||||
|
||||
cluster = cluster();
|
||||
|
||||
if (keyspace() == null) {
|
||||
@@ -91,8 +107,11 @@ public abstract class AbstractEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
log.info("After: clear -> " + clear + ", connected -> " + connected());
|
||||
if (clear && connected()) {
|
||||
log.info("Cleaning Cassandra");
|
||||
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -18,6 +18,9 @@ package org.springframework.cassandra.test.integration.core.cql.generator;
|
||||
import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.assertNoTable;
|
||||
import static org.springframework.cassandra.test.integration.core.cql.generator.CqlTableSpecificationAssertions.assertTable;
|
||||
|
||||
import org.cassandraunit.CassandraCQLUnit;
|
||||
import org.cassandraunit.dataset.cql.ClassPathCQLDataSet;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
@@ -39,6 +42,18 @@ public class TableLifecycleIntegrationTest extends AbstractEmbeddedCassandraInte
|
||||
|
||||
CreateTableCqlGeneratorTests.MultipleOptionsTest createTableTest = new CreateTableCqlGeneratorTests.MultipleOptionsTest();
|
||||
|
||||
public TableLifecycleIntegrationTest() {
|
||||
super("tlit");
|
||||
clear = 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);
|
||||
|
||||
@Test
|
||||
public void testDrop() {
|
||||
|
||||
|
||||
@@ -67,7 +67,7 @@ import com.datastax.driver.core.exceptions.DriverException;
|
||||
*/
|
||||
public class CassandraOperationsTest extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
|
||||
private CassandraOperations cassandraTemplate;
|
||||
private static CassandraOperations cassandraTemplate;
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CassandraOperationsTest.class);
|
||||
|
||||
@@ -88,9 +88,26 @@ public class CassandraOperationsTest extends AbstractEmbeddedCassandraIntegratio
|
||||
"cassandraOperationsTest-cql-dataload.cql", this.keyspace), CASSANDRA_CONFIG, CASSANDRA_HOST,
|
||||
CASSANDRA_NATIVE_PORT);
|
||||
|
||||
public CassandraOperationsTest() {
|
||||
super("sdctest");
|
||||
clear = true;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setupTemplate() {
|
||||
cassandraTemplate = new CassandraTemplate(session);
|
||||
|
||||
log.info("Running setupTemplate()");
|
||||
|
||||
if (cassandraTemplate == null) {
|
||||
|
||||
log.info("null Template ... Initialzing DB test CQL");
|
||||
|
||||
// CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet(
|
||||
// "cassandraOperationsTest-cql-dataload.cql", keyspace), CASSANDRA_CONFIG, CASSANDRA_HOST,
|
||||
// CASSANDRA_NATIVE_PORT);
|
||||
|
||||
cassandraTemplate = new CassandraTemplate(session);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -140,9 +157,11 @@ public class CassandraOperationsTest extends AbstractEmbeddedCassandraIntegratio
|
||||
}
|
||||
|
||||
@Test
|
||||
@SuppressWarnings( "unchecked" )
|
||||
@SuppressWarnings("unchecked")
|
||||
public void ingestionTestListOfList() {
|
||||
|
||||
log.info("Keyspace => " + keyspace);
|
||||
|
||||
String cql = "insert into book (isbn, title, author, pages) values (?, ?, ?, ?)";
|
||||
|
||||
List<List<?>> values = new LinkedList<List<?>>();
|
||||
@@ -166,6 +185,8 @@ public class CassandraOperationsTest extends AbstractEmbeddedCassandraIntegratio
|
||||
@Test
|
||||
public void ingestionTestObjectArray() {
|
||||
|
||||
log.info("Keyspace => " + keyspace);
|
||||
|
||||
String cql = "insert into book (isbn, title, author, pages) values (?, ?, ?, ?)";
|
||||
|
||||
Object[][] values = new Object[3][];
|
||||
@@ -508,7 +529,7 @@ public class CassandraOperationsTest extends AbstractEmbeddedCassandraIntegratio
|
||||
// Insert our 3 test books.
|
||||
ingestionTestObjectArray();
|
||||
|
||||
@SuppressWarnings( "unused" )
|
||||
@SuppressWarnings("unused")
|
||||
Book book = cassandraTemplate.queryForObject("select * from book where isbn in ('1234','2345','3456')",
|
||||
new RowMapper<Book>() {
|
||||
@Override
|
||||
@@ -563,7 +584,7 @@ public class CassandraOperationsTest extends AbstractEmbeddedCassandraIntegratio
|
||||
@Test(expected = ClassCastException.class)
|
||||
public void queryForObjectTestCqlStringRequiredTypeInvalid() {
|
||||
|
||||
@SuppressWarnings( "unused" )
|
||||
@SuppressWarnings("unused")
|
||||
Float title = cassandraTemplate.queryForObject("select title from book where isbn in ('" + ISBN_NINES + "')",
|
||||
Float.class);
|
||||
|
||||
|
||||
Reference in New Issue
Block a user