From 39a20bd788c664105c18886abf77c372cf9229aa Mon Sep 17 00:00:00 2001 From: "Christopher L. Shannon" Date: Sun, 29 Nov 2015 10:05:27 -0500 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-6065 Fixed test case so that a System.exit call will not take down the JVM and cause the test suite to abort in Jenkins early --- activemq-broker/pom.xml | 5 ++++ .../util/DefaultIOExceptionHandlerTest.java | 26 +++++++++++++++---- pom.xml | 7 +++++ 3 files changed, 33 insertions(+), 5 deletions(-) diff --git a/activemq-broker/pom.xml b/activemq-broker/pom.xml index 5f8545bcdf..b905db3dc5 100755 --- a/activemq-broker/pom.xml +++ b/activemq-broker/pom.xml @@ -78,6 +78,11 @@ junit test + + com.github.stefanbirkner + system-rules + test + org.slf4j slf4j-log4j12 diff --git a/activemq-broker/src/test/java/org/apache/activemq/util/DefaultIOExceptionHandlerTest.java b/activemq-broker/src/test/java/org/apache/activemq/util/DefaultIOExceptionHandlerTest.java index a9e207032d..0d63e1e4f5 100644 --- a/activemq-broker/src/test/java/org/apache/activemq/util/DefaultIOExceptionHandlerTest.java +++ b/activemq-broker/src/test/java/org/apache/activemq/util/DefaultIOExceptionHandlerTest.java @@ -17,27 +17,43 @@ package org.apache.activemq.util; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import static org.junit.Assert.fail; + import java.io.IOException; import java.util.concurrent.CountDownLatch; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; + import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.SuppressReplyException; +import org.junit.Rule; import org.junit.Test; - - -import static org.junit.Assert.*; +import org.junit.contrib.java.lang.system.ExpectedSystemExit; +import org.junit.contrib.java.lang.system.internal.NoExitSecurityManager; public class DefaultIOExceptionHandlerTest { + @Rule + public final ExpectedSystemExit exit = ExpectedSystemExit.none(); + DefaultIOExceptionHandler underTest = new DefaultIOExceptionHandler(); - @Test + @Test(timeout=20000) public void testHandleWithShutdownOnExit() throws Exception { + exit.expectSystemExit(); doTest(true); + assertTrue(Wait.waitFor(new Wait.Condition() { + @Override + public boolean isSatisified() throws Exception { + return ((NoExitSecurityManager)System.getSecurityManager()).isCheckExitCalled(); + } + }, 10000)); + } - @Test + @Test(timeout=20000) public void testHandleWithOutShutdownOnExit() throws Exception { doTest(false); } diff --git a/pom.xml b/pom.xml index f988a3fb61..d26d3329ab 100755 --- a/pom.xml +++ b/pom.xml @@ -117,6 +117,7 @@ 4.1.8.RELEASE 1.2.1 3.0.2 + 1.13.0 1.7 4.2.0 2.7.2 @@ -995,6 +996,12 @@ ${junit-version} test + + com.github.stefanbirkner + system-rules + ${system-rules-version} + test + org.mockito mockito-core