[JAVA-9585] Convert Cassandra integration tests to Live tests
This commit is contained in:
parent
048547c003
commit
d70d23f8e1
|
@ -47,8 +47,8 @@ public class SpringContextTest {
|
|||
}
|
||||
|
||||
@Before
|
||||
public void createTable() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<String, Object>());
|
||||
public void createTable() {
|
||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
|
|
@ -1,17 +1,15 @@
|
|||
package com.baeldung.spring.data.cassandra.repository;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import com.baeldung.spring.data.cassandra.config.CassandraConfig;
|
||||
import com.baeldung.spring.data.cassandra.model.Book;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.utils.UUIDs;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.thrift.transport.TTransportException;
|
||||
import com.baeldung.spring.data.cassandra.config.CassandraConfig;
|
||||
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
|
@ -25,15 +23,24 @@ import org.springframework.data.cassandra.core.CassandraAdminOperations;
|
|||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.utils.UUIDs;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.io.IOException;
|
||||
import java.util.HashMap;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotEquals;
|
||||
|
||||
/**
|
||||
* Live test for Cassandra testing.
|
||||
*
|
||||
* This can be converted to IntegrationTest once cassandra-unit tests can be executed in parallel and
|
||||
* multiple test servers started as part of test suite.
|
||||
*
|
||||
* Open cassandra-unit issue for parallel execution: https://github.com/jsevellec/cassandra-unit/issues/155
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = CassandraConfig.class)
|
||||
public class BookRepositoryIntegrationTest {
|
||||
private static final Log LOGGER = LogFactory.getLog(BookRepositoryIntegrationTest.class);
|
||||
public class BookRepositoryLiveTest {
|
||||
private static final Log LOGGER = LogFactory.getLog(BookRepositoryLiveTest.class);
|
||||
|
||||
public static final String KEYSPACE_CREATION_QUERY = "CREATE KEYSPACE IF NOT EXISTS testKeySpace WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '3' };";
|
||||
|
||||
|
@ -47,8 +54,6 @@ public class BookRepositoryIntegrationTest {
|
|||
@Autowired
|
||||
private CassandraAdminOperations adminTemplate;
|
||||
|
||||
//
|
||||
|
||||
@BeforeClass
|
||||
public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
||||
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
|
||||
|
@ -62,8 +67,8 @@ public class BookRepositoryIntegrationTest {
|
|||
}
|
||||
|
||||
@Before
|
||||
public void createTable() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<String, Object>());
|
||||
public void createTable() {
|
||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<>());
|
||||
}
|
||||
|
||||
@Test
|
|
@ -1,17 +1,13 @@
|
|||
package com.baeldung.spring.data.cassandra.repository;
|
||||
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import com.baeldung.spring.data.cassandra.config.CassandraConfig;
|
||||
import com.baeldung.spring.data.cassandra.model.Book;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import com.datastax.driver.core.querybuilder.Select;
|
||||
import com.datastax.driver.core.utils.UUIDs;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
@ -30,17 +26,28 @@ import org.springframework.data.cassandra.core.CassandraOperations;
|
|||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import com.datastax.driver.core.querybuilder.Select;
|
||||
import com.datastax.driver.core.utils.UUIDs;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
|
||||
import static junit.framework.TestCase.assertNull;
|
||||
import static org.hamcrest.CoreMatchers.is;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
/**
|
||||
* Live test for Cassandra testing.
|
||||
*
|
||||
* This can be converted to IntegrationTest once cassandra-unit tests can be executed in parallel and
|
||||
* multiple test servers started as part of test suite.
|
||||
*
|
||||
* Open cassandra-unit issue for parallel execution: https://github.com/jsevellec/cassandra-unit/issues/155
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = CassandraConfig.class)
|
||||
public class CassandraTemplateIntegrationTest {
|
||||
private static final Log LOGGER = LogFactory.getLog(CassandraTemplateIntegrationTest.class);
|
||||
public class CassandraTemplateLiveTest {
|
||||
private static final Log LOGGER = LogFactory.getLog(CassandraTemplateLiveTest.class);
|
||||
|
||||
public static final String KEYSPACE_CREATION_QUERY = "CREATE KEYSPACE IF NOT EXISTS testKeySpace " + "WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '3' };";
|
||||
|
||||
|
@ -54,8 +61,6 @@ public class CassandraTemplateIntegrationTest {
|
|||
@Autowired
|
||||
private CassandraOperations cassandraTemplate;
|
||||
|
||||
//
|
||||
|
||||
@BeforeClass
|
||||
public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
||||
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
|
||||
|
@ -69,8 +74,8 @@ public class CassandraTemplateIntegrationTest {
|
|||
}
|
||||
|
||||
@Before
|
||||
public void createTable() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<String, Object>());
|
||||
public void createTable() {
|
||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<>());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
@ -111,7 +116,7 @@ public class CassandraTemplateIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void whenDeletingASelectedBook_thenNotAvailableOnRetrieval() throws InterruptedException {
|
||||
public void whenDeletingASelectedBook_thenNotAvailableOnRetrieval() {
|
||||
final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "OReilly Media", ImmutableSet.of("Computer", "Software"));
|
||||
cassandraTemplate.insert(javaBook);
|
||||
cassandraTemplate.delete(javaBook);
|
|
@ -1,19 +1,16 @@
|
|||
package com.baeldung.spring.data.cassandra.repository;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.apache.thrift.transport.TTransportException;
|
||||
import com.baeldung.spring.data.cassandra.config.CassandraConfig;
|
||||
import com.baeldung.spring.data.cassandra.model.Book;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.querybuilder.Insert;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import com.datastax.driver.core.querybuilder.Select;
|
||||
import com.datastax.driver.core.utils.UUIDs;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
|
@ -28,18 +25,25 @@ import org.springframework.data.cassandra.core.CassandraOperations;
|
|||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.querybuilder.Insert;
|
||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
||||
import com.datastax.driver.core.querybuilder.Select;
|
||||
import com.datastax.driver.core.utils.UUIDs;
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.UUID;
|
||||
|
||||
import static junit.framework.TestCase.assertEquals;
|
||||
|
||||
/**
|
||||
* Live test for Cassandra testing.
|
||||
*
|
||||
* This can be converted to IntegrationTest once cassandra-unit tests can be executed in parallel and
|
||||
* multiple test servers started as part of test suite.
|
||||
*
|
||||
* Open cassandra-unit issue for parallel execution: https://github.com/jsevellec/cassandra-unit/issues/155
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration(classes = CassandraConfig.class)
|
||||
public class CqlQueriesIntegrationTest {
|
||||
private static final Log LOGGER = LogFactory.getLog(CqlQueriesIntegrationTest.class);
|
||||
public class CqlQueriesLiveTest {
|
||||
private static final Log LOGGER = LogFactory.getLog(CqlQueriesLiveTest.class);
|
||||
|
||||
public static final String KEYSPACE_CREATION_QUERY = "CREATE KEYSPACE IF NOT EXISTS testKeySpace " + "WITH replication = { 'class': 'SimpleStrategy', 'replication_factor': '3' };";
|
||||
|
||||
|
@ -53,10 +57,8 @@ public class CqlQueriesIntegrationTest {
|
|||
@Autowired
|
||||
private CassandraOperations cassandraTemplate;
|
||||
|
||||
//
|
||||
|
||||
@BeforeClass
|
||||
public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
||||
public static void startCassandraEmbedded() throws Exception {
|
||||
EmbeddedCassandraServerHelper.startEmbeddedCassandra(25000);
|
||||
final Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build();
|
||||
LOGGER.info("Server Started at 127.0.0.1:9142... ");
|
||||
|
@ -68,8 +70,8 @@ public class CqlQueriesIntegrationTest {
|
|||
}
|
||||
|
||||
@Before
|
||||
public void createTable() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<String, Object>());
|
||||
public void createTable() {
|
||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<>());
|
||||
}
|
||||
|
||||
@Test
|
Loading…
Reference in New Issue