From 7fdfdeba79d849623d3e82beded4786c1e337dea Mon Sep 17 00:00:00 2001 From: Timothy Bish Date: Wed, 4 Mar 2015 10:44:03 -0500 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-5621 Turn off JMX, switch to JUnit 4 style test with timeout, actually shutdown the running broker and clean up in tear down method. --- .../org/apache/activemq/bugs/AMQ3779Test.java | 74 +++++++++++++------ 1 file changed, 51 insertions(+), 23 deletions(-) diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ3779Test.java b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ3779Test.java index 5a410e87a4..e068a4cfbc 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ3779Test.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/bugs/AMQ3779Test.java @@ -17,29 +17,40 @@ package org.apache.activemq.bugs; +import static org.junit.Assert.assertTrue; + import java.util.concurrent.atomic.AtomicBoolean; + import javax.jms.Connection; import javax.jms.DeliveryMode; import javax.jms.MessageProducer; import javax.jms.Session; + import org.apache.activemq.ActiveMQConnectionFactory; -import org.apache.activemq.AutoFailTestSupport; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.util.LoggingBrokerPlugin; import org.apache.activemq.util.DefaultTestAppender; import org.apache.log4j.Appender; import org.apache.log4j.Logger; import org.apache.log4j.spi.LoggingEvent; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; -public class AMQ3779Test extends AutoFailTestSupport { +public class AMQ3779Test { - private static final Logger logger = Logger.getLogger(AMQ3779Test.class); + private static final Logger LOG = Logger.getLogger(AMQ3779Test.class); private static final String qName = "QNameToFind"; - public void testLogPerDest() throws Exception { + private BrokerService brokerService; + private Appender appender; + private final AtomicBoolean ok = new AtomicBoolean(false); - final AtomicBoolean ok = new AtomicBoolean(false); - Appender appender = new DefaultTestAppender() { + @Before + public void setUp() throws Exception { + ok.set(false); + + appender = new DefaultTestAppender() { @Override public void doAppend(LoggingEvent event) { if (event.getLoggerName().toString().contains(qName)) { @@ -47,30 +58,47 @@ public class AMQ3779Test extends AutoFailTestSupport { } } }; - logger.getRootLogger().addAppender(appender); + + Logger.getRootLogger().addAppender(appender); try { - - BrokerService broker = new BrokerService(); + brokerService = new BrokerService(); LoggingBrokerPlugin loggingBrokerPlugin = new LoggingBrokerPlugin(); loggingBrokerPlugin.setPerDestinationLogger(true); loggingBrokerPlugin.setLogAll(true); - broker.setPlugins(new LoggingBrokerPlugin[]{loggingBrokerPlugin}); - broker.start(); + brokerService.setPlugins(new LoggingBrokerPlugin[]{loggingBrokerPlugin}); - - Connection connection = new ActiveMQConnectionFactory(broker.getVmConnectorURI()).createConnection(); - Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - MessageProducer messageProducer = session.createProducer(session.createQueue(qName)); - messageProducer.setDeliveryMode(DeliveryMode.PERSISTENT); - connection.start(); - - messageProducer.send(session.createTextMessage("Hi")); - connection.close(); - - assertTrue("got expected log message", ok.get()); + brokerService.setPersistent(false); + brokerService.setUseJmx(false); + brokerService.start(); } finally { - logger.removeAppender(appender); + LOG.removeAppender(appender); } } + + @After + public void tearDown() throws Exception { + try { + if (brokerService != null) { + brokerService.stop(); + brokerService.waitUntilStopped(); + } + } finally { + LOG.removeAppender(appender); + } + } + + @Test(timeout = 60000) + public void testLogPerDest() throws Exception { + Connection connection = new ActiveMQConnectionFactory(brokerService.getVmConnectorURI()).createConnection(); + Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + MessageProducer messageProducer = session.createProducer(session.createQueue(qName)); + messageProducer.setDeliveryMode(DeliveryMode.PERSISTENT); + connection.start(); + + messageProducer.send(session.createTextMessage("Hi")); + connection.close(); + + assertTrue("got expected log message", ok.get()); + } }