This is an automated email from the ASF dual-hosted git repository.
clebertsuconic pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/activemq-artemis.git
The following commit(s) were added to refs/heads/main by this push:
new cf2f9b4ffd ARTEMIS-3305 Compatibility tests dont work with Java 16+
cf2f9b4ffd is described below
commit cf2f9b4ffd8882b882262e34300e61d8e6835775
Author: Clebert Suconic <[email protected]>
AuthorDate: Fri Jun 10 11:16:53 2022 -0400
ARTEMIS-3305 Compatibility tests dont work with Java 16+
---
tests/compatibility-tests/pom.xml | 21 -------
.../artemis/tests/compatibility/GroovyRun.java | 7 ++-
.../resources/addressConfig/receiveMessages.groovy | 4 +-
.../artemis/tests/compatibility/ReplyToTest.java | 9 +++
.../tests/compatibility/base/ClasspathBase.java | 70 +++++++++++++++++-----
.../tests/compatibility/base/TestClassLoader.java | 48 +++++++++++++++
.../tests/compatibility/base/VersionedBase.java | 9 +--
7 files changed, 124 insertions(+), 44 deletions(-)
diff --git a/tests/compatibility-tests/pom.xml
b/tests/compatibility-tests/pom.xml
index 5b8935ffc5..07f96718f0 100644
--- a/tests/compatibility-tests/pom.xml
+++ b/tests/compatibility-tests/pom.xml
@@ -765,25 +765,4 @@
</snapshotRepository>
</distributionManagement>
- <profiles>
- <profile>
- <!-- TODO: Changes so these tests can work? -->
- <id>jdk16on</id>
- <activation>
- <jdk>[16,)</jdk>
- </activation>
- <build>
- <plugins>
- <plugin>
- <groupId>org.apache.maven.plugins</groupId>
- <artifactId>maven-surefire-plugin</artifactId>
- <configuration>
- <skip>true</skip>
- </configuration>
- </plugin>
- </plugins>
- </build>
- </profile>
- </profiles>
-
</project>
diff --git
a/tests/compatibility-tests/src/main/java/org/apache/activemq/artemis/tests/compatibility/GroovyRun.java
b/tests/compatibility-tests/src/main/java/org/apache/activemq/artemis/tests/compatibility/GroovyRun.java
index b584d08c90..1ff3593463 100644
---
a/tests/compatibility-tests/src/main/java/org/apache/activemq/artemis/tests/compatibility/GroovyRun.java
+++
b/tests/compatibility-tests/src/main/java/org/apache/activemq/artemis/tests/compatibility/GroovyRun.java
@@ -21,6 +21,8 @@ import java.io.IOException;
import java.net.URI;
import java.net.URISyntaxException;
import java.net.URL;
+import java.util.ArrayList;
+import java.util.List;
import groovy.lang.Binding;
import groovy.lang.GroovyShell;
@@ -45,8 +47,9 @@ public class GroovyRun {
public static GroovyShell shell = new GroovyShell(binding);
public static void clear() {
- binding = new Binding();
- shell = new GroovyShell(binding);
+ List<String> variablesToRemove = new ArrayList<>();
+ variablesToRemove.addAll(binding.getVariables().keySet());
+ variablesToRemove.forEach(v -> binding.removeVariable(v));
}
/**
diff --git
a/tests/compatibility-tests/src/main/resources/addressConfig/receiveMessages.groovy
b/tests/compatibility-tests/src/main/resources/addressConfig/receiveMessages.groovy
index 441b8e58ab..75f46314a0 100644
---
a/tests/compatibility-tests/src/main/resources/addressConfig/receiveMessages.groovy
+++
b/tests/compatibility-tests/src/main/resources/addressConfig/receiveMessages.groovy
@@ -23,7 +23,7 @@ import javax.jms.*
*/
-ConnectionFactory cf = new ActiveMQConnectionFactory();
+ActiveMQConnectionFactory cf = new ActiveMQConnectionFactory();
Connection connection = cf.createConnection();
Session session = connection.createSession(true, Session.SESSION_TRANSACTED);
Queue queue = session.createQueue("myQueue");
@@ -38,6 +38,8 @@ for (int i = 0; i < 500; i++) {
}
}
session.commit();
+connection.close();
+cf.close();
// Defined on AddressConfigTest.java at the test with setVariable
latch.countDown();
diff --git
a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ReplyToTest.java
b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ReplyToTest.java
index 1f1699f57e..e7dd934766 100644
---
a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ReplyToTest.java
+++
b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/ReplyToTest.java
@@ -74,8 +74,15 @@ public class ReplyToTest extends ServerBase {
@Override
public void tearDown() throws Throwable {
super.tearDown();
+
+ localClassLoaders.forEach(cl -> {
+ clearClassLoader(cl);
+ });
+ localClassLoaders.clear();
}
+ private static final ArrayList<ClassLoader> localClassLoaders = new
ArrayList<>();
+
@Override
public ClassLoader getClasspath(String name) throws Exception {
if (name.equals(SNAPSHOT)) {
@@ -89,6 +96,8 @@ public class ReplyToTest extends ServerBase {
clearGroovy(loader);
+ localClassLoaders.add(loader);
+
return loader;
} else {
return super.getClasspath(name);
diff --git
a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/ClasspathBase.java
b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/ClasspathBase.java
index 50f2a00de7..922c7deddb 100644
---
a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/ClasspathBase.java
+++
b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/ClasspathBase.java
@@ -20,13 +20,14 @@ package
org.apache.activemq.artemis.tests.compatibility.base;
import java.io.File;
import java.lang.reflect.Method;
import java.net.URL;
-import java.net.URLClassLoader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import org.apache.activemq.artemis.tests.compatibility.GroovyRun;
+import org.apache.activemq.artemis.utils.ThreadLeakCheckRule;
import org.jboss.logging.Logger;
+import org.junit.AfterClass;
import org.junit.Assume;
import org.junit.ClassRule;
import org.junit.Rule;
@@ -41,8 +42,9 @@ import static
org.apache.activemq.artemis.tests.compatibility.GroovyRun.SNAPSHOT
public class ClasspathBase {
+ private static final Logger logger = Logger.getLogger(ClasspathBase.class);
- private final Logger instanceLog = Logger.getLogger(this.getClass());
+ private final Logger instanceLog = logger;
@Rule
public TestRule watcher = new TestWatcher() {
@@ -58,15 +60,49 @@ public class ClasspathBase {
}
};
+ @AfterClass
+ public static void cleanup() {
+ loaderMap.values().forEach((cl -> clearClassLoader(cl)));
+ clearClassLoader(VersionedBase.class.getClassLoader());
+ }
+
+ public static void clearClassLoader(ClassLoader loader) {
+ try {
+ execute(loader,
"org.apache.activemq.artemis.api.core.client.ActiveMQClient.clearThreadPools()");
+ } catch (Throwable e) {
+ logger.debug(e.getMessage(), e);
+ }
+
+ try {
+ execute(loader,
"org.hornetq.core.client.impl.ServerLocatorImpl.clearThreadPools()");
+ } catch (Throwable e) {
+ logger.debug(e.getMessage(), e);
+ }
+
+ clearGroovy(loader);
+ }
+
+ @ClassRule
+ public static ThreadLeakCheckRule threadLeakCheckRule = new
ThreadLeakCheckRule();
+
@ClassRule
public static TemporaryFolder serverFolder;
private static int javaVersion;
+ public static final int getJavaVersion() {
+ return javaVersion;
+ }
+
+ // definining server folder
static {
File parent = new File("./target/tmp");
parent.mkdirs();
serverFolder = new TemporaryFolder(parent);
+ }
+
+ // defining java version
+ static {
String version = System.getProperty("java.version");
if (version.startsWith("1.")) {
version = version.substring(2, 3);
@@ -89,11 +125,9 @@ public class ClasspathBase {
for (int i = 0; i < classPathArray.length; i++) {
elements[i] = new File(classPathArray[i]).toPath().toUri().toURL();
}
- if (javaVersion > 8) {
- ClassLoader parent = (ClassLoader)
ClassLoader.class.getDeclaredMethod("getPlatformClassLoader").invoke(null);
- return new URLClassLoader(elements, parent);
- }
- return new URLClassLoader(elements, null);
+
+ ClassLoader parent = ClassLoader.getPlatformClassLoader();
+ return new TestClassLoader(elements, parent);
}
protected static void startServer(File folder,
@@ -119,6 +153,10 @@ public class ClasspathBase {
protected ClassLoader getClasspath(String name, boolean forceNew) throws
Exception {
+ if (name.equals(GroovyRun.ONE_FIVE) || name.equals(GroovyRun.TWO_ZERO)) {
+ Assume.assumeTrue("This version of artemis cannot be ran against
JDK16+", getJavaVersion() < 16);
+ }
+
if (!forceNew) {
if (name.equals(SNAPSHOT)) {
GroovyRun.clear();
@@ -174,13 +212,17 @@ public class ClasspathBase {
});
}
- protected static void clearGroovy(ClassLoader loader) throws Exception {
- tclCall(loader, () -> {
- Class clazz = loader.loadClass(GroovyRun.class.getName());
- Method method = clazz.getMethod("clear");
- method.invoke(null);
- return null;
- });
+ protected static void clearGroovy(ClassLoader loader) {
+ try {
+ tclCall(loader, () -> {
+ Class clazz = loader.loadClass(GroovyRun.class.getName());
+ Method method = clazz.getMethod("clear");
+ method.invoke(null);
+ return null;
+ });
+ } catch (Throwable e) {
+ logger.warn(e.getMessage(), e);
+ }
}
protected static Object setVariable(ClassLoader loader, String name) throws
Exception {
diff --git
a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/TestClassLoader.java
b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/TestClassLoader.java
new file mode 100644
index 0000000000..7dcba349a5
--- /dev/null
+++
b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/TestClassLoader.java
@@ -0,0 +1,48 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * The ASF licenses this file to You under the Apache License, Version 2.0
+ * (the "License"); you may not use this file except in compliance with
+ * the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.activemq.artemis.tests.compatibility.base;
+
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.net.URLStreamHandlerFactory;
+
+/** The sole purpose of this class is to be a tag for eventually looking into
MemoryDumps.
+ * When tests are failing, I need to identify the classloaders created by the
testsuite.
+ * And this class would make it simpler for that purpose. */
+public class TestClassLoader extends URLClassLoader {
+
+ public TestClassLoader(URL[] urls, ClassLoader parent) {
+ super(urls, parent);
+ }
+
+ public TestClassLoader(URL[] urls) {
+ super(urls);
+ }
+
+ public TestClassLoader(URL[] urls, ClassLoader parent,
URLStreamHandlerFactory factory) {
+ super(urls, parent, factory);
+ }
+
+ public TestClassLoader(String name, URL[] urls, ClassLoader parent) {
+ super(name, urls, parent);
+ }
+
+ public TestClassLoader(String name, URL[] urls, ClassLoader parent,
URLStreamHandlerFactory factory) {
+ super(name, urls, parent, factory);
+ }
+}
diff --git
a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/VersionedBase.java
b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/VersionedBase.java
index 9beb440ef3..e3e56ef60c 100644
---
a/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/VersionedBase.java
+++
b/tests/compatibility-tests/src/test/java/org/apache/activemq/artemis/tests/compatibility/base/VersionedBase.java
@@ -21,10 +21,12 @@ import java.io.File;
import java.util.LinkedList;
import java.util.List;
-import org.junit.AfterClass;
+import org.jboss.logging.Logger;
public abstract class VersionedBase extends ClasspathBase {
+ private static final Logger logger = Logger.getLogger(VersionedBase.class);
+
protected final String server;
protected final String sender;
protected final String receiver;
@@ -48,11 +50,6 @@ public abstract class VersionedBase extends ClasspathBase {
clearGroovy(serverClassloader);
}
- @AfterClass
- public static void cleanup() {
- loaderMap.clear();
- }
-
protected static List<Object[]> combinatory(Object[] rootSide, Object[]
sideLeft, Object[] sideRight) {
return combinatory(null, rootSide, sideLeft, sideRight);
}