Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

CASSJAVA-40: Driver testing against Java 21 #1999

Open
wants to merge 13 commits into
base: 4.x
Choose a base branch
from
Open
4 changes: 2 additions & 2 deletions Jenkinsfile-asf
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ pipeline {
axes {
axis {
name 'TEST_JAVA_VERSION'
values '[email protected]', '[email protected]', 'openjdk@17'
values '[email protected]', '[email protected]', 'openjdk@17', '[email protected]'
}
axis {
name 'SERVER_VERSION'
Expand Down Expand Up @@ -67,7 +67,7 @@ pipeline {
def executeTests() {
def testJavaMajorVersion = (TEST_JAVA_VERSION =~ /@(?:1\.)?(\d+)/)[0][1]
sh """
container_id=\$(docker run -td -e TEST_JAVA_VERSION=${TEST_JAVA_VERSION} -e SERVER_VERSION=${SERVER_VERSION} -e TEST_JAVA_MAJOR_VERSION=${testJavaMajorVersion} -v \$(pwd):/home/docker/cassandra-java-driver apache.jfrog.io/cassan-docker/apache/cassandra-java-driver-testing-ubuntu2204 'sleep 2h')
container_id=\$(docker run -td -e TEST_JAVA_VERSION=${TEST_JAVA_VERSION} -e SERVER_VERSION=${SERVER_VERSION} -e TEST_JAVA_MAJOR_VERSION=${testJavaMajorVersion} -v \$(pwd):/home/docker/cassandra-java-driver janehe158/cassandra-java-driver-dev-env 'sleep 2h')
docker exec --user root \$container_id bash -c \"sudo bash /home/docker/cassandra-java-driver/ci/create-user.sh docker \$(id -u) \$(id -g) /home/docker/cassandra-java-driver\"
docker exec --user docker \$container_id './cassandra-java-driver/ci/run-tests.sh'
( nohup docker stop \$container_id >/dev/null 2>/dev/null & )
Expand Down
1 change: 0 additions & 1 deletion ci/run-tests.sh
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
cd $(dirname "$(readlink -f "$0")")/..
printenv | sort
mvn -B -V install -DskipTests -Dmaven.javadoc.skip=true
jabba use ${TEST_JAVA_VERSION}
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This was required by CCM right?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change should be reverted together with the CcmBridge changes when your PR-2000 is merged.

# Find out the latest patch version of Cassandra
PATCH_SERVER_VERSION=$(curl -s https://downloads.apache.org/cassandra/ | grep -oP '(?<=href=\")[0-9]+\.[0-9]+\.[0-9]+(?=)' | sort -rV | uniq -w 3 | grep $SERVER_VERSION)
printenv | sort
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@
package com.datastax.oss.driver.internal.core.util;

import edu.umd.cs.findbugs.annotations.NonNull;
import java.util.Random;
import java.util.concurrent.ThreadLocalRandom;

public class ArrayUtils {
Expand Down Expand Up @@ -77,7 +78,7 @@ public static <ElementT> void shuffleHead(@NonNull ElementT[] elements, int n) {
* Fisher-Yates shuffle</a>
*/
public static <ElementT> void shuffleHead(
@NonNull ElementT[] elements, int n, @NonNull ThreadLocalRandom random) {
@NonNull ElementT[] elements, int n, @NonNull Random random) {
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mockito says they can no longer support mocking of ThreadLocalRandom.
This fix will also close JAVA-3137.

if (n > elements.length) {
throw new ArrayIndexOutOfBoundsException(
String.format(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public class QueryTraceFetcherTest {
@Mock private NettyOptions nettyOptions;
@Mock private EventExecutorGroup adminEventExecutorGroup;
@Mock private EventExecutor eventExecutor;
@Mock private InetAddress address;
private InetAddress address = InetAddress.getLoopbackAddress();
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Mockito can no longer mock InetAddress as it becomes final in newer JDK versions.


@Captor private ArgumentCaptor<SimpleStatement> statementCaptor;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;

import java.util.concurrent.ThreadLocalRandom;
import java.util.Random;
import org.junit.Test;

public class ArrayUtilsTest {
Expand Down Expand Up @@ -86,7 +86,7 @@ public void should_not_bubble_down_when_target_index_lower() {
@Test
public void should_shuffle_head() {
String[] array = {"a", "b", "c", "d", "e"};
ThreadLocalRandom random = mock(ThreadLocalRandom.class);
Random random = mock(Random.class);
when(random.nextInt(anyInt()))
.thenAnswer(
(invocation) -> {
Expand Down
13 changes: 13 additions & 0 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1016,6 +1016,19 @@ limitations under the License.]]></inlineHeader>
<mockitoopens.argline>--add-opens java.base/jdk.internal.util.random=ALL-UNNAMED</mockitoopens.argline>
</properties>
</profile>
<profile>
<!-- workarounds for running tests with JDK21 -->
<id>test-jdk-21</id>
<activation>
<jdk>[21,)</jdk>
</activation>
<properties>
<!-- for DriverBlockHoundIntegrationIT when using JDK 13+, see https://github.com/reactor/BlockHound/issues/33 -->
<blockhound.argline>-XX:+AllowRedefinitionToAddDeleteMethods</blockhound.argline>
<!-- allow deep reflection for mockito when using JDK 17+, see https://stackoverflow.com/questions/70993863/mockito-can-not-mock-random-in-java-17 -->
<mockitoopens.argline>--add-opens=java.base/jdk.internal.util.random=ALL-UNNAMED</mockitoopens.argline>
</properties>
</profile>
</profiles>
<licenses>
<license>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,7 @@
import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Locale;
Expand Down Expand Up @@ -409,7 +410,16 @@ protected void processLine(String line, int logLevel) {
executor.setStreamHandler(streamHandler);
executor.setWatchdog(watchDog);

int retValue = executor.execute(cli);
int retValue;
Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I modified CcmBridge because the latest commit on guava shaded broke the CI, cuz some how there are two source files that are not compiled in mvn install but compiled in mvn verify. Maybe we need to figure out why that happens and fix that instead, and revert the CcmBridge changes here.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can be reverted once #2000 is merged.

if (System.getProperty("testJavaHome") != null) {
// Set PATH and JAVA_HOME to enable ccm to find the correct java
Map<String, String> env = new HashMap<>(System.getenv());
env.put("PATH", System.getProperty("testJavaHome") + "/bin:" + env.get("PATH"));
env.put("JAVA_HOME", System.getProperty("testJavaHome"));
retValue = executor.execute(cli, env);
} else {
retValue = executor.execute(cli);
}
if (retValue != 0) {
LOG.error("Non-zero exit code ({}) returned from executing ccm command: {}", retValue, cli);
}
Expand Down