diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractTestWithCallbacksExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractTestWithCallbacksExtension.java index c48fdc5624a9e..0299c686e134d 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractTestWithCallbacksExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/AbstractTestWithCallbacksExtension.java @@ -100,7 +100,7 @@ protected void invokeAfterAllCallbacks(Class clazz, Object testContext) throw invokeCallbacks(afterAllCallbacks, "afterAll", clazz, testContext); } - protected void populateCallbacks(ClassLoader classLoader) throws ClassNotFoundException { + protected static void clearCallbacks() { beforeClassCallbacks = new ArrayList<>(); afterConstructCallbacks = new ArrayList<>(); beforeEachCallbacks = new ArrayList<>(); @@ -108,6 +108,10 @@ protected void populateCallbacks(ClassLoader classLoader) throws ClassNotFoundEx afterTestCallbacks = new ArrayList<>(); afterEachCallbacks = new ArrayList<>(); afterAllCallbacks = new ArrayList<>(); + } + + protected void populateCallbacks(ClassLoader classLoader) throws ClassNotFoundException { + clearCallbacks(); ServiceLoader quarkusTestBeforeClassLoader = ServiceLoader .load(Class.forName(QuarkusTestBeforeClassCallback.class.getName(), false, classLoader), classLoader); diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestExtensionState.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestExtensionState.java index 0983096593d22..5c51ae0d062f4 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestExtensionState.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/IntegrationTestExtensionState.java @@ -8,11 +8,11 @@ public class IntegrationTestExtensionState extends QuarkusTestExtensionState { - private Map sysPropRestore; + private final Map sysPropRestore; public IntegrationTestExtensionState(TestResourceManager testResourceManager, Closeable resource, - Map sysPropRestore) { - super(testResourceManager, resource); + Runnable clearCallbacks, Map sysPropRestore) { + super(testResourceManager, resource, clearCallbacks); this.sysPropRestore = sysPropRestore; } diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java index c2c6d43c99ac2..1dd9e846a844f 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusIntegrationTestExtension.java @@ -13,12 +13,10 @@ import static io.quarkus.test.junit.IntegrationTestUtil.handleDevServices; import static io.quarkus.test.junit.IntegrationTestUtil.readQuarkusArtifactProperties; import static io.quarkus.test.junit.IntegrationTestUtil.startLauncher; -import static io.quarkus.test.junit.TestResourceUtil.testResourcesRequireReload; import static io.quarkus.test.junit.TestResourceUtil.TestResourceManagerReflections.copyEntriesFromProfile; import java.io.Closeable; import java.io.File; -import java.io.IOException; import java.lang.reflect.Field; import java.nio.file.Path; import java.time.Duration; @@ -108,7 +106,6 @@ public void beforeTestExecution(ExtensionContext context) throws Exception { } else { throwBootFailureException(); - return; } } @@ -305,7 +302,7 @@ public void close() throws Throwable { Closeable resource = new IntegrationTestExtensionStateResource(launcher, devServicesLaunchResult.getCuratedApplication()); IntegrationTestExtensionState state = new IntegrationTestExtensionState(testResourceManager, resource, - sysPropRestore); + AbstractTestWithCallbacksExtension::clearCallbacks, sysPropRestore); testHttpEndpointProviders = TestHttpEndpointProvider.load(); return state; @@ -467,7 +464,7 @@ public IntegrationTestExtensionStateResource(ArtifactLauncher launcher, } @Override - public void close() throws IOException { + public void close() { if (launcher != null) { try { launcher.close(); diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java index 33e6a6175196d..4d9c48d8ca2ba 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtension.java @@ -3,7 +3,6 @@ import static io.quarkus.test.junit.IntegrationTestUtil.activateLogging; import java.io.Closeable; -import java.io.IOException; import java.lang.management.ManagementFactory; import java.lang.management.ThreadInfo; import java.lang.reflect.Constructor; @@ -272,7 +271,7 @@ public Thread newThread(Runnable r) { Closeable shutdownTask = new Closeable() { @Override - public void close() throws IOException { + public void close() { TracingHandler.quarkusStopping(); try { runningQuarkusApplication.close(); @@ -295,8 +294,7 @@ public void close() throws IOException { } } }; - ExtensionState state = new ExtensionState(testResourceManager, shutdownTask); - return state; + return new ExtensionState(testResourceManager, shutdownTask, AbstractTestWithCallbacksExtension::clearCallbacks); } catch (Throwable e) { if (!InitialConfigurator.DELAYED_HANDLER.isActivated()) { activateLogging(); @@ -1176,12 +1174,12 @@ public ConditionEvaluationResult evaluateExecutionCondition(ExtensionContext con public static class ExtensionState extends QuarkusTestExtensionState { - public ExtensionState(Closeable testResourceManager, Closeable resource) { - super(testResourceManager, resource); + public ExtensionState(Closeable testResourceManager, Closeable resource, Runnable clearCallbacks) { + super(testResourceManager, resource, clearCallbacks); } @Override - protected void doClose() throws IOException { + protected void doClose() { ClassLoader old = Thread.currentThread().getContextClassLoader(); if (runningQuarkusApplication != null) { Thread.currentThread().setContextClassLoader(runningQuarkusApplication.getClassLoader()); diff --git a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtensionState.java b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtensionState.java index 6024cb50f400c..121bf20220c0d 100644 --- a/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtensionState.java +++ b/test-framework/junit5/src/main/java/io/quarkus/test/junit/QuarkusTestExtensionState.java @@ -15,11 +15,13 @@ public class QuarkusTestExtensionState implements ExtensionContext.Store.Closeab protected final Closeable testResourceManager; protected final Closeable resource; private final Thread shutdownHook; + private final Runnable clearCallbacks; private Throwable testErrorCause; - public QuarkusTestExtensionState(Closeable testResourceManager, Closeable resource) { + public QuarkusTestExtensionState(Closeable testResourceManager, Closeable resource, Runnable clearCallbacks) { this.testResourceManager = testResourceManager; this.resource = resource; + this.clearCallbacks = clearCallbacks; this.shutdownHook = new Thread(new Runnable() { @Override public void run() { @@ -40,6 +42,7 @@ public Throwable getTestErrorCause() { public void close() throws IOException { if (closed.compareAndSet(false, true)) { doClose(); + clearCallbacks.run(); try { Runtime.getRuntime().removeShutdownHook(shutdownHook);