Skip to content

Commit af06564

Browse files
committed
AMQ-9825: ActiveMQ on Java 25
Use Java 25 compatible version of Mockito Use Mockito Agent because self attaching an agent is now unavailable since Java 21+ Split integration tests (MRJAR dependent) into a specific integration-test phase so they use the jar in the classpath Do not rely on activeByDefault because when other profiles activate, quick becomes inactive
1 parent d79dc60 commit af06564

4 files changed

Lines changed: 57 additions & 20 deletions

File tree

Jenkinsfile

Lines changed: 2 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@ pipeline {
4949
choice(name: 'nodeLabel', choices: [ 'ubuntu', 's390x', 'arm', 'Windows' ])
5050
choice(name: 'jdkVersion', choices: ['jdk_17_latest', 'jdk_21_latest', 'jdk_25_latest', 'jdk_17_latest_windows', 'jdk_21_latest_windows', 'jdk_25_latest_windows'])
5151
booleanParam(name: 'deployEnabled', defaultValue: false)
52-
booleanParam(name: 'parallelTestsEnabled', defaultValue: true)
5352
booleanParam(name: 'sonarEnabled', defaultValue: false)
5453
booleanParam(name: 'testsEnabled', defaultValue: true)
5554
}
@@ -137,13 +136,8 @@ pipeline {
137136
// all tests is very very long (10 hours on Apache Jenkins)
138137
// sh 'mvn -B -e test -pl activemq-unit-tests -Dactivemq.tests=all'
139138
script {
140-
if (params.parallelTestsEnabled == 'true') {
141-
sh 'echo "Running parallel-tests ..."'
142-
sh 'mvn -B -e -fae -Pparallel-tests test -Dsurefire.rerunFailingTestsCount=3'
143-
} else {
144-
sh 'echo "Running tests ..."'
145-
sh 'mvn -B -e -fae test -Dsurefire.rerunFailingTestsCount=3'
146-
}
139+
sh 'echo "Running tests ..."'
140+
sh 'mvn -B -e -fae verify -Pactivemq.tests-quick'
147141
}
148142
}
149143
post {

activemq-broker/src/main/java/org/apache/activemq/broker/BrokerService.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1898,7 +1898,7 @@ public boolean isVirtualThreadTaskRunner() {
18981898
return virtualThreadTaskRunner;
18991899
}
19001900

1901-
@Experimental("Tech Preview for Virtaul Thread support")
1901+
@Experimental("Tech Preview for Virtual Thread support")
19021902
public void setVirtualThreadTaskRunner(boolean virtualThreadTaskRunner) {
19031903
this.virtualThreadTaskRunner = virtualThreadTaskRunner;
19041904
}

activemq-client/src/main/java/org/apache/activemq/thread/TaskRunnerFactory.java

Lines changed: 11 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -240,10 +240,7 @@ public void uncaughtException(final Thread t, final Throwable e) {
240240
}
241241

242242
protected ExecutorService createVirtualThreadExecutor() {
243-
if(!(Runtime.version().feature() >= 21)) {
244-
LOG.error("Virtual Thread support requires JDK 21 or higher");
245-
throw new IllegalStateException("Virtual Thread support requires JDK 21 or higher");
246-
}
243+
assertJDK21VirtualThreadSupport();
247244

248245
try {
249246
Class<?> virtualThreadExecutorClass = Class.forName("org.apache.activemq.thread.VirtualThreadExecutor", false, threadClassLoader);
@@ -253,18 +250,15 @@ protected ExecutorService createVirtualThreadExecutor() {
253250
throw new IllegalStateException("VirtualThreadExecutor not returned");
254251
}
255252
LOG.info("VirtualThreadExecutor initialized name:{}", name);
256-
return ExecutorService.class.cast(result);
253+
return (ExecutorService) result;
257254
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException e) {
258255
LOG.error("VirtualThreadExecutor class failed to load", e);
259256
throw new IllegalStateException(e);
260257
}
261258
}
262259

263260
protected TaskRunner createVirtualThreadTaskRunner(Executor executor, Task task, int maxIterations) {
264-
if(!(Runtime.version().feature() >= 21)) {
265-
LOG.error("Virtual Thread support requires JDK 21 or higher");
266-
throw new IllegalStateException("Virtual Thread support requires JDK 21 or higher");
267-
}
261+
assertJDK21VirtualThreadSupport();
268262

269263
try {
270264
Class<?> virtualThreadTaskRunnerClass = Class.forName("org.apache.activemq.thread.VirtualThreadTaskRunner", false, threadClassLoader);
@@ -273,13 +267,20 @@ protected TaskRunner createVirtualThreadTaskRunner(Executor executor, Task task,
273267
if(!TaskRunner.class.isAssignableFrom(result.getClass())) {
274268
throw new IllegalStateException("VirtualThreadTaskRunner not returned");
275269
}
276-
return TaskRunner.class.cast(result);
270+
return (TaskRunner) result;
277271
} catch (ClassNotFoundException | NoSuchMethodException | SecurityException | IllegalAccessException | InvocationTargetException | InstantiationException | IllegalArgumentException e) {
278272
LOG.error("VirtualThreadTaskRunner class failed to load", e);
279273
throw new IllegalStateException(e);
280274
}
281275
}
282276

277+
private void assertJDK21VirtualThreadSupport() {
278+
if(!(Runtime.version().feature() >= 21)) {
279+
LOG.error("Virtual Thread support requires JDK 21 or higher");
280+
throw new IllegalStateException("Virtual Thread support requires JDK 21 or higher");
281+
}
282+
}
283+
283284

284285
public ExecutorService getExecutor() {
285286
return executorRef.get();

activemq-unit-tests/pom.xml

Lines changed: 43 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -465,6 +465,18 @@
465465
<exclude>**/ClientIdFilterDispatchPolicyTest.java</exclude>
466466
<exclude>**/StartAndConcurrentStopBrokerTest.java</exclude>
467467
<exclude>**/BlobTransferPolicyUriTest.java</exclude>
468+
469+
<!--
470+
added when running under Java 21+, but it can't run as part of normal tests
471+
because Maven Surefire will use activemq-client/target/classes instead of the MRJAR
472+
473+
This test needs to run as part of the integration test phase to ensure it's using the packaged version
474+
We use failsafe instead which is a better choice for integration tests. See bellow the configuration.
475+
-->
476+
<exclude>**/VirtualThreadTaskRunnerBrokerTest.java</exclude>
477+
<exclude>**/DLQRetryTest.java</exclude>
478+
<exclude>**/JmxAuditLogTest.java</exclude>
479+
<exclude>**/JmxCreateNCTest.java</exclude>
468480
</excludes>
469481
</configuration>
470482
<executions>
@@ -507,6 +519,37 @@
507519
</dependency>
508520
</dependencies>
509521
</plugin>
522+
<plugin>
523+
<groupId>org.apache.maven.plugins</groupId>
524+
<artifactId>maven-failsafe-plugin</artifactId>
525+
<version>3.5.2</version>
526+
<executions>
527+
<execution>
528+
<goals>
529+
<goal>integration-test</goal>
530+
<goal>verify</goal>
531+
</goals>
532+
</execution>
533+
</executions>
534+
<configuration>
535+
<forkCount>1</forkCount>
536+
<reuseForks>false</reuseForks>
537+
<failIfNoTests>false</failIfNoTests>
538+
<systemPropertyVariables>
539+
<org.apache.activemq.default.directory.prefix>${project.build.directory}/</org.apache.activemq.default.directory.prefix>
540+
<java.net.preferIPv4Stack>true</java.net.preferIPv4Stack>
541+
<org.apache.activemq.AutoFailTestSupport.disableSystemExit>true</org.apache.activemq.AutoFailTestSupport.disableSystemExit>
542+
<org.apache.activemq.broker.jmx.createConnector>false</org.apache.activemq.broker.jmx.createConnector>
543+
</systemPropertyVariables>
544+
<argLine>-Xmx512m -javaagent:${org.mockito:mockito-core:jar}</argLine>
545+
<includes>
546+
<include>**/VirtualThreadTaskRunnerBrokerTest.java</include>
547+
<include>**/DLQRetryTest.java</include>
548+
<include>**/JmxAuditLogTest.java</include>
549+
<include>**/JmxCreateNCTest.java</include>
550+
</includes>
551+
</configuration>
552+
</plugin>
510553

511554
<plugin>
512555
<groupId>org.apache.maven.plugins</groupId>
@@ -717,7 +760,6 @@
717760
<profile>
718761
<id>activemq.tests-quick</id>
719762
<activation>
720-
<activeByDefault>true</activeByDefault>
721763
<property>
722764
<name>activemq.tests</name>
723765
<value>quick</value>

0 commit comments

Comments
 (0)