This is an automated email from the ASF dual-hosted git repository.
robbie 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 8195394eca ARTEMIS-4511: adjust MainTest to clean up resources in case
of failure, prevent knock-on test failures
8195394eca is described below
commit 8195394eca07217e73a7946fecef0f658339da63
Author: Robbie Gemmell <[email protected]>
AuthorDate: Mon Nov 20 11:09:09 2023 +0000
ARTEMIS-4511: adjust MainTest to clean up resources in case of failure,
prevent knock-on test failures
---
.../artemis/core/server/embedded/MainTest.java | 33 ++++++++++++++++++++--
1 file changed, 30 insertions(+), 3 deletions(-)
diff --git
a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/embedded/MainTest.java
b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/embedded/MainTest.java
index 3ff3291755..3f391a2da2 100644
---
a/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/embedded/MainTest.java
+++
b/artemis-server/src/test/java/org/apache/activemq/artemis/core/server/embedded/MainTest.java
@@ -16,15 +16,42 @@
*/
package org.apache.activemq.artemis.core.server.embedded;
+import static org.junit.Assert.fail;
+
import java.io.IOException;
+import java.lang.invoke.MethodHandles;
import org.junit.Test;
-
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
public class MainTest {
- @Test(expected = IOException.class, timeout = 5000)
+ private static final Logger logger =
LoggerFactory.getLogger(MethodHandles.lookup().lookupClass());
+
+ /* Tests what happens when no workdir arg is given and the default can't
+ * be accessed as not in container env, expect to throw IOE. */
+ @Test(timeout = 5000)
public void testNull() throws Exception {
- Main.main(new String[]{});
+ try {
+ Main.main(new String[] {""});
+ fail("Should have thrown an exception");
+ } catch (IOException expected) {
+ // Expected
+ logger.info("Caught expected IOException: " + expected.getMessage());
+ } finally {
+ EmbeddedActiveMQ server = Main.getEmbeddedServer();
+ if (server != null) {
+ // Happens if the startup succeeds unexpectedly, but is
+ // interrupted before return, e.g during a test timeout.
+ // Clean up to avoid impacting later tests.
+ try {
+ server.stop();
+ } catch (Throwable t) {
+ // Log but suppress, allowing original issue be reported as
failure.
+ logger.warn("Caught issue while stopping the
unexpectedly-present server", t);
+ }
+ }
+ }
}
}