Search in sources :

Example 1 with DefaultTestAppender

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());
}
Also used : Appender(org.apache.log4j.Appender) DefaultTestAppender(org.apache.activemq.util.DefaultTestAppender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultTestAppender(org.apache.activemq.util.DefaultTestAppender) InvalidClientIDException(javax.jms.InvalidClientIDException) Connection(javax.jms.Connection)

Example 2 with DefaultTestAppender

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);
}
Also used : LoggingEvent(org.apache.log4j.spi.LoggingEvent) DefaultTestAppender(org.apache.activemq.util.DefaultTestAppender) JMSException(javax.jms.JMSException) DemandForwardingBridgeSupport(org.apache.activemq.network.DemandForwardingBridgeSupport)

Example 3 with DefaultTestAppender

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());
}
Also used : Appender(org.apache.log4j.Appender) DefaultTestAppender(org.apache.activemq.util.DefaultTestAppender) LoggingEvent(org.apache.log4j.spi.LoggingEvent) AtomicBoolean(java.util.concurrent.atomic.AtomicBoolean) DefaultTestAppender(org.apache.activemq.util.DefaultTestAppender) QueueViewMBean(org.apache.activemq.broker.jmx.QueueViewMBean) Level(org.apache.log4j.Level)

Aggregations

DefaultTestAppender (org.apache.activemq.util.DefaultTestAppender)3 LoggingEvent (org.apache.log4j.spi.LoggingEvent)3 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)2 Appender (org.apache.log4j.Appender)2 Connection (javax.jms.Connection)1 InvalidClientIDException (javax.jms.InvalidClientIDException)1 JMSException (javax.jms.JMSException)1 QueueViewMBean (org.apache.activemq.broker.jmx.QueueViewMBean)1 DemandForwardingBridgeSupport (org.apache.activemq.network.DemandForwardingBridgeSupport)1 Level (org.apache.log4j.Level)1