Merge pull request #14705 from ehsansasanian/java-21464-upgrade-java-cassandra-to-jdk17
java-21464: upgrade java-cassandra to jdk17
This commit is contained in:
commit
6978371d17
|
@ -13,26 +13,11 @@
|
|||
</parent>
|
||||
|
||||
<dependencies>
|
||||
<!-- Cassandra -->
|
||||
<dependency>
|
||||
<groupId>com.datastax.cassandra</groupId>
|
||||
<artifactId>cassandra-driver-core</artifactId>
|
||||
<version>${cassandra-driver-core.version}</version>
|
||||
<optional>true</optional>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<groupId>com.google.guava</groupId>
|
||||
<artifactId>guava</artifactId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
</dependency>
|
||||
<!-- https://mvnrepository.com/artifact/org.cassandraunit/cassandra-unit -->
|
||||
<dependency>
|
||||
<groupId>org.cassandraunit</groupId>
|
||||
<artifactId>cassandra-unit</artifactId>
|
||||
<version>${cassandra-unit.version}</version>
|
||||
</dependency>
|
||||
<!-- DataStax Cassandra -->
|
||||
<dependency>
|
||||
<groupId>com.datastax.oss</groupId>
|
||||
<artifactId>java-driver-core</artifactId>
|
||||
|
@ -48,32 +33,28 @@
|
|||
<artifactId>netty-transport</artifactId>
|
||||
<version>${netty-transport-version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.testcontainers</groupId>
|
||||
<artifactId>cassandra</artifactId>
|
||||
<version>${cassandra-testcontainer.version}</version>
|
||||
<scope>test</scope>
|
||||
</dependency>
|
||||
</dependencies>
|
||||
|
||||
<profiles>
|
||||
<profile>
|
||||
<id>integration-lite-first</id>
|
||||
|
||||
<build>
|
||||
<plugins>
|
||||
<plugin>
|
||||
<groupId>org.apache.maven.plugins</groupId>
|
||||
<artifactId>maven-surefire-plugin</artifactId>
|
||||
<configuration>
|
||||
<forkCount>1</forkCount>
|
||||
<reuseForks>true</reuseForks>
|
||||
</configuration>
|
||||
<artifactId>maven-compiler-plugin</artifactId>
|
||||
</plugin>
|
||||
</plugins>
|
||||
</build>
|
||||
</profile>
|
||||
</profiles>
|
||||
|
||||
<properties>
|
||||
<!-- Cassandra -->
|
||||
<cassandra-driver-core.version>3.1.2</cassandra-driver-core.version>
|
||||
<cassandra-unit.version>3.1.1.0</cassandra-unit.version>
|
||||
<datastax-cassandra.version>4.1.0</datastax-cassandra.version>
|
||||
<cassandra-testcontainer.version>1.15.3</cassandra-testcontainer.version>
|
||||
<netty-transport-version>4.1.71.Final</netty-transport-version>
|
||||
</properties>
|
||||
|
||||
|
|
|
@ -5,8 +5,6 @@ import com.datastax.oss.driver.api.core.CqlSessionBuilder;
|
|||
|
||||
import java.net.InetSocketAddress;
|
||||
|
||||
import org.apache.commons.lang3.StringUtils;
|
||||
|
||||
public class CassandraConnector {
|
||||
|
||||
private CqlSession session;
|
||||
|
@ -14,7 +12,7 @@ public class CassandraConnector {
|
|||
public void connect(final String node, final Integer port, final String dataCenter) {
|
||||
CqlSessionBuilder builder = CqlSession.builder();
|
||||
builder.addContactPoint(new InetSocketAddress(node, port));
|
||||
if (StringUtils.isNotBlank(dataCenter)) {
|
||||
if (dataCenter != null && !dataCenter.isEmpty()) {
|
||||
builder.withLocalDatacenter(dataCenter);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,5 +1,6 @@
|
|||
package com.baeldung.datastax.cassandra;
|
||||
|
||||
import com.baeldung.cassandra.batch.repository.ProductRepository;
|
||||
import com.baeldung.datastax.cassandra.domain.Video;
|
||||
import com.baeldung.datastax.cassandra.repository.KeyspaceRepository;
|
||||
import com.baeldung.datastax.cassandra.repository.VideoRepository;
|
||||
|
@ -30,9 +31,11 @@ public class Application {
|
|||
keyspaceRepository.useKeyspace("testKeyspace");
|
||||
|
||||
VideoRepository videoRepository = new VideoRepository(session);
|
||||
ProductRepository productRepository = new ProductRepository(session);
|
||||
|
||||
videoRepository.createTable();
|
||||
|
||||
productRepository.createProductTableByName("testKeyspace");
|
||||
videoRepository.insertVideo(new Video("Video Title 1", Instant.now()));
|
||||
videoRepository.insertVideo(new Video("Video Title 2",
|
||||
Instant.now().minus(1, ChronoUnit.DAYS)));
|
||||
|
|
|
@ -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 {
|
||||
|
||||
public class ProductRepositoryLiveTest {
|
||||
@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
|
||||
|
@ -115,13 +110,6 @@ public class ProductRepositoryIntegrationTest {
|
|||
assertEquals(productList.get(1).getPrice(), 12f,0f);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@AfterClass
|
||||
public static void cleanup() {
|
||||
EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
|
||||
}
|
||||
|
||||
private Product getTestProduct() {
|
||||
Product product = new Product();
|
||||
product.setProductName("Banana");
|
|
@ -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;
|
||||
|
||||
public class BookRepositoryIntegrationTest {
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
private KeyspaceRepository schemaRepository;
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
public class BookRepositoryLiveTest {
|
||||
@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();
|
||||
}
|
||||
}
|
|
@ -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 {
|
||||
|
||||
public class KeyspaceRepositoryLiveTest {
|
||||
@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();
|
||||
}
|
||||
}
|
|
@ -35,6 +35,7 @@
|
|||
<module>hibernate-queries</module>
|
||||
<module>hibernate-enterprise</module>
|
||||
<module>influxdb</module>
|
||||
<module>java-cassandra</module>
|
||||
<module>java-cockroachdb</module>
|
||||
<module>java-jdbi</module>
|
||||
<module>java-jpa</module> <!-- long running -->
|
||||
|
|
2
pom.xml
2
pom.xml
|
@ -366,7 +366,6 @@
|
|||
<module>web-modules/restx</module>
|
||||
<module>persistence-modules/deltaspike</module> <!-- delta spike it doesn't support yet the jakarta API-->
|
||||
<module>persistence-modules/hibernate-ogm</module> <!-- hibernate-ogm wasn't updated because it doesn't support jakarta API -->
|
||||
<module>persistence-modules/java-cassandra</module> <!-- JAVA-21464 cassandra-unit library doesn't support to run with jdk9 and above -->
|
||||
<module>persistence-modules/spring-data-cassandra-reactive</module> <!--JAVA-21844-->
|
||||
<module>java-nashorn</module>
|
||||
<module>jeromq</module>
|
||||
|
@ -542,7 +541,6 @@
|
|||
<module>web-modules/restx</module>
|
||||
<module>persistence-modules/deltaspike</module> <!-- delta spike it doesn't support yet the jakarta API-->
|
||||
<module>persistence-modules/hibernate-ogm</module> <!-- hibernate-ogm wasn't updated because it doesn't support jakarta API -->
|
||||
<module>persistence-modules/java-cassandra</module> <!-- JAVA-21464 cassandra-unit library doesn't support to run with jdk9 and above -->
|
||||
<module>persistence-modules/spring-data-cassandra-reactive</module> <!--JAVA-21844-->
|
||||
<module>java-nashorn</module>
|
||||
<module>spring-ejb-modules/ejb-beans</module>
|
||||
|
|
Loading…
Reference in New Issue