From 6ea84380713f6d3942c56e983f654c6e5dc79e2a Mon Sep 17 00:00:00 2001 From: "Timothy A. Bish" Date: Wed, 5 Jun 2013 18:41:58 +0000 Subject: [PATCH] Test fix, don't produce a StackOverflowException git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1489997 13f79535-47bb-0310-9956-ffa450edef68 --- .../java/org/apache/activemq/bugs/AMQ2902Test.java | 13 ++++++++++++- 1 file changed, 12 insertions(+), 1 deletion(-) diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2902Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2902Test.java index fed4c96893..0b1dd9b135 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2902Test.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ2902Test.java @@ -17,10 +17,13 @@ package org.apache.activemq.bugs; import java.util.concurrent.atomic.AtomicBoolean; + import javax.jms.Connection; import javax.jms.ConnectionFactory; import javax.jms.JMSException; + import junit.framework.TestCase; + import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.broker.TransportConnection; import org.apache.activemq.transport.TransportDisposedIOException; @@ -36,12 +39,18 @@ public class AMQ2902Test extends TestCase { final AtomicBoolean gotExceptionInLog = new AtomicBoolean(Boolean.FALSE); final AtomicBoolean failedToFindMDC = new AtomicBoolean(Boolean.FALSE); - + Appender appender = new DefaultTestAppender() { @Override public void doAppend(LoggingEvent event) { if (event.getThrowableInformation() != null && event.getThrowableInformation().getThrowable() instanceof TransportDisposedIOException) { + + // Prevent StackOverflowException so we can see a sane stack trace. + if (gotExceptionInLog.get()) { + return; + } + LOG.error("got event: " + event + ", ex:" + event.getThrowableInformation().getThrowable(), event.getThrowableInformation().getThrowable()); gotExceptionInLog.set(Boolean.TRUE); } @@ -70,6 +79,7 @@ public class AMQ2902Test extends TestCase { connection.close(); } + @Override public void setUp() throws Exception { gotExceptionInLog.set(Boolean.FALSE); failedToFindMDC.set(Boolean.FALSE); @@ -78,6 +88,7 @@ public class AMQ2902Test extends TestCase { Logger.getLogger(TransportConnection.class.getName()).setLevel(Level.DEBUG); } + @Override public void tearDown() throws Exception { Logger.getRootLogger().removeAppender(appender); assertFalse("got unexpected ex in log on graceful close", gotExceptionInLog.get());