[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
|
@Before
|
||||||
public void createTable() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
public void createTable() {
|
||||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<String, Object>());
|
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
|
|
@ -1,17 +1,15 @@
|
||||||
package com.baeldung.spring.data.cassandra.repository;
|
package com.baeldung.spring.data.cassandra.repository;
|
||||||
|
|
||||||
import static org.junit.Assert.assertEquals;
|
import com.baeldung.spring.data.cassandra.config.CassandraConfig;
|
||||||
import static org.junit.Assert.assertNotEquals;
|
|
||||||
|
|
||||||
import java.io.IOException;
|
|
||||||
import java.util.HashMap;
|
|
||||||
|
|
||||||
import com.baeldung.spring.data.cassandra.model.Book;
|
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.cassandra.exceptions.ConfigurationException;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
import org.apache.commons.logging.LogFactory;
|
||||||
import org.apache.thrift.transport.TTransportException;
|
import org.apache.thrift.transport.TTransportException;
|
||||||
import com.baeldung.spring.data.cassandra.config.CassandraConfig;
|
|
||||||
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
|
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
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.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import com.datastax.driver.core.Cluster;
|
import java.io.IOException;
|
||||||
import com.datastax.driver.core.Session;
|
import java.util.HashMap;
|
||||||
import com.datastax.driver.core.utils.UUIDs;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
|
|
||||||
|
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)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = CassandraConfig.class)
|
@ContextConfiguration(classes = CassandraConfig.class)
|
||||||
public class BookRepositoryIntegrationTest {
|
public class BookRepositoryLiveTest {
|
||||||
private static final Log LOGGER = LogFactory.getLog(BookRepositoryIntegrationTest.class);
|
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' };";
|
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
|
@Autowired
|
||||||
private CassandraAdminOperations adminTemplate;
|
private CassandraAdminOperations adminTemplate;
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
||||||
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
|
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
|
||||||
|
@ -62,8 +67,8 @@ public class BookRepositoryIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void createTable() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
public void createTable() {
|
||||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<String, Object>());
|
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
|
@ -1,17 +1,13 @@
|
||||||
package com.baeldung.spring.data.cassandra.repository;
|
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.config.CassandraConfig;
|
||||||
import com.baeldung.spring.data.cassandra.model.Book;
|
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.cassandra.exceptions.ConfigurationException;
|
||||||
import org.apache.commons.logging.Log;
|
import org.apache.commons.logging.Log;
|
||||||
import org.apache.commons.logging.LogFactory;
|
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.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import com.datastax.driver.core.Cluster;
|
import java.io.IOException;
|
||||||
import com.datastax.driver.core.Session;
|
import java.util.ArrayList;
|
||||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
import java.util.HashMap;
|
||||||
import com.datastax.driver.core.querybuilder.Select;
|
import java.util.List;
|
||||||
import com.datastax.driver.core.utils.UUIDs;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
|
|
||||||
|
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)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = CassandraConfig.class)
|
@ContextConfiguration(classes = CassandraConfig.class)
|
||||||
public class CassandraTemplateIntegrationTest {
|
public class CassandraTemplateLiveTest {
|
||||||
private static final Log LOGGER = LogFactory.getLog(CassandraTemplateIntegrationTest.class);
|
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' };";
|
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
|
@Autowired
|
||||||
private CassandraOperations cassandraTemplate;
|
private CassandraOperations cassandraTemplate;
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
||||||
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
|
EmbeddedCassandraServerHelper.startEmbeddedCassandra();
|
||||||
|
@ -69,8 +74,8 @@ public class CassandraTemplateIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void createTable() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
public void createTable() {
|
||||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<String, Object>());
|
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
||||||
|
@ -111,7 +116,7 @@ public class CassandraTemplateIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@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"));
|
final Book javaBook = new Book(UUIDs.timeBased(), "Head First Java", "OReilly Media", ImmutableSet.of("Computer", "Software"));
|
||||||
cassandraTemplate.insert(javaBook);
|
cassandraTemplate.insert(javaBook);
|
||||||
cassandraTemplate.delete(javaBook);
|
cassandraTemplate.delete(javaBook);
|
|
@ -1,19 +1,16 @@
|
||||||
package com.baeldung.spring.data.cassandra.repository;
|
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.config.CassandraConfig;
|
||||||
import com.baeldung.spring.data.cassandra.model.Book;
|
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.cassandraunit.utils.EmbeddedCassandraServerHelper;
|
||||||
import org.junit.After;
|
import org.junit.After;
|
||||||
import org.junit.AfterClass;
|
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.ContextConfiguration;
|
||||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||||
|
|
||||||
import com.datastax.driver.core.Cluster;
|
import java.util.ArrayList;
|
||||||
import com.datastax.driver.core.Session;
|
import java.util.HashMap;
|
||||||
import com.datastax.driver.core.querybuilder.Insert;
|
import java.util.List;
|
||||||
import com.datastax.driver.core.querybuilder.QueryBuilder;
|
import java.util.UUID;
|
||||||
import com.datastax.driver.core.querybuilder.Select;
|
|
||||||
import com.datastax.driver.core.utils.UUIDs;
|
|
||||||
import com.google.common.collect.ImmutableSet;
|
|
||||||
|
|
||||||
|
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)
|
@RunWith(SpringJUnit4ClassRunner.class)
|
||||||
@ContextConfiguration(classes = CassandraConfig.class)
|
@ContextConfiguration(classes = CassandraConfig.class)
|
||||||
public class CqlQueriesIntegrationTest {
|
public class CqlQueriesLiveTest {
|
||||||
private static final Log LOGGER = LogFactory.getLog(CqlQueriesIntegrationTest.class);
|
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' };";
|
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
|
@Autowired
|
||||||
private CassandraOperations cassandraTemplate;
|
private CassandraOperations cassandraTemplate;
|
||||||
|
|
||||||
//
|
|
||||||
|
|
||||||
@BeforeClass
|
@BeforeClass
|
||||||
public static void startCassandraEmbedded() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
public static void startCassandraEmbedded() throws Exception {
|
||||||
EmbeddedCassandraServerHelper.startEmbeddedCassandra(25000);
|
EmbeddedCassandraServerHelper.startEmbeddedCassandra(25000);
|
||||||
final Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build();
|
final Cluster cluster = Cluster.builder().addContactPoints("127.0.0.1").withPort(9142).build();
|
||||||
LOGGER.info("Server Started at 127.0.0.1:9142... ");
|
LOGGER.info("Server Started at 127.0.0.1:9142... ");
|
||||||
|
@ -68,8 +70,8 @@ public class CqlQueriesIntegrationTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Before
|
@Before
|
||||||
public void createTable() throws InterruptedException, TTransportException, ConfigurationException, IOException {
|
public void createTable() {
|
||||||
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<String, Object>());
|
adminTemplate.createTable(true, CqlIdentifier.cqlId(DATA_TABLE_NAME), Book.class, new HashMap<>());
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test
|
@Test
|
Loading…
Reference in New Issue