Test fix, don't produce a StackOverflowException

git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@1489997 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Timothy A. Bish 2013-06-05 18:41:58 +00:00
parent 01cda8582a
commit 6ea8438071
1 changed files with 12 additions and 1 deletions

View File

@ -17,10 +17,13 @@
package org.apache.activemq.bugs; package org.apache.activemq.bugs;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import javax.jms.Connection; import javax.jms.Connection;
import javax.jms.ConnectionFactory; import javax.jms.ConnectionFactory;
import javax.jms.JMSException; import javax.jms.JMSException;
import junit.framework.TestCase; import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.TransportConnection; import org.apache.activemq.broker.TransportConnection;
import org.apache.activemq.transport.TransportDisposedIOException; import org.apache.activemq.transport.TransportDisposedIOException;
@ -42,6 +45,12 @@ public class AMQ2902Test extends TestCase {
public void doAppend(LoggingEvent event) { public void doAppend(LoggingEvent event) {
if (event.getThrowableInformation() != null if (event.getThrowableInformation() != null
&& event.getThrowableInformation().getThrowable() instanceof TransportDisposedIOException) { && 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()); LOG.error("got event: " + event + ", ex:" + event.getThrowableInformation().getThrowable(), event.getThrowableInformation().getThrowable());
gotExceptionInLog.set(Boolean.TRUE); gotExceptionInLog.set(Boolean.TRUE);
} }
@ -70,6 +79,7 @@ public class AMQ2902Test extends TestCase {
connection.close(); connection.close();
} }
@Override
public void setUp() throws Exception { public void setUp() throws Exception {
gotExceptionInLog.set(Boolean.FALSE); gotExceptionInLog.set(Boolean.FALSE);
failedToFindMDC.set(Boolean.FALSE); failedToFindMDC.set(Boolean.FALSE);
@ -78,6 +88,7 @@ public class AMQ2902Test extends TestCase {
Logger.getLogger(TransportConnection.class.getName()).setLevel(Level.DEBUG); Logger.getLogger(TransportConnection.class.getName()).setLevel(Level.DEBUG);
} }
@Override
public void tearDown() throws Exception { public void tearDown() throws Exception {
Logger.getRootLogger().removeAppender(appender); Logger.getRootLogger().removeAppender(appender);
assertFalse("got unexpected ex in log on graceful close", gotExceptionInLog.get()); assertFalse("got unexpected ex in log on graceful close", gotExceptionInLog.get());