fixed integration test classes to work with a single forked jvm
This commit is contained in:
3
pom.xml
3
pom.xml
@@ -260,7 +260,8 @@
|
||||
<artifactId>maven-failsafe-plugin</artifactId>
|
||||
<version>${failsafe.version}</version>
|
||||
<configuration>
|
||||
<forkMode>always</forkMode>
|
||||
<forkCount>1</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
<argLine>-Xmx2048m -XX:MaxPermSize=512m</argLine>
|
||||
<useFile>false</useFile>
|
||||
<includes>
|
||||
|
||||
@@ -1,117 +1,72 @@
|
||||
package org.springframework.cassandra.test.integration;
|
||||
|
||||
import java.io.IOException;
|
||||
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.BeforeClass;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cassandra.test.unit.support.Utils;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.KeyspaceMetadata;
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
public abstract class AbstractEmbeddedCassandraIntegrationTest {
|
||||
/**
|
||||
* Abstract base integration test class that starts an embedded Cassandra instance.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class AbstractEmbeddedCassandraIntegrationTest {
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(AbstractEmbeddedCassandraIntegrationTest.class);
|
||||
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;
|
||||
protected static final String CASSANDRA_CONFIG = "spring-cassandra.yaml";
|
||||
protected static final String CASSANDRA_HOST = "localhost";
|
||||
protected static final int CASSANDRA_NATIVE_PORT = 9042;
|
||||
|
||||
/**
|
||||
* The session connected to the system keyspace.
|
||||
*/
|
||||
protected static Session SYSTEM;
|
||||
/**
|
||||
* The {@link Cluster} that's connected to Cassandra.
|
||||
*/
|
||||
protected static Cluster CLUSTER;
|
||||
|
||||
public static String randomKeyspaceName() {
|
||||
return Utils.randomKeyspaceName();
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void startCassandra() throws ConfigurationException, TTransportException, IOException,
|
||||
InterruptedException {
|
||||
log.info("Starting Cassandra Embedded Server");
|
||||
|
||||
EmbeddedCassandraServerHelper.startEmbeddedCassandra(CASSANDRA_CONFIG);
|
||||
}
|
||||
|
||||
public AbstractEmbeddedCassandraIntegrationTest() {
|
||||
if (session == null) {
|
||||
connect();
|
||||
}
|
||||
}
|
||||
|
||||
public AbstractEmbeddedCassandraIntegrationTest(String keyspace) {
|
||||
this.keyspace = keyspace;
|
||||
if (session == null) {
|
||||
connect();
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to clear the cluster before the next test.
|
||||
*/
|
||||
protected boolean clear = false;
|
||||
/**
|
||||
* Whether to connect to Cassandra.
|
||||
*/
|
||||
protected boolean connect = true;
|
||||
/**
|
||||
* The {@link Cluster} that's connected to Cassandra.
|
||||
*/
|
||||
protected Cluster cluster;
|
||||
/**
|
||||
* 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 String keyspace() {
|
||||
return keyspace;
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether we're currently connected to the cluster.
|
||||
*/
|
||||
public boolean connected() {
|
||||
return session != null;
|
||||
}
|
||||
|
||||
public Cluster cluster() {
|
||||
public static Cluster cluster() {
|
||||
return Cluster.builder().addContactPoint(CASSANDRA_HOST).withPort(CASSANDRA_NATIVE_PORT).build();
|
||||
}
|
||||
|
||||
public void connect() {
|
||||
/**
|
||||
* Ensures that the cluster is created and that the session {@link #SYSTEM} is connected to it.
|
||||
*/
|
||||
public static void ensureClusterConnection() {
|
||||
|
||||
if (connect && !connected()) {
|
||||
// check cluster
|
||||
if (CLUSTER == null) {
|
||||
CLUSTER = cluster();
|
||||
}
|
||||
|
||||
log.info("Connecting to Cassandra");
|
||||
|
||||
cluster = cluster();
|
||||
|
||||
if (keyspace() == null) {
|
||||
session = cluster.connect();
|
||||
} else {
|
||||
|
||||
KeyspaceMetadata kmd = cluster.getMetadata().getKeyspace(keyspace());
|
||||
if (kmd == null) { // then create keyspace
|
||||
session = cluster.connect();
|
||||
session.execute("CREATE KEYSPACE " + keyspace()
|
||||
+ " WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};");
|
||||
session.execute("USE " + keyspace() + ";");
|
||||
} else {// else keyspace already exists
|
||||
session = cluster.connect(keyspace());
|
||||
}
|
||||
}
|
||||
// check system session connected
|
||||
if (SYSTEM == null) {
|
||||
SYSTEM = CLUSTER.connect();
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
log.info("After: clear -> " + clear + ", connected -> " + connected());
|
||||
if (clear && connected()) {
|
||||
log.info("Cleaning Cassandra");
|
||||
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
|
||||
}
|
||||
public AbstractEmbeddedCassandraIntegrationTest() {
|
||||
ensureClusterConnection();
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -0,0 +1,109 @@
|
||||
package org.springframework.cassandra.test.integration;
|
||||
|
||||
import org.junit.After;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
|
||||
import com.datastax.driver.core.KeyspaceMetadata;
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
/**
|
||||
* Abstract base integration test class that creates a keyspace
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public abstract class AbstractKeyspaceCreatingIntegrationTest extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
|
||||
static Logger log = LoggerFactory.getLogger(AbstractKeyspaceCreatingIntegrationTest.class);
|
||||
|
||||
/**
|
||||
* The session that's connected to the keyspace used in the current instance's test.
|
||||
*/
|
||||
protected static Session SESSION;
|
||||
|
||||
/**
|
||||
* The name of the keyspace to use for this test instance.
|
||||
*/
|
||||
protected String keyspace;
|
||||
|
||||
public AbstractKeyspaceCreatingIntegrationTest() {
|
||||
this(randomKeyspaceName());
|
||||
}
|
||||
|
||||
public AbstractKeyspaceCreatingIntegrationTest(String keyspace) {
|
||||
|
||||
this.keyspace = keyspace;
|
||||
ensureKeyspaceAndSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether we're currently connected to the keyspace.
|
||||
*/
|
||||
public static boolean connected() {
|
||||
return SESSION != null;
|
||||
}
|
||||
|
||||
/**
|
||||
* Whether to drop the keyspace that was created after the test has completed. Subclasses should override and return
|
||||
* true, since this default implementation returns false.
|
||||
*/
|
||||
public boolean dropKeyspaceAfterTest() {
|
||||
return false;
|
||||
}
|
||||
|
||||
public void ensureKeyspaceAndSession() {
|
||||
|
||||
// ensure that test keyspace exists
|
||||
|
||||
if (!StringUtils.hasText(keyspace)) {
|
||||
keyspace = null;
|
||||
}
|
||||
|
||||
if (keyspace != null) {
|
||||
// see if we need to create the keyspace
|
||||
KeyspaceMetadata kmd = CLUSTER.getMetadata().getKeyspace(keyspace);
|
||||
if (kmd == null) { // then create keyspace
|
||||
|
||||
String cql = "CREATE KEYSPACE " + keyspace
|
||||
+ " WITH replication = {'class': 'SimpleStrategy', 'replication_factor' : 1};";
|
||||
log.info("creating keyspace {} via CQL [{}]", keyspace, cql);
|
||||
|
||||
SYSTEM.execute(cql);
|
||||
}
|
||||
}
|
||||
|
||||
// keyspace now exists; ensure the session is using it
|
||||
if (SESSION == null) {
|
||||
|
||||
log.info("connecting to keyspace {}", keyspace == null ? "system" : keyspace + "...");
|
||||
|
||||
SESSION = keyspace == null ? CLUSTER.connect() : CLUSTER.connect(keyspace);
|
||||
|
||||
log.info("connected to keyspace {}", keyspace == null ? "system" : keyspace);
|
||||
|
||||
} else {
|
||||
|
||||
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.info("now using keyspace " + keyspace);
|
||||
}
|
||||
}
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
if (dropKeyspaceAfterTest() && keyspace != null) {
|
||||
|
||||
SESSION.execute("USE system");
|
||||
|
||||
log.info("dropping keyspace {} ...", keyspace);
|
||||
|
||||
SYSTEM.execute("DROP KEYSPACE " + keyspace);
|
||||
|
||||
log.info("dropped keyspace {}", keyspace);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -1,28 +1,13 @@
|
||||
package org.springframework.cassandra.test.integration.config.java;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.junit.Assert;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.cassandra.test.integration.config.IntegrationTestUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = KeyspaceCreatingJavaConfig.class)
|
||||
public class KeyspaceCreatingJavaConfigTest extends AbstractIntegrationTest {
|
||||
|
||||
@Inject
|
||||
protected Session session;
|
||||
|
||||
@Override
|
||||
protected String keyspace() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Assert.assertNotNull(session);
|
||||
|
||||
@@ -15,11 +15,6 @@ import com.datastax.driver.core.Session;
|
||||
@ContextConfiguration
|
||||
public class FullySpecifiedKeyspaceCreatingXmlConfigTest extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@Override
|
||||
protected String keyspace() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Inject
|
||||
Session s;
|
||||
|
||||
|
||||
@@ -15,11 +15,6 @@ import com.datastax.driver.core.Session;
|
||||
@ContextConfiguration
|
||||
public class MinimalKeyspaceCreatingXmlConfigTest extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
|
||||
@Override
|
||||
protected String keyspace() {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Inject
|
||||
Session s;
|
||||
|
||||
|
||||
@@ -1,13 +1,13 @@
|
||||
package org.springframework.cassandra.test.integration.config.xml;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.cassandra.core.CassandraOperations;
|
||||
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
import org.springframework.cassandra.test.integration.config.IntegrationTestUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -16,10 +16,12 @@ import com.datastax.driver.core.Session;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class MinimalXmlConfigTest extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
public class MinimalXmlConfigTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
protected String keyspace() {
|
||||
return "minimalxmlconfigtest";
|
||||
public static final String KEYSPACE = "minimalxmlconfigtest";
|
||||
|
||||
public MinimalXmlConfigTest() {
|
||||
super(KEYSPACE);
|
||||
}
|
||||
|
||||
@Inject
|
||||
@@ -31,7 +33,7 @@ public class MinimalXmlConfigTest extends AbstractEmbeddedCassandraIntegrationTe
|
||||
@Test
|
||||
public void test() {
|
||||
IntegrationTestUtils.assertSession(s);
|
||||
IntegrationTestUtils.assertKeyspaceExists(keyspace(), s);
|
||||
IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, s);
|
||||
|
||||
assertNotNull(ops);
|
||||
}
|
||||
|
||||
@@ -4,7 +4,7 @@ import javax.inject.Inject;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
import org.springframework.cassandra.test.integration.config.IntegrationTestUtils;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@@ -13,18 +13,20 @@ import com.datastax.driver.core.Session;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
public class XmlConfigTest extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
public class XmlConfigTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
protected String keyspace() {
|
||||
return "xmlconfigtest";
|
||||
}
|
||||
public static final String KEYSPACE = "xmlconfigtest";
|
||||
|
||||
@Inject
|
||||
Session s;
|
||||
|
||||
public XmlConfigTest() {
|
||||
super(KEYSPACE);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
IntegrationTestUtils.assertSession(s);
|
||||
IntegrationTestUtils.assertKeyspaceExists(keyspace(), s);
|
||||
IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, s);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -6,7 +6,7 @@ import org.cassandraunit.CassandraCQLUnit;
|
||||
import org.cassandraunit.dataset.cql.ClassPathCQLDataSet;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.CreateIndexCqlGeneratorTests.BasicTest;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.CreateIndexCqlGeneratorTests.CreateIndexTest;
|
||||
|
||||
@@ -24,7 +24,7 @@ public class CreateIndexCqlGeneratorIntegrationTests {
|
||||
*
|
||||
* @param <T> The concrete unit test class to which this integration test corresponds.
|
||||
*/
|
||||
public static abstract class Base<T extends CreateIndexTest> extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
public static abstract class Base<T extends CreateIndexTest> extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
T unit;
|
||||
|
||||
public abstract T unit();
|
||||
@@ -34,9 +34,9 @@ public class CreateIndexCqlGeneratorIntegrationTests {
|
||||
unit = unit();
|
||||
unit.prepare();
|
||||
|
||||
session.execute(unit.cql);
|
||||
SESSION.execute(unit.cql);
|
||||
|
||||
assertIndex(unit.specification, keyspace, session);
|
||||
assertIndex(unit.specification, keyspace, SESSION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -30,9 +30,9 @@ public class CreateKeyspaceCqlGeneratorIntegrationTests {
|
||||
unit = unit();
|
||||
unit.prepare();
|
||||
|
||||
session.execute(unit.cql);
|
||||
SYSTEM.execute(unit.cql);
|
||||
|
||||
assertKeyspace(unit.specification, unit.keyspace, session);
|
||||
assertKeyspace(unit.specification, unit.keyspace, SYSTEM);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -50,5 +50,5 @@ public class CreateKeyspaceCqlGeneratorIntegrationTests {
|
||||
public NetworkTopologyTest unit() {
|
||||
return new NetworkTopologyTest();
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -5,7 +5,7 @@ import static org.springframework.cassandra.test.integration.core.cql.generator.
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests.BasicTest;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests.CompositePartitionKeyTest;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests.CreateTableTest;
|
||||
@@ -26,7 +26,7 @@ public class CreateTableCqlGeneratorIntegrationTests {
|
||||
*
|
||||
* @param <T> The concrete unit test class to which this integration test corresponds.
|
||||
*/
|
||||
public static abstract class Base<T extends CreateTableTest> extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
public static abstract class Base<T extends CreateTableTest> extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
T unit;
|
||||
|
||||
public abstract T unit();
|
||||
@@ -36,9 +36,9 @@ public class CreateTableCqlGeneratorIntegrationTests {
|
||||
unit = unit();
|
||||
unit.prepare();
|
||||
|
||||
session.execute(unit.cql);
|
||||
SESSION.execute(unit.cql);
|
||||
|
||||
assertTable(unit.specification, keyspace, session);
|
||||
assertTable(unit.specification, keyspace, SESSION);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.CreateIndexCqlGeneratorTests;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.DropIndexCqlGeneratorTests;
|
||||
|
||||
@@ -18,7 +18,7 @@ import org.springframework.cassandra.test.unit.core.cql.generator.DropIndexCqlGe
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
*/
|
||||
public class IndexLifecycleCqlGeneratorIntegrationTests extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
public class IndexLifecycleCqlGeneratorIntegrationTests extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
Logger log = LoggerFactory.getLogger(IndexLifecycleCqlGeneratorIntegrationTests.class);
|
||||
|
||||
@@ -42,19 +42,19 @@ public class IndexLifecycleCqlGeneratorIntegrationTests extends AbstractEmbedded
|
||||
dropIfExists.prepare();
|
||||
|
||||
log.info(createTest.cql);
|
||||
session.execute(createTest.cql);
|
||||
SESSION.execute(createTest.cql);
|
||||
|
||||
assertIndex(createTest.specification, keyspace, session);
|
||||
assertIndex(createTest.specification, keyspace, SESSION);
|
||||
|
||||
log.info(dropTest.cql);
|
||||
session.execute(dropTest.cql);
|
||||
SESSION.execute(dropTest.cql);
|
||||
|
||||
assertNoIndex(createTest.specification, keyspace, session);
|
||||
assertNoIndex(createTest.specification, keyspace, SESSION);
|
||||
|
||||
// log.info(dropIfExists.cql);
|
||||
// session.execute(dropIfExists.cql);
|
||||
// SESSION.execute(dropIfExists.cql);
|
||||
//
|
||||
// assertNoIndex(createTest.specification, keyspace, session);
|
||||
// assertNoIndex(createTest.specification, keyspace, SESSION);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -26,7 +26,7 @@ import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cassandra.core.cql.generator.DropTableCqlGenerator;
|
||||
import org.springframework.cassandra.core.keyspace.DropTableSpecification;
|
||||
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.AlterTableCqlGeneratorTests;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.DropTableCqlGeneratorTests;
|
||||
@@ -36,7 +36,7 @@ import org.springframework.cassandra.test.unit.core.cql.generator.DropTableCqlGe
|
||||
*
|
||||
* @author David Webb
|
||||
*/
|
||||
public class TableLifecycleIntegrationTest extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
public class TableLifecycleIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(TableLifecycleIntegrationTest.class);
|
||||
|
||||
@@ -44,10 +44,14 @@ public class TableLifecycleIntegrationTest extends AbstractEmbeddedCassandraInte
|
||||
|
||||
public TableLifecycleIntegrationTest() {
|
||||
super("tlit");
|
||||
clear = true;
|
||||
}
|
||||
|
||||
// This only ensures the keyspace exists before each test, while using a static session from the parent object.
|
||||
@Override
|
||||
public boolean dropKeyspaceAfterTest() {
|
||||
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(
|
||||
@@ -61,18 +65,18 @@ public class TableLifecycleIntegrationTest extends AbstractEmbeddedCassandraInte
|
||||
|
||||
log.info(createTableTest.cql);
|
||||
|
||||
session.execute(createTableTest.cql);
|
||||
SESSION.execute(createTableTest.cql);
|
||||
|
||||
assertTable(createTableTest.specification, keyspace, session);
|
||||
assertTable(createTableTest.specification, keyspace, SESSION);
|
||||
|
||||
DropTableTest dropTest = new DropTableTest();
|
||||
dropTest.prepare();
|
||||
|
||||
log.info(dropTest.cql);
|
||||
|
||||
session.execute(dropTest.cql);
|
||||
SESSION.execute(dropTest.cql);
|
||||
|
||||
assertNoTable(dropTest.specification, keyspace, session);
|
||||
assertNoTable(dropTest.specification, keyspace, SESSION);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -82,18 +86,18 @@ public class TableLifecycleIntegrationTest extends AbstractEmbeddedCassandraInte
|
||||
|
||||
log.info(createTableTest.cql);
|
||||
|
||||
session.execute(createTableTest.cql);
|
||||
SESSION.execute(createTableTest.cql);
|
||||
|
||||
assertTable(createTableTest.specification, keyspace, session);
|
||||
assertTable(createTableTest.specification, keyspace, SESSION);
|
||||
|
||||
AlterTableCqlGeneratorTests.MultipleOptionsTest alterTest = new AlterTableCqlGeneratorTests.MultipleOptionsTest();
|
||||
alterTest.prepare();
|
||||
|
||||
log.info(alterTest.cql);
|
||||
|
||||
session.execute(alterTest.cql);
|
||||
SESSION.execute(alterTest.cql);
|
||||
|
||||
// assertTable(alterTest.specification, keyspace, session);
|
||||
// assertTable(alterTest.specification, keyspace, SESSION);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -21,6 +21,7 @@ import org.junit.Test;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCqlGeneratorTests;
|
||||
|
||||
/**
|
||||
@@ -28,7 +29,7 @@ import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCql
|
||||
*
|
||||
* @author David Webb
|
||||
*/
|
||||
public class TableOptionsIntegrationTest extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
public class TableOptionsIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
private final static Logger log = LoggerFactory.getLogger(TableOptionsIntegrationTest.class);
|
||||
|
||||
@@ -41,8 +42,8 @@ public class TableOptionsIntegrationTest extends AbstractEmbeddedCassandraIntegr
|
||||
|
||||
log.info(optionsTest.cql);
|
||||
|
||||
session.execute(optionsTest.cql);
|
||||
SESSION.execute(optionsTest.cql);
|
||||
|
||||
assertTable(optionsTest.specification, keyspace, session);
|
||||
assertTable(optionsTest.specification, keyspace, SESSION);
|
||||
}
|
||||
}
|
||||
@@ -46,7 +46,7 @@ import org.springframework.cassandra.core.RowCallbackHandler;
|
||||
import org.springframework.cassandra.core.RowIterator;
|
||||
import org.springframework.cassandra.core.RowMapper;
|
||||
import org.springframework.cassandra.core.SessionCallback;
|
||||
import org.springframework.cassandra.test.integration.AbstractEmbeddedCassandraIntegrationTest;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
import org.springframework.dao.DataAccessException;
|
||||
import org.springframework.util.CollectionUtils;
|
||||
|
||||
@@ -65,7 +65,7 @@ import com.datastax.driver.core.exceptions.DriverException;
|
||||
* @author David Webb
|
||||
*
|
||||
*/
|
||||
public class CassandraOperationsTest extends AbstractEmbeddedCassandraIntegrationTest {
|
||||
public class CassandraOperationsTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
private static CassandraOperations cassandraTemplate;
|
||||
|
||||
@@ -89,8 +89,8 @@ public class CassandraOperationsTest extends AbstractEmbeddedCassandraIntegratio
|
||||
CASSANDRA_NATIVE_PORT);
|
||||
|
||||
public CassandraOperationsTest() {
|
||||
super("sdctest");
|
||||
clear = true;
|
||||
super();
|
||||
// TODO clear = true;
|
||||
}
|
||||
|
||||
@Before
|
||||
@@ -106,7 +106,7 @@ public class CassandraOperationsTest extends AbstractEmbeddedCassandraIntegratio
|
||||
// "cassandraOperationsTest-cql-dataload.cql", keyspace), CASSANDRA_CONFIG, CASSANDRA_HOST,
|
||||
// CASSANDRA_NATIVE_PORT);
|
||||
|
||||
cassandraTemplate = new CassandraTemplate(session);
|
||||
cassandraTemplate = new CassandraTemplate(SESSION);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -160,8 +160,6 @@ public class CassandraOperationsTest extends AbstractEmbeddedCassandraIntegratio
|
||||
@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<?>>();
|
||||
@@ -185,8 +183,6 @@ 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][];
|
||||
|
||||
@@ -11,6 +11,7 @@ import org.springframework.cassandra.core.keyspace.AlterKeyspaceSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.DefaultOption;
|
||||
import org.springframework.cassandra.core.keyspace.KeyspaceOption;
|
||||
import org.springframework.cassandra.core.keyspace.Option;
|
||||
import org.springframework.cassandra.test.unit.support.Utils;
|
||||
|
||||
public class AlterKeyspaceCqlGeneratorTests {
|
||||
|
||||
@@ -23,8 +24,8 @@ public class AlterKeyspaceCqlGeneratorTests {
|
||||
|
||||
private static void assertReplicationMap(Map<Option, Object> replicationMap, String cql) {
|
||||
assertTrue(cql.contains(" WITH replication = { "));
|
||||
|
||||
for (Map.Entry<Option, Object> entry : replicationMap.entrySet() ) {
|
||||
|
||||
for (Map.Entry<Option, Object> entry : replicationMap.entrySet()) {
|
||||
String keyValuePair = "'" + entry.getKey().getName() + "' : '" + entry.getValue().toString() + "'";
|
||||
assertTrue(cql.contains(keyValuePair));
|
||||
}
|
||||
@@ -38,28 +39,28 @@ public class AlterKeyspaceCqlGeneratorTests {
|
||||
* Convenient base class that other test classes can use so as not to repeat the generics declarations.
|
||||
*/
|
||||
public static abstract class AlterKeyspaceTest extends
|
||||
KeyspaceOperationCqlGeneratorTest<AlterKeyspaceSpecification, AlterKeyspaceCqlGenerator> {
|
||||
KeyspaceOperationCqlGeneratorTest<AlterKeyspaceSpecification, AlterKeyspaceCqlGenerator> {
|
||||
}
|
||||
|
||||
public static class CompleteTest extends AlterKeyspaceTest {
|
||||
|
||||
public String name = "mykeyspace";
|
||||
public String name = Utils.randomKeyspaceName();
|
||||
public Boolean durableWrites = true;
|
||||
|
||||
|
||||
public Map<Option, Object> replicationMap = new HashMap<Option, Object>();
|
||||
|
||||
@Override
|
||||
public AlterKeyspaceSpecification specification() {
|
||||
replicationMap.put( new DefaultOption( "class", String.class, false, false, true ), "SimpleStrategy" );
|
||||
replicationMap.put( new DefaultOption( "replication_factor", Long.class, false, false, true ), 1 );
|
||||
replicationMap.put( new DefaultOption( "dc1", Long.class, false, false, true ), 2 );
|
||||
replicationMap.put( new DefaultOption( "dc2", Long.class, false, false, true ), 3 );
|
||||
|
||||
return AlterKeyspaceSpecification.alterKeyspace()
|
||||
.name(name)
|
||||
.with(KeyspaceOption.REPLICATION, replicationMap)
|
||||
replicationMap.put(new DefaultOption("class", String.class, false, false, true), "SimpleStrategy");
|
||||
replicationMap.put(new DefaultOption("replication_factor", Long.class, false, false, true), 1);
|
||||
replicationMap.put(new DefaultOption("dc1", Long.class, false, false, true), 2);
|
||||
replicationMap.put(new DefaultOption("dc2", Long.class, false, false, true), 3);
|
||||
|
||||
return AlterKeyspaceSpecification.alterKeyspace().name(name).with(KeyspaceOption.REPLICATION, replicationMap)
|
||||
.with(KeyspaceOption.DURABLE_WRITES, durableWrites);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlterKeyspaceCqlGenerator generator() {
|
||||
return new AlterKeyspaceCqlGenerator(specification);
|
||||
}
|
||||
@@ -78,20 +79,20 @@ public class AlterKeyspaceCqlGeneratorTests {
|
||||
|
||||
public String name = "mytable";
|
||||
public Boolean durableWrites = true;
|
||||
|
||||
|
||||
public Map<Option, Object> replicationMap = new HashMap<Option, Object>();
|
||||
|
||||
@Override
|
||||
public AlterKeyspaceSpecification specification() {
|
||||
replicationMap.put( new DefaultOption( "class", String.class, false, false, true ), "SimpleStrategy" );
|
||||
replicationMap.put( new DefaultOption( "replication_factor", Long.class, false, false, true ), 1 );
|
||||
replicationMap.put( new DefaultOption( "dc1", Long.class, false, false, true ), 2 );
|
||||
replicationMap.put( new DefaultOption( "dc2", Long.class, false, false, true ), 3 );
|
||||
|
||||
return AlterKeyspaceSpecification.alterKeyspace()
|
||||
.name(name)
|
||||
.with(KeyspaceOption.REPLICATION, replicationMap);
|
||||
replicationMap.put(new DefaultOption("class", String.class, false, false, true), "SimpleStrategy");
|
||||
replicationMap.put(new DefaultOption("replication_factor", Long.class, false, false, true), 1);
|
||||
replicationMap.put(new DefaultOption("dc1", Long.class, false, false, true), 2);
|
||||
replicationMap.put(new DefaultOption("dc2", Long.class, false, false, true), 3);
|
||||
|
||||
return AlterKeyspaceSpecification.alterKeyspace().name(name).with(KeyspaceOption.REPLICATION, replicationMap);
|
||||
}
|
||||
|
||||
@Override
|
||||
public AlterKeyspaceCqlGenerator generator() {
|
||||
return new AlterKeyspaceCqlGenerator(specification);
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.springframework.cassandra.core.keyspace.CreateKeyspaceSpecification;
|
||||
import org.springframework.cassandra.core.keyspace.DefaultOption;
|
||||
import org.springframework.cassandra.core.keyspace.KeyspaceOption;
|
||||
import org.springframework.cassandra.core.keyspace.Option;
|
||||
import org.springframework.cassandra.test.unit.support.Utils;
|
||||
|
||||
public class CreateKeyspaceCqlGeneratorTests {
|
||||
|
||||
@@ -51,7 +52,7 @@ public class CreateKeyspaceCqlGeneratorTests {
|
||||
|
||||
public static class BasicTest extends CreateKeyspaceTest {
|
||||
|
||||
public String name = "mykeyspace";
|
||||
public String name = Utils.randomKeyspaceName();
|
||||
public Boolean durableWrites = true;
|
||||
|
||||
public Map<Option, Object> replicationMap = KeyspaceAttributes.newSimpleReplication();
|
||||
@@ -76,7 +77,7 @@ public class CreateKeyspaceCqlGeneratorTests {
|
||||
|
||||
public static class NetworkTopologyTest extends CreateKeyspaceTest {
|
||||
|
||||
public String name = "mykeyspace";
|
||||
public String name = Utils.randomKeyspaceName();
|
||||
public Boolean durableWrites = false;
|
||||
|
||||
public Map<Option, Object> replicationMap = new HashMap<Option, Object>();
|
||||
|
||||
@@ -5,6 +5,7 @@ import static org.junit.Assert.assertTrue;
|
||||
import org.junit.Test;
|
||||
import org.springframework.cassandra.core.cql.generator.DropKeyspaceCqlGenerator;
|
||||
import org.springframework.cassandra.core.keyspace.DropKeyspaceSpecification;
|
||||
import org.springframework.cassandra.test.unit.support.Utils;
|
||||
|
||||
public class DropKeyspaceCqlGeneratorTests {
|
||||
|
||||
@@ -24,12 +25,14 @@ public class DropKeyspaceCqlGeneratorTests {
|
||||
|
||||
public static class BasicTest extends DropTableTest {
|
||||
|
||||
public String name = "mykeyspace";
|
||||
public String name = Utils.randomKeyspaceName();
|
||||
|
||||
@Override
|
||||
public DropKeyspaceSpecification specification() {
|
||||
return DropKeyspaceSpecification.dropKeyspace().name(name);
|
||||
}
|
||||
|
||||
@Override
|
||||
public DropKeyspaceCqlGenerator generator() {
|
||||
return new DropKeyspaceCqlGenerator(specification);
|
||||
}
|
||||
|
||||
@@ -0,0 +1,11 @@
|
||||
package org.springframework.cassandra.test.unit.support;
|
||||
|
||||
import java.util.UUID;
|
||||
|
||||
public class Utils {
|
||||
|
||||
public static String randomKeyspaceName() {
|
||||
return "ks" + UUID.randomUUID().toString().replace("-", "");
|
||||
}
|
||||
|
||||
}
|
||||
@@ -6,11 +6,8 @@
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
|
||||
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd">
|
||||
|
||||
<context:property-placeholder
|
||||
location="classpath:/org/springframework/cassandra/test/integration/config/xml/xmlconfigtest.properties" />
|
||||
|
||||
<cassandra:cluster id="cassandra-cluster"
|
||||
contactPoints="${cassandra.contactPoints}" port="${cassandra.port}">
|
||||
contactPoints="localhost" port="9042">
|
||||
<cassandra:local-pooling-options
|
||||
min-simultaneous-requests="25" max-simultaneous-requests="100"
|
||||
core-connections="2" max-connections="8" />
|
||||
@@ -24,7 +21,7 @@
|
||||
</cassandra:cluster>
|
||||
|
||||
<cassandra:session id="cassandra-session"
|
||||
keyspace-name="${cassandra.keyspace}" />
|
||||
keyspace-name="xmlconfigtest" />
|
||||
|
||||
<bean id="cassandraTemplate" class="org.springframework.cassandra.core.CassandraTemplate">
|
||||
<constructor-arg ref="cassandra-session" />
|
||||
|
||||
@@ -1,3 +0,0 @@
|
||||
cassandra.contactPoints=localhost
|
||||
cassandra.port=9042
|
||||
cassandra.keyspace=xmlconfigtest
|
||||
Reference in New Issue
Block a user