java-21464: upgrade and move java-cassandra to jdk9 profile
This commit is contained in:
+26
-38
@@ -1,24 +1,5 @@
|
||||
package com.baeldung.cassandra.batch.epository;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.thrift.transport.TTransportException;
|
||||
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import com.baeldung.cassandra.batch.CassandraConnector;
|
||||
import com.baeldung.cassandra.batch.domain.Product;
|
||||
import com.baeldung.cassandra.batch.repository.KeyspaceRepository;
|
||||
import com.baeldung.cassandra.batch.repository.ProductRepository;
|
||||
@@ -26,10 +7,25 @@ import com.datastax.oss.driver.api.core.CqlIdentifier;
|
||||
import com.datastax.oss.driver.api.core.CqlSession;
|
||||
import com.datastax.oss.driver.api.core.cql.ColumnDefinition;
|
||||
import com.datastax.oss.driver.api.core.cql.ResultSet;
|
||||
import org.junit.Before;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.testcontainers.containers.CassandraContainer;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class ProductRepositoryIntegrationTest {
|
||||
|
||||
@Rule
|
||||
public CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2");
|
||||
private KeyspaceRepository schemaRepository;
|
||||
|
||||
private ProductRepository productRepository;
|
||||
@@ -39,21 +35,20 @@ public class ProductRepositoryIntegrationTest {
|
||||
private final String KEYSPACE_NAME = "testBaeldungKeyspace";
|
||||
private final String PRODUCT = "product";
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws ConfigurationException, TTransportException, IOException, InterruptedException {
|
||||
// Start an embedded Cassandra Server
|
||||
EmbeddedCassandraServerHelper.startEmbeddedCassandra(20000L);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void connect() {
|
||||
CassandraConnector client = new CassandraConnector();
|
||||
client.connect("127.0.0.1", 9142,"datacenter1");
|
||||
session = client.getSession();
|
||||
schemaRepository = new KeyspaceRepository(client.getSession());
|
||||
cassandra.start();
|
||||
|
||||
this.session = CqlSession
|
||||
.builder()
|
||||
.addContactPoint(new InetSocketAddress(cassandra.getHost(),cassandra.getFirstMappedPort()))
|
||||
.withLocalDatacenter("datacenter1")
|
||||
.build();
|
||||
|
||||
schemaRepository = new KeyspaceRepository(this.session);
|
||||
schemaRepository.createKeyspace(KEYSPACE_NAME, 1);
|
||||
schemaRepository.useKeyspace(KEYSPACE_NAME);
|
||||
productRepository = new ProductRepository(client.getSession());
|
||||
productRepository = new ProductRepository(this.session);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -114,14 +109,7 @@ public class ProductRepositoryIntegrationTest {
|
||||
assertEquals(productList.get(0).getPrice(), 12f,0f);
|
||||
assertEquals(productList.get(1).getPrice(), 12f,0f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup() {
|
||||
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
|
||||
}
|
||||
|
||||
private Product getTestProduct() {
|
||||
Product product = new Product();
|
||||
product.setProductName("Banana");
|
||||
|
||||
+22
-34
@@ -1,31 +1,24 @@
|
||||
package com.baeldung.cassandra.java.client.repository;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.thrift.transport.TTransportException;
|
||||
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
|
||||
import com.baeldung.cassandra.java.client.CassandraConnector;
|
||||
import com.baeldung.cassandra.java.client.domain.Book;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Session;
|
||||
import com.datastax.driver.core.exceptions.InvalidQueryException;
|
||||
import com.datastax.driver.core.utils.UUIDs;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.testcontainers.containers.CassandraContainer;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class BookRepositoryIntegrationTest {
|
||||
|
||||
private KeyspaceRepository schemaRepository;
|
||||
@Rule
|
||||
public CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2");
|
||||
|
||||
private BookRepository bookRepository;
|
||||
|
||||
@@ -35,18 +28,18 @@ public class BookRepositoryIntegrationTest {
|
||||
final String BOOKS = "books";
|
||||
final String BOOKS_BY_TITLE = "booksByTitle";
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws ConfigurationException, TTransportException, IOException, InterruptedException {
|
||||
// Start an embedded Cassandra Server
|
||||
EmbeddedCassandraServerHelper.startEmbeddedCassandra(20000L);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void connect() {
|
||||
CassandraConnector client = new CassandraConnector();
|
||||
client.connect("127.0.0.1", 9142);
|
||||
this.session = client.getSession();
|
||||
schemaRepository = new KeyspaceRepository(session);
|
||||
cassandra.start();
|
||||
|
||||
this.session = Cluster
|
||||
.builder()
|
||||
.addContactPoint(cassandra.getHost())
|
||||
.withPort(cassandra.getMappedPort(CassandraContainer.CQL_PORT))
|
||||
.build()
|
||||
.newSession();
|
||||
|
||||
KeyspaceRepository schemaRepository = new KeyspaceRepository(session);
|
||||
schemaRepository.createKeyspace(KEYSPACE_NAME, "SimpleStrategy", 1);
|
||||
schemaRepository.useKeyspace(KEYSPACE_NAME);
|
||||
bookRepository = new BookRepository(session);
|
||||
@@ -166,9 +159,4 @@ public class BookRepositoryIntegrationTest {
|
||||
|
||||
session.execute("SELECT * FROM " + KEYSPACE_NAME + "." + BOOKS + ";");
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup() {
|
||||
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
|
||||
}
|
||||
}
|
||||
|
||||
+22
-34
@@ -1,45 +1,38 @@
|
||||
package com.baeldung.cassandra.java.client.repository;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import com.datastax.driver.core.Cluster;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Session;
|
||||
import org.junit.Before;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
import org.testcontainers.containers.CassandraContainer;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import org.apache.cassandra.exceptions.ConfigurationException;
|
||||
import org.apache.thrift.transport.TTransportException;
|
||||
import org.cassandraunit.utils.EmbeddedCassandraServerHelper;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.FixMethodOrder;
|
||||
import org.junit.Test;
|
||||
import org.junit.runners.MethodSorters;
|
||||
|
||||
import com.baeldung.cassandra.java.client.CassandraConnector;
|
||||
import com.datastax.driver.core.ResultSet;
|
||||
import com.datastax.driver.core.Session;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
@FixMethodOrder(MethodSorters.NAME_ASCENDING)
|
||||
public class KeyspaceRepositoryIntegrationTest {
|
||||
|
||||
@Rule
|
||||
public CassandraContainer<?> cassandra = new CassandraContainer<>("cassandra:3.11.2");
|
||||
private KeyspaceRepository schemaRepository;
|
||||
|
||||
private Session session;
|
||||
|
||||
@BeforeClass
|
||||
public static void init() throws ConfigurationException, TTransportException, IOException, InterruptedException {
|
||||
// Start an embedded Cassandra Server
|
||||
EmbeddedCassandraServerHelper.startEmbeddedCassandra(20000L);
|
||||
}
|
||||
|
||||
@Before
|
||||
public void connect() {
|
||||
CassandraConnector client = new CassandraConnector();
|
||||
client.connect("127.0.0.1", 9142);
|
||||
this.session = client.getSession();
|
||||
cassandra.start();
|
||||
|
||||
this.session = Cluster
|
||||
.builder()
|
||||
.addContactPoint(cassandra.getHost())
|
||||
.withPort(cassandra.getMappedPort(CassandraContainer.CQL_PORT))
|
||||
.build()
|
||||
.newSession();
|
||||
|
||||
schemaRepository = new KeyspaceRepository(session);
|
||||
}
|
||||
|
||||
@@ -62,16 +55,11 @@ public class KeyspaceRepositoryIntegrationTest {
|
||||
public void whenDeletingAKeyspace_thenDoesNotExist() {
|
||||
String keyspaceName = "testBaeldungKeyspace";
|
||||
|
||||
// schemaRepository.createKeyspace(keyspaceName, "SimpleStrategy", 1);
|
||||
schemaRepository.createKeyspace(keyspaceName, "SimpleStrategy", 1);
|
||||
schemaRepository.deleteKeyspace(keyspaceName);
|
||||
|
||||
ResultSet result = session.execute("SELECT * FROM system_schema.keyspaces;");
|
||||
boolean isKeyspaceCreated = result.all().stream().anyMatch(r -> r.getString(0).equals(keyspaceName.toLowerCase()));
|
||||
assertFalse(isKeyspaceCreated);
|
||||
}
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup() {
|
||||
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user