use of org.apache.activemq.util.DefaultTestAppender in project activemq-artemis by apache.
the class ReconnectWithSameClientIDTest method testReconnectMultipleTimesWithSameClientID.
public void testReconnectMultipleTimesWithSameClientID() throws Exception {
org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(org.apache.activemq.broker.jmx.ManagedTransportConnection.class);
final AtomicBoolean failed = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() {
@Override
public void doAppend(LoggingEvent event) {
if (event.getMessage().toString().startsWith("Failed to register MBean")) {
LOG.info("received unexpected log message: " + event.getMessage());
failed.set(true);
}
}
};
log4jLogger.addAppender(appender);
try {
connection = connectionFactory.createConnection();
useConnection(connection);
// now lets create another which should fail
for (int i = 1; i < 11; i++) {
Connection connection2 = connectionFactory.createConnection();
try {
useConnection(connection2);
fail("Should have thrown InvalidClientIDException on attempt" + i);
} catch (InvalidClientIDException e) {
LOG.info("Caught expected: " + e);
} finally {
connection2.close();
}
}
// now lets try closing the original connection and creating a new
// connection with the same ID
connection.close();
connection = connectionFactory.createConnection();
useConnection(connection);
} finally {
log4jLogger.removeAppender(appender);
}
assertFalse("failed on unexpected log event", failed.get());
}
use of org.apache.activemq.util.DefaultTestAppender in project activemq-artemis by apache.
the class RequestReplyTempDestRemovalAdvisoryRaceTest method slowDownAdvisoryDispatch.
private void slowDownAdvisoryDispatch() throws Exception {
org.apache.log4j.Logger.getLogger(DemandForwardingBridgeSupport.class).setLevel(Level.DEBUG);
// instrument a logger to block the processing of a remove sub advisory
// simulate a slow thread
slowDownAppender = new DefaultTestAppender() {
@Override
public void doAppend(LoggingEvent loggingEvent) {
if (Level.DEBUG.equals(loggingEvent.getLevel())) {
String message = loggingEvent.getMessage().toString();
if (message.startsWith("BrokerB") && message.contains("remove local subscription")) {
// sleep for a bit
try {
consumerDemandExists.countDown();
System.err.println("Sleeping on receipt of remove info debug message: " + message);
TimeUnit.SECONDS.sleep(2);
} catch (Exception ignored) {
}
}
}
}
};
org.apache.log4j.Logger.getRootLogger().addAppender(slowDownAppender);
}
use of org.apache.activemq.util.DefaultTestAppender in project activemq-artemis by apache.
the class QueuePurgeTest method testPurgeLargeQueue.
public void testPurgeLargeQueue() throws Exception {
applyBrokerSpoolingPolicy();
createProducerAndSendMessages(NUM_TO_SEND);
QueueViewMBean proxy = getProxyToQueueViewMBean();
LOG.info("purging..");
org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(org.apache.activemq.broker.region.Queue.class);
final AtomicBoolean gotPurgeLogMessage = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() {
@Override
public void doAppend(LoggingEvent event) {
if (event.getMessage() instanceof String) {
String message = (String) event.getMessage();
if (message.contains("purged of " + NUM_TO_SEND + " messages")) {
LOG.info("Received a log message: {} ", event.getMessage());
gotPurgeLogMessage.set(true);
}
}
}
};
Level level = log4jLogger.getLevel();
log4jLogger.setLevel(Level.INFO);
log4jLogger.addAppender(appender);
try {
proxy.purge();
} finally {
log4jLogger.setLevel(level);
log4jLogger.removeAppender(appender);
}
assertEquals("Queue size is not zero, it's " + proxy.getQueueSize(), 0, proxy.getQueueSize());
assertTrue("cache is disabled, temp store being used", !proxy.isCacheEnabled());
assertTrue("got expected info purge log message", gotPurgeLogMessage.get());
}
Aggregations