mirror of https://github.com/apache/activemq.git
Turn off JMX, switch to JUnit 4 style test with timeout, actually shutdown the running broker and clean up in tear down method.
This commit is contained in:
parent
ac24a08b8b
commit
7fdfdeba79
|
@ -17,29 +17,40 @@
|
||||||
|
|
||||||
package org.apache.activemq.bugs;
|
package org.apache.activemq.bugs;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import java.util.concurrent.atomic.AtomicBoolean;
|
import java.util.concurrent.atomic.AtomicBoolean;
|
||||||
|
|
||||||
import javax.jms.Connection;
|
import javax.jms.Connection;
|
||||||
import javax.jms.DeliveryMode;
|
import javax.jms.DeliveryMode;
|
||||||
import javax.jms.MessageProducer;
|
import javax.jms.MessageProducer;
|
||||||
import javax.jms.Session;
|
import javax.jms.Session;
|
||||||
|
|
||||||
import org.apache.activemq.ActiveMQConnectionFactory;
|
import org.apache.activemq.ActiveMQConnectionFactory;
|
||||||
import org.apache.activemq.AutoFailTestSupport;
|
|
||||||
import org.apache.activemq.broker.BrokerService;
|
import org.apache.activemq.broker.BrokerService;
|
||||||
import org.apache.activemq.broker.util.LoggingBrokerPlugin;
|
import org.apache.activemq.broker.util.LoggingBrokerPlugin;
|
||||||
import org.apache.activemq.util.DefaultTestAppender;
|
import org.apache.activemq.util.DefaultTestAppender;
|
||||||
import org.apache.log4j.Appender;
|
import org.apache.log4j.Appender;
|
||||||
import org.apache.log4j.Logger;
|
import org.apache.log4j.Logger;
|
||||||
import org.apache.log4j.spi.LoggingEvent;
|
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";
|
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);
|
@Before
|
||||||
Appender appender = new DefaultTestAppender() {
|
public void setUp() throws Exception {
|
||||||
|
ok.set(false);
|
||||||
|
|
||||||
|
appender = new DefaultTestAppender() {
|
||||||
@Override
|
@Override
|
||||||
public void doAppend(LoggingEvent event) {
|
public void doAppend(LoggingEvent event) {
|
||||||
if (event.getLoggerName().toString().contains(qName)) {
|
if (event.getLoggerName().toString().contains(qName)) {
|
||||||
|
@ -47,30 +58,47 @@ public class AMQ3779Test extends AutoFailTestSupport {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
};
|
};
|
||||||
logger.getRootLogger().addAppender(appender);
|
|
||||||
|
Logger.getRootLogger().addAppender(appender);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
|
brokerService = new BrokerService();
|
||||||
BrokerService broker = new BrokerService();
|
|
||||||
LoggingBrokerPlugin loggingBrokerPlugin = new LoggingBrokerPlugin();
|
LoggingBrokerPlugin loggingBrokerPlugin = new LoggingBrokerPlugin();
|
||||||
loggingBrokerPlugin.setPerDestinationLogger(true);
|
loggingBrokerPlugin.setPerDestinationLogger(true);
|
||||||
loggingBrokerPlugin.setLogAll(true);
|
loggingBrokerPlugin.setLogAll(true);
|
||||||
broker.setPlugins(new LoggingBrokerPlugin[]{loggingBrokerPlugin});
|
brokerService.setPlugins(new LoggingBrokerPlugin[]{loggingBrokerPlugin});
|
||||||
broker.start();
|
|
||||||
|
|
||||||
|
brokerService.setPersistent(false);
|
||||||
Connection connection = new ActiveMQConnectionFactory(broker.getVmConnectorURI()).createConnection();
|
brokerService.setUseJmx(false);
|
||||||
Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
|
brokerService.start();
|
||||||
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());
|
|
||||||
} finally {
|
} 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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in New Issue