DATACASS-196 - Improve usage of embedded Cassandra in integration tests.
Moved to non-static fields for Cassandra Cluster and Session and properly connect and close resources in @Before/@After callbacks. Added missing license headers where necessary.
This commit is contained in:
@@ -1,20 +1,40 @@
|
||||
/*
|
||||
* Copyright 2013-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.springframework.cassandra.core.CqlOperations;
|
||||
import org.springframework.cassandra.core.CqlTemplate;
|
||||
|
||||
/**
|
||||
* @author Matthew T. Adams
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class AbstractCqlTemplateIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
protected CqlOperations t;
|
||||
|
||||
{
|
||||
t = new CqlTemplate(SESSION);
|
||||
}
|
||||
|
||||
public AbstractCqlTemplateIntegrationTest() {}
|
||||
|
||||
public AbstractCqlTemplateIntegrationTest(String keyspace) {
|
||||
super(keyspace);
|
||||
}
|
||||
|
||||
|
||||
@Before
|
||||
public void createTemplate() {
|
||||
this.t = new CqlTemplate(session);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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,6 +21,8 @@ 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;
|
||||
@@ -34,6 +36,7 @@ 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 {
|
||||
|
||||
@@ -52,11 +55,11 @@ public class AbstractEmbeddedCassandraIntegrationTest {
|
||||
/**
|
||||
* The session connected to the system keyspace.
|
||||
*/
|
||||
protected static Session SYSTEM;
|
||||
protected Session system;
|
||||
/**
|
||||
* The {@link Cluster} that's connected to Cassandra.
|
||||
* The {@link Cluster} that'session connected to Cassandra.
|
||||
*/
|
||||
protected static Cluster CLUSTER;
|
||||
protected Cluster cluster;
|
||||
|
||||
public static String randomKeyspaceName() {
|
||||
return Utils.randomKeyspaceName();
|
||||
@@ -73,23 +76,17 @@ public class AbstractEmbeddedCassandraIntegrationTest {
|
||||
return Cluster.builder().addContactPoint(CASSANDRA_HOST).withPort(CASSANDRA_NATIVE_PORT).build();
|
||||
}
|
||||
|
||||
/**
|
||||
* Ensures that the cluster is created and that the session {@link #SYSTEM} is connected to it.
|
||||
*/
|
||||
public static void ensureClusterConnection() {
|
||||
@Before
|
||||
public void connect() {
|
||||
|
||||
// check cluster
|
||||
if (CLUSTER == null) {
|
||||
CLUSTER = cluster();
|
||||
}
|
||||
|
||||
// check system session connected
|
||||
if (SYSTEM == null) {
|
||||
SYSTEM = CLUSTER.connect();
|
||||
}
|
||||
this.cluster = cluster();
|
||||
this.system = cluster.connect();
|
||||
}
|
||||
|
||||
public AbstractEmbeddedCassandraIntegrationTest() {
|
||||
ensureClusterConnection();
|
||||
@After
|
||||
public void disconnect() {
|
||||
|
||||
this.system.close();
|
||||
this.cluster.close();
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.cassandra.test.integration;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.util.StringUtils;
|
||||
@@ -27,15 +28,16 @@ import com.datastax.driver.core.Session;
|
||||
* Abstract base integration test class that creates a keyspace
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
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.
|
||||
* The session that'session connected to the keyspace used in the current instance'session test.
|
||||
*/
|
||||
protected static Session SESSION;
|
||||
protected Session session;
|
||||
|
||||
/**
|
||||
* The name of the keyspace to use for this test instance.
|
||||
@@ -47,16 +49,7 @@ public abstract class AbstractKeyspaceCreatingIntegrationTest extends AbstractEm
|
||||
}
|
||||
|
||||
public AbstractKeyspaceCreatingIntegrationTest(String keyspace) {
|
||||
|
||||
this.keyspace = keyspace;
|
||||
ensureKeyspaceAndSession();
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns whether we're currently connected to the keyspace.
|
||||
*/
|
||||
public static boolean connected() {
|
||||
return SESSION != null;
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -67,6 +60,7 @@ public abstract class AbstractKeyspaceCreatingIntegrationTest extends AbstractEm
|
||||
return false;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void ensureKeyspaceAndSession() {
|
||||
|
||||
// ensure that test keyspace exists
|
||||
@@ -77,23 +71,23 @@ public abstract class AbstractKeyspaceCreatingIntegrationTest extends AbstractEm
|
||||
|
||||
if (keyspace != null) {
|
||||
// see if we need to create the keyspace
|
||||
KeyspaceMetadata kmd = CLUSTER.getMetadata().getKeyspace(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);
|
||||
system.execute(cql);
|
||||
}
|
||||
}
|
||||
|
||||
// keyspace now exists; ensure the session is using it
|
||||
if (SESSION == null) {
|
||||
if (session == null) {
|
||||
|
||||
log.info("connecting to keyspace {}", keyspace == null ? "system" : keyspace + "...");
|
||||
|
||||
SESSION = keyspace == null ? CLUSTER.connect() : CLUSTER.connect(keyspace);
|
||||
session = keyspace == null ? cluster.connect() : cluster.connect(keyspace);
|
||||
|
||||
log.info("connected to keyspace {}", keyspace == null ? "system" : keyspace);
|
||||
|
||||
@@ -102,7 +96,7 @@ public abstract class AbstractKeyspaceCreatingIntegrationTest extends AbstractEm
|
||||
log.info("session already connected to a keyspace; attempting to change to use {}", keyspace);
|
||||
|
||||
String cql = "USE " + (keyspace == null ? "system" : keyspace) + ";";
|
||||
SESSION.execute(cql);
|
||||
session.execute(cql);
|
||||
|
||||
log.info("now using keyspace " + keyspace);
|
||||
}
|
||||
@@ -110,13 +104,14 @@ public abstract class AbstractKeyspaceCreatingIntegrationTest extends AbstractEm
|
||||
|
||||
@After
|
||||
public void after() {
|
||||
|
||||
if (dropKeyspaceAfterTest() && keyspace != null) {
|
||||
|
||||
SESSION.execute("USE system");
|
||||
session.execute("USE system");
|
||||
|
||||
log.info("dropping keyspace {} ...", keyspace);
|
||||
|
||||
SYSTEM.execute("DROP KEYSPACE " + keyspace);
|
||||
system.execute("DROP KEYSPACE " + keyspace);
|
||||
|
||||
log.info("dropped keyspace {}", keyspace);
|
||||
}
|
||||
|
||||
@@ -1,19 +1,38 @@
|
||||
/*
|
||||
* Copyright 2013-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.config.java;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.cassandra.config.java.AbstractCqlTemplateConfiguration;
|
||||
import org.springframework.cassandra.core.CqlTemplate;
|
||||
import org.springframework.cassandra.test.integration.AbstractKeyspaceCreatingIntegrationTest;
|
||||
import org.springframework.cassandra.test.integration.config.IntegrationTestUtils;
|
||||
import org.springframework.cassandra.test.unit.support.Utils;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
|
||||
import org.springframework.context.annotation.Configuration;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
/**
|
||||
* @author Matthews T. Adams
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class CqlTemplateConfigIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
public static final String KEYSPACE_NAME = Utils.randomKeyspaceName();
|
||||
@@ -31,9 +50,21 @@ public class CqlTemplateConfigIntegrationTest extends AbstractKeyspaceCreatingIn
|
||||
return CASSANDRA_NATIVE_PORT;
|
||||
}
|
||||
}
|
||||
|
||||
@Autowired
|
||||
CqlTemplate template;
|
||||
|
||||
Session session;
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
this.context = new AnnotationConfigApplicationContext(Config.class);
|
||||
this.session = context.getBean(Session.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
context.close();
|
||||
}
|
||||
|
||||
public CqlTemplateConfigIntegrationTest() {
|
||||
super(KEYSPACE_NAME);
|
||||
@@ -41,6 +72,6 @@ public class CqlTemplateConfigIntegrationTest extends AbstractKeyspaceCreatingIn
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
IntegrationTestUtils.assertCqlTemplate(template);
|
||||
IntegrationTestUtils.assertCqlTemplate(context.getBean(CqlTemplate.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -15,22 +15,23 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.config.xml;
|
||||
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.cassandra.core.CqlOperations;
|
||||
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;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
/**
|
||||
* @author Matthews T. Adams
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class MinimalXmlConfigTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
public static final String KEYSPACE = "minimalxmlconfigtest";
|
||||
@@ -39,17 +40,27 @@ public class MinimalXmlConfigTest extends AbstractKeyspaceCreatingIntegrationTes
|
||||
super(KEYSPACE);
|
||||
}
|
||||
|
||||
@Inject
|
||||
Session s;
|
||||
|
||||
@Inject
|
||||
CqlOperations ops;
|
||||
Session session;
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
this.context = new ClassPathXmlApplicationContext("MinimalXmlConfigTest-context.xml", getClass());
|
||||
this.session = context.getBean(Session.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
IntegrationTestUtils.assertSession(s);
|
||||
IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, s);
|
||||
|
||||
IntegrationTestUtils.assertSession(session);
|
||||
IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, session);
|
||||
|
||||
assertNotNull(ops);
|
||||
assertNotNull(context.getBean(CqlOperations.class));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -15,34 +15,46 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.config.xml;
|
||||
|
||||
import javax.inject.Inject;
|
||||
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
import org.springframework.context.ConfigurableApplicationContext;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
|
||||
import com.datastax.driver.core.Session;
|
||||
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(
|
||||
locations = "classpath:/org/springframework/cassandra/test/integration/config/xml/XmlConfigTest-context.xml")
|
||||
/**
|
||||
* @author Matthews T. Adams
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class XmlConfigTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
public static final String KEYSPACE = "xmlconfigtest";
|
||||
|
||||
@Inject
|
||||
Session s;
|
||||
|
||||
Session session;
|
||||
ConfigurableApplicationContext context;
|
||||
|
||||
public XmlConfigTest() {
|
||||
super(KEYSPACE);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
|
||||
this.context = new ClassPathXmlApplicationContext("XmlConfigTest-context.xml", getClass());
|
||||
this.session = context.getBean(Session.class);
|
||||
}
|
||||
|
||||
@After
|
||||
public void tearDown() {
|
||||
context.close();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
IntegrationTestUtils.assertSession(s);
|
||||
IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, s);
|
||||
IntegrationTestUtils.assertSession(session);
|
||||
IntegrationTestUtils.assertKeyspaceExists(KEYSPACE, session);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -29,6 +29,7 @@ import org.springframework.cassandra.test.unit.core.cql.generator.CreateIndexCql
|
||||
* Integration tests that reuse unit tests.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class CreateIndexCqlGeneratorIntegrationTests {
|
||||
|
||||
@@ -48,9 +49,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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -27,6 +27,7 @@ import org.springframework.cassandra.test.unit.core.cql.generator.CreateKeyspace
|
||||
* Integration tests that reuse unit tests.
|
||||
*
|
||||
* @author John McPeek
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class CreateKeyspaceCqlGeneratorIntegrationTests {
|
||||
|
||||
@@ -45,9 +46,9 @@ public class CreateKeyspaceCqlGeneratorIntegrationTests {
|
||||
unit = unit();
|
||||
unit.prepare();
|
||||
|
||||
SYSTEM.execute(unit.cql);
|
||||
system.execute(unit.cql);
|
||||
|
||||
assertKeyspace(unit.specification, unit.keyspace, SYSTEM);
|
||||
assertKeyspace(unit.specification, unit.keyspace, system);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -27,6 +27,7 @@ import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCql
|
||||
* Integration tests that reuse unit tests.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class CreateTableCqlGeneratorIntegrationTests {
|
||||
|
||||
@@ -37,18 +38,20 @@ 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 AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
T unit;
|
||||
|
||||
public abstract T unit();
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
|
||||
unit = unit();
|
||||
unit.prepare();
|
||||
|
||||
SESSION.execute(unit.cql);
|
||||
session.execute(unit.cql);
|
||||
|
||||
assertTable(unit.specification, keyspace, SESSION);
|
||||
assertTable(unit.specification, keyspace, session);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,3 +1,18 @@
|
||||
/*
|
||||
* Copyright 2013-2015 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.core.cql.generator;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -8,6 +23,10 @@ import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCql
|
||||
|
||||
import com.datastax.driver.core.DataType;
|
||||
|
||||
/**
|
||||
* @author Matthew T. Adams
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class FunkyIdentifierIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
public FunkyIdentifierIntegrationTest() {
|
||||
@@ -17,7 +36,7 @@ public class FunkyIdentifierIntegrationTest extends AbstractKeyspaceCreatingInte
|
||||
@Test
|
||||
public void testFunkyTableName() {
|
||||
for (String name : FunkyTableNameTest.FUNKY_LEGAL_NAMES) {
|
||||
SESSION.execute(new CreateTableCqlGenerator(CreateTableSpecification.createTable().name(name)
|
||||
session.execute(new CreateTableCqlGenerator(CreateTableSpecification.createTable().name(name)
|
||||
.partitionKeyColumn("key", DataType.text())).toCql());
|
||||
}
|
||||
}
|
||||
@@ -27,7 +46,7 @@ public class FunkyIdentifierIntegrationTest extends AbstractKeyspaceCreatingInte
|
||||
String table = "funky";
|
||||
int i = 0;
|
||||
for (String name : FunkyTableNameTest.FUNKY_LEGAL_NAMES) {
|
||||
SESSION.execute(new CreateTableCqlGenerator(CreateTableSpecification.createTable().name(table + i++)
|
||||
session.execute(new CreateTableCqlGenerator(CreateTableSpecification.createTable().name(table + i++)
|
||||
.partitionKeyColumn(name, DataType.text())).toCql());
|
||||
}
|
||||
}
|
||||
@@ -35,7 +54,7 @@ public class FunkyIdentifierIntegrationTest extends AbstractKeyspaceCreatingInte
|
||||
@Test
|
||||
public void testFunkyTableAndColumnName() {
|
||||
for (String name : FunkyTableNameTest.FUNKY_LEGAL_NAMES) {
|
||||
SESSION.execute(new CreateTableCqlGenerator(CreateTableSpecification.createTable().name(name)
|
||||
session.execute(new CreateTableCqlGenerator(CreateTableSpecification.createTable().name(name)
|
||||
.partitionKeyColumn(name, DataType.text())).toCql());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -32,6 +32,7 @@ import org.springframework.cassandra.test.unit.core.cql.generator.DropIndexCqlGe
|
||||
* Integration tests that reuse unit tests.
|
||||
*
|
||||
* @author Matthew T. Adams
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class IndexLifecycleCqlGeneratorIntegrationTests extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
@@ -57,20 +58,13 @@ public class IndexLifecycleCqlGeneratorIntegrationTests extends AbstractKeyspace
|
||||
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);
|
||||
|
||||
assertNoIndex(createTest.specification, keyspace, SESSION);
|
||||
|
||||
// log.info(dropIfExists.cql);
|
||||
// SESSION.execute(dropIfExists.cql);
|
||||
//
|
||||
// assertNoIndex(createTest.specification, keyspace, SESSION);
|
||||
session.execute(dropTest.cql);
|
||||
|
||||
assertNoIndex(createTest.specification, keyspace, session);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -35,6 +35,7 @@ import org.springframework.cassandra.test.unit.core.cql.generator.DropTableCqlGe
|
||||
* Test CREATE TABLE / ALTER TABLE / DROP TABLE
|
||||
*
|
||||
* @author David Webb
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class TableLifecycleIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
@@ -51,7 +52,7 @@ 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.
|
||||
// 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(
|
||||
@@ -65,18 +66,18 @@ public class TableLifecycleIntegrationTest extends AbstractKeyspaceCreatingInteg
|
||||
|
||||
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
|
||||
@@ -86,18 +87,18 @@ public class TableLifecycleIntegrationTest extends AbstractKeyspaceCreatingInteg
|
||||
|
||||
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);
|
||||
|
||||
}
|
||||
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -27,6 +27,7 @@ import org.springframework.cassandra.test.unit.core.cql.generator.CreateTableCql
|
||||
* Test CREATE TABLE for all Options and assert against C* TableMetaData
|
||||
*
|
||||
* @author David Webb
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class TableOptionsIntegrationTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
@@ -41,8 +42,8 @@ public class TableOptionsIntegrationTest extends AbstractKeyspaceCreatingIntegra
|
||||
|
||||
log.info(optionsTest.cql);
|
||||
|
||||
SESSION.execute(optionsTest.cql);
|
||||
session.execute(optionsTest.cql);
|
||||
|
||||
assertTable(optionsTest.specification, keyspace, SESSION);
|
||||
assertTable(optionsTest.specification, keyspace, session);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2013-2014 the original author or authors.
|
||||
* Copyright 2013-2015 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.
|
||||
@@ -15,6 +15,8 @@
|
||||
*/
|
||||
package org.springframework.cassandra.test.integration.core.template;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.LinkedList;
|
||||
import java.util.List;
|
||||
@@ -65,21 +67,17 @@ import com.datastax.driver.core.querybuilder.Insert;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import com.datastax.driver.core.querybuilder.Truncate;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
/**
|
||||
* Unit Tests for CqlTemplate
|
||||
*
|
||||
* @author David Webb
|
||||
* @author Oliver Gierke
|
||||
*/
|
||||
public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
|
||||
private static CqlOperations cqlTemplate;
|
||||
|
||||
private static Logger log = LoggerFactory.getLogger(CQLOperationsTest.class);
|
||||
|
||||
private CqlOperations cqlTemplate;
|
||||
/*
|
||||
* Objects used for test data
|
||||
*/
|
||||
@@ -92,27 +90,14 @@ public class CQLOperationsTest extends AbstractKeyspaceCreatingIntegrationTest {
|
||||
/**
|
||||
* This loads any test specific Cassandra objects
|
||||
*/
|
||||
@Rule
|
||||
@Rule
|
||||
public CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet(
|
||||
"cassandraOperationsTest-cql-dataload.cql", this.keyspace), CASSANDRA_CONFIG, CASSANDRA_HOST,
|
||||
CASSANDRA_NATIVE_PORT);
|
||||
|
||||
public CQLOperationsTest() {
|
||||
super();
|
||||
// TODO clear = true;
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setupTemplate() {
|
||||
|
||||
if (cqlTemplate == null) {
|
||||
|
||||
// CassandraCQLUnit cassandraCQLUnit = new CassandraCQLUnit(new ClassPathCQLDataSet(
|
||||
// "cassandraOperationsTest-cql-dataload.cql", keyspace), CASSANDRA_CONFIG, CASSANDRA_HOST,
|
||||
// CASSANDRA_NATIVE_PORT);
|
||||
|
||||
cqlTemplate = new CqlTemplate(SESSION);
|
||||
}
|
||||
this.cqlTemplate = new CqlTemplate(session);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user