Skip to content

Commit 84eb557

Browse files
ruhan1claude
andcommitted
Upgrade to Java 17 and replace cassandra-maven-plugin with testcontainers
Migrated the project from Java 11 to Java 17 to take advantage of newer language features and long-term support. Replaced cassandra-maven-plugin with testcontainers for Cassandra integration tests, as the maven plugin does not support Java 17. Changes: - Updated Java version from 11 to 17 in all configurations (pom.xml, toolchains.xml, CI workflows, Dockerfile) - Updated GitHub Actions to use ubuntu-latest instead of ubuntu-22.04 - Removed explicit Maven setup from CI workflows (uses default Maven from ubuntu-latest) - Removed cassandra-maven-plugin and added testcontainers:cassandra dependency - Created CassandraTestResource to manage Cassandra container lifecycle for tests - Updated integration tests to use @QuarkusTestResource with CassandraTestResource - Simplified test configuration by removing hardcoded Cassandra connection details Benefits: - Java 17 LTS support with improved performance and features - Better test isolation with containerized Cassandra instances - Simplified local development workflow - tests can run directly in IDE without manual Cassandra setup - Cleaner CI configuration using default tooling Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
1 parent b618ba1 commit 84eb557

File tree

10 files changed

+97
-66
lines changed

10 files changed

+97
-66
lines changed

.github/workflows/merge-build.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@ jobs:
2525
publish-snapshot:
2626
name: publish to oss sonatype & push image
2727

28-
runs-on: ubuntu-22.04
28+
runs-on: ubuntu-latest
2929

3030
permissions:
3131
contents: read
@@ -42,12 +42,7 @@ jobs:
4242
with:
4343
distribution: 'temurin'
4444
architecture: x64
45-
java-version: 11
46-
47-
- name: Set up Maven
48-
uses: stCarolas/setup-maven@v4.5
49-
with:
50-
maven-version: 3.8.8
45+
java-version: 17
5146

5247
- name: maven-settings-xml-action
5348
uses: whelk-io/maven-settings-xml-action@v14

.github/workflows/pr-build.yml

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -24,22 +24,17 @@ on: [pull_request]
2424
jobs:
2525
build:
2626

27-
runs-on: ubuntu-22.04
27+
runs-on: ubuntu-latest
2828

2929
steps:
3030
- uses: actions/checkout@v2
3131

3232
- name: Set up JDK
3333
uses: actions/setup-java@v2
3434
with:
35-
java-version: '11'
35+
java-version: '17'
3636
distribution: 'adopt'
3737

38-
- name: Set up Maven
39-
uses: stCarolas/setup-maven@v4.5
40-
with:
41-
maven-version: 3.8.8
42-
4338
- name: maven-settings-xml-action
4439
uses: whelk-io/maven-settings-xml-action@v14
4540
with:

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@ Users r/w the files via REST api. Multiple users can r/w same file without affec
1010
The concurrent r/w is no surprise when you run a standalone service which only concerns one node. The most significant fact lies on the 'cluster' mode. You can deploy it on a Cloud platform, such as k8s or Openshift, and scale up to as many nodes as you want. The concurrent r/w promise still hold. On cluster mode, all nodes share the same persistent volume and connect to the same Cassandra as the backend DB.
1111

1212
## Prerequisite
13-
1. jdk11
13+
1. jdk17
1414
2. mvn 3.6.2+
1515

1616
## Prerequisite for debugging in local

pom.xml

Lines changed: 6 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,6 @@
4444
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
4545
<path-mapped-storage.version>3.0</path-mapped-storage.version>
4646
<toolchains-plugin.version>3.0.0</toolchains-plugin.version>
47-
<cassandra-maven-plugin.version>3.8</cassandra-maven-plugin.version>
4847
<quarkus.package.type>uber-jar</quarkus.package.type>
4948
<testcontainers.version>1.19.7</testcontainers.version>
5049
<skipTests>false</skipTests>
@@ -196,6 +195,11 @@
196195
<artifactId>localstack</artifactId>
197196
<scope>test</scope>
198197
</dependency>
198+
<dependency>
199+
<groupId>org.testcontainers</groupId>
200+
<artifactId>cassandra</artifactId>
201+
<scope>test</scope>
202+
</dependency>
199203
</dependencies>
200204

201205
<build>
@@ -254,7 +258,7 @@
254258
<configuration>
255259
<toolchains>
256260
<jdk>
257-
<version>11</version>
261+
<version>17</version>
258262
<vendor>OpenJDK</vendor>
259263
</jdk>
260264
</toolchains>
@@ -279,34 +283,6 @@
279283
</execution>
280284
</executions>
281285
</plugin>
282-
<plugin>
283-
<groupId>org.codehaus.mojo</groupId>
284-
<artifactId>cassandra-maven-plugin</artifactId>
285-
<version>${cassandra-maven-plugin.version}</version>
286-
<configuration>
287-
<startNativeTransport>true</startNativeTransport>
288-
<nativeTransportPort>9942</nativeTransportPort>
289-
<loadFailureIgnore>true</loadFailureIgnore>
290-
<script>${basedir}/src/test/resources/cql/load.cql</script>
291-
<skip>${skipTests}</skip>
292-
</configuration>
293-
<dependencies>
294-
<dependency>
295-
<groupId>net.java.dev.jna</groupId>
296-
<artifactId>jna</artifactId>
297-
<version>5.8.0</version>
298-
</dependency>
299-
</dependencies>
300-
<executions>
301-
<execution>
302-
<id>cassandra</id>
303-
<goals>
304-
<goal>start</goal>
305-
<goal>stop</goal>
306-
</goals>
307-
</execution>
308-
</executions>
309-
</plugin>
310286
<plugin>
311287
<groupId>org.apache.maven.plugins</groupId>
312288
<artifactId>maven-release-plugin</artifactId>

src/main/image/Dockerfile.jvm

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@
2323
###
2424
FROM registry.access.redhat.com/ubi8/ubi-minimal:8.1
2525

26-
ARG JAVA_PACKAGE=java-11-openjdk-headless
26+
ARG JAVA_PACKAGE=java-17-openjdk-headless
2727
ARG RUN_JAVA_VERSION=1.3.8
2828

2929
ENV LANG='en_US.UTF-8' LANGUAGE='en_US:en'

src/test/java/org/commonjava/service/storage/S3StorageIT.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,7 @@
1818
import io.quarkus.test.common.QuarkusTestResource;
1919
import io.quarkus.test.junit.QuarkusTest;
2020
import jakarta.inject.Inject;
21+
import org.commonjava.service.storage.util.CassandraTestResource;
2122
import org.commonjava.service.storage.util.LocalStackTestResource;
2223
import org.junit.jupiter.api.Test;
2324
import software.amazon.awssdk.services.s3.S3Client;
@@ -32,6 +33,7 @@
3233
import static org.junit.jupiter.api.Assertions.assertTrue;
3334

3435
@QuarkusTest
36+
@QuarkusTestResource(CassandraTestResource.class)
3537
@QuarkusTestResource(LocalStackTestResource.class)
3638
public class S3StorageIT
3739
extends StorageIT

src/test/java/org/commonjava/service/storage/StorageIT.java

Lines changed: 8 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -15,8 +15,10 @@
1515
*/
1616
package org.commonjava.service.storage;
1717

18+
import io.quarkus.test.common.QuarkusTestResource;
1819
import io.quarkus.test.common.http.TestHTTPResource;
1920
import org.apache.commons.io.IOUtils;
21+
import org.commonjava.service.storage.util.CassandraTestResource;
2022
import org.commonjava.storage.pathmapped.core.PathMappedFileManager;
2123
import org.junit.jupiter.api.AfterAll;
2224
import org.junit.jupiter.api.BeforeAll;
@@ -27,6 +29,7 @@
2729
import java.io.OutputStream;
2830
import java.net.URL;
2931

32+
@QuarkusTestResource(CassandraTestResource.class)
3033
public abstract class StorageIT
3134
{
3235
protected final String PATH = "io/quarkus/quarkus-junit5/quarkus-junit5-1.12.0.Final.jar";
@@ -45,27 +48,18 @@ public abstract class StorageIT
4548
public static void init() throws Exception
4649
{
4750
/*
48-
* The reason I dropped embedded cassandra:
49-
* Previously I use 'cassandra-unit' which is great because we can run the unit tests both
50-
* by mvn command and in IDEA. Unfortunately, after upgrading to Quarkus 3.x, there is a
51-
* dependence change, and it breaks the embedded cassandra.
51+
* Now using testcontainers for Cassandra which supports Java 17.
52+
* The CassandraTestResource starts/stops the container automatically.
53+
* Tests can now be run both from mvn and directly in IDEA.
5254
*
53-
* Because of that, I moved to cassandra-maven-plugin in pom.xml. It works well with Quarkus 3
54-
* to start/stop cassandra. But I have to move Junit tests to integration tests because
55-
* this plugin works for integration phase only. The test classes are refactored as '*IT.java'.
56-
* The downside is that we can not run the IT tests in IDEA by simply clicking the 'Run'.
57-
* We need to do from command line as 'mvn verify'. Or we run 'mvn cassandra:start' beforehand
58-
* then run IT tests in IDEA.
59-
*
60-
* ruhan Feb 9, 2024
55+
* Updated for Java 17 migration, March 2026
6156
*/
62-
//EmbeddedCassandraServerHelper.startEmbeddedCassandra();
6357
}
6458

6559
@AfterAll
6660
public static void stop() throws Exception
6761
{
68-
//EmbeddedCassandraServerHelper.cleanEmbeddedCassandra();
62+
// Cleanup handled by CassandraTestResource
6963
}
7064

7165
@BeforeEach
Lines changed: 72 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,72 @@
1+
/**
2+
* Copyright (C) 2021 Red Hat, Inc. (https://github.com/Commonjava/service-parent)
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* http://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
package org.commonjava.service.storage.util;
17+
18+
import io.quarkus.test.common.QuarkusTestResourceLifecycleManager;
19+
import org.testcontainers.containers.CassandraContainer;
20+
import org.testcontainers.utility.DockerImageName;
21+
22+
import java.io.IOException;
23+
import java.nio.file.Files;
24+
import java.nio.file.Paths;
25+
import java.util.HashMap;
26+
import java.util.Map;
27+
28+
public class CassandraTestResource implements QuarkusTestResourceLifecycleManager {
29+
30+
static DockerImageName dockerImageName = DockerImageName.parse("cassandra:3.11.10");
31+
static CassandraContainer<?> cassandraContainer = new CassandraContainer<>(dockerImageName)
32+
.withExposedPorts(9042);
33+
34+
@Override
35+
public Map<String, String> start() {
36+
cassandraContainer.start();
37+
38+
// Load CQL script if it exists
39+
try {
40+
String scriptPath = "src/test/resources/cql/load.cql";
41+
if (Files.exists(Paths.get(scriptPath))) {
42+
String cqlScript = Files.readString(Paths.get(scriptPath)).trim();
43+
if (!cqlScript.isEmpty()) {
44+
// Split by semicolon and execute each statement
45+
String[] statements = cqlScript.split(";");
46+
for (String statement : statements) {
47+
String trimmed = statement.trim();
48+
if (!trimmed.isEmpty() && !trimmed.startsWith("--") && !trimmed.startsWith("//")) {
49+
cassandraContainer.getSession().execute(trimmed);
50+
}
51+
}
52+
}
53+
}
54+
} catch (IOException e) {
55+
// Script loading is optional, continue without it
56+
}
57+
58+
HashMap<String, String> map = new HashMap<>();
59+
map.put("cassandra.host", cassandraContainer.getHost());
60+
map.put("cassandra.port", String.valueOf(cassandraContainer.getMappedPort(9042)));
61+
map.put("cassandra.user", cassandraContainer.getUsername());
62+
map.put("cassandra.pass", cassandraContainer.getPassword());
63+
return map;
64+
}
65+
66+
@Override
67+
public void stop() {
68+
if (cassandraContainer != null) {
69+
cassandraContainer.stop();
70+
}
71+
}
72+
}

src/test/resources/application.yaml

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -32,11 +32,8 @@ quarkus:
3232
swagger-ui:
3333
always-include: true
3434

35+
# Cassandra configuration is provided by CassandraTestResource at runtime
3536
cassandra:
36-
host: localhost
37-
port: 9942
38-
user: cassandra
39-
pass: cassandra
4037
keyspace: indystorage
4138

4239
storage:

toolchains.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,11 +30,11 @@
3030
<toolchain>
3131
<type>jdk</type>
3232
<provides>
33-
<version>11</version>
33+
<version>17</version>
3434
<vendor>OpenJDK</vendor>
3535
</provides>
3636
<configuration>
37-
<jdkHome>/usr/lib/jvm/java-11-openjdk</jdkHome>
37+
<jdkHome>/usr/lib/jvm/java-17-openjdk</jdkHome>
3838
</configuration>
3939
</toolchain>
4040
</toolchains>

0 commit comments

Comments
 (0)