[AMQ-8520] WIP: Convert activemq-unit-tests to log4j2

This commit is contained in:
Matt Pavlovich 2022-03-02 09:13:55 -06:00
parent c1b35058d3
commit 7ec5254bb5
54 changed files with 883 additions and 620 deletions

View File

@ -34,7 +34,6 @@ import javax.jms.TextMessage;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.broker.region.Queue; import org.apache.activemq.broker.region.Queue;
import org.apache.activemq.broker.region.Topic;
import org.apache.activemq.broker.region.policy.PolicyEntry; import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.broker.region.policy.VMPendingQueueMessageStoragePolicy; import org.apache.activemq.broker.region.policy.VMPendingQueueMessageStoragePolicy;
@ -42,9 +41,10 @@ import org.apache.activemq.broker.region.policy.VMPendingSubscriberMessageStorag
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.transport.tcp.TcpTransport; import org.apache.activemq.transport.tcp.TcpTransport;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -261,22 +261,24 @@ public class ProducerFlowControlTest extends JmsTestSupport {
Appender appender = new DefaultTestAppender() { Appender appender = new DefaultTestAppender() {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().toString().contains("Usage Manager Memory Limit")) { if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().contains("Usage Manager Memory Limit")) {
LOG.info("received warn log message: " + event.getMessage()); LOG.info("received warn log message: " + event.getMessage());
warnings.incrementAndGet(); warnings.incrementAndGet();
} }
if (event.getLevel().equals(Level.DEBUG) && event.getMessage().toString().contains("Usage Manager Memory Limit")) { if (event.getLevel().equals(Level.DEBUG) && event.getMessage().getFormattedMessage().contains("Usage Manager Memory Limit")) {
LOG.info("received debug log message: " + event.getMessage()); LOG.info("received debug log message: " + event.getMessage());
debugs.incrementAndGet(); debugs.incrementAndGet();
} }
} }
}; };
org.apache.log4j.Logger log4jLogger = appender.start();
org.apache.log4j.Logger.getLogger(Queue.class);
org.apache.logging.log4j.core.Logger log4jLogger = (org.apache.logging.log4j.core.Logger)LogManager.getLogger(Queue.class);
log4jLogger.addAppender(appender); log4jLogger.addAppender(appender);
log4jLogger.setLevel(Level.DEBUG); log4jLogger.setLevel(Level.DEBUG);
try { try {
ConnectionFactory factory = createConnectionFactory(); ConnectionFactory factory = createConnectionFactory();
connection = (ActiveMQConnection)factory.createConnection(); connection = (ActiveMQConnection)factory.createConnection();

View File

@ -24,9 +24,13 @@ import javax.jms.JMSException;
import javax.jms.Session; import javax.jms.Session;
import junit.framework.Test; import junit.framework.Test;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Appender; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -48,20 +52,22 @@ public class ReconnectWithSameClientIDTest extends EmbeddedBrokerTestSupport {
public void testReconnectMultipleTimesWithSameClientID() throws Exception { 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); final AtomicBoolean failed = new AtomicBoolean(false);
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger((org.apache.activemq.broker.jmx.ManagedTransportConnection.class)));
Appender appender = new DefaultTestAppender() { final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getMessage().toString().startsWith("Failed to register MBean")) { if (event.getMessage().getFormattedMessage().startsWith("Failed to register MBean")) {
LOG.info("received unexpected log message: " + event.getMessage()); LOG.info("received unexpected log message: " + event.getMessage());
failed.set(true); failed.set(true);
} }
} }
}; };
log4jLogger.addAppender(appender); appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try { try {
connection = connectionFactory.createConnection(); connection = connectionFactory.createConnection();
useConnection(connection); useConnection(connection);
@ -85,7 +91,7 @@ public class ReconnectWithSameClientIDTest extends EmbeddedBrokerTestSupport {
connection = connectionFactory.createConnection(); connection = connectionFactory.createConnection();
useConnection(connection); useConnection(connection);
} finally { } finally {
log4jLogger.removeAppender(appender); logger.removeAppender(appender);
} }
assertFalse("failed on unexpected log event", failed.get()); assertFalse("failed on unexpected log event", failed.get());
} }

View File

@ -18,39 +18,44 @@
package org.apache.activemq; package org.apache.activemq;
import org.apache.activemq.broker.jmx.ManagementContext; import org.apache.activemq.broker.jmx.ManagementContext;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.*; import org.junit.*;
import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertFalse;
import java.util.concurrent.*; import java.util.concurrent.*;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import javax.management.JMException; import javax.management.JMException;
import javax.management.ObjectName; import javax.management.ObjectName;
public class TcpTransportCloseConnectionTest { public class TcpTransportCloseConnectionTest {
static boolean transportConnectionFailed = false; static boolean transportConnectionFailed = false;
static final org.apache.logging.log4j.core.Appender appender;
private BrokerService broker; private BrokerService broker;
private final String uri = "tcp://localhost:0?wireFormat.maxInactivityDuration=500"; private final String uri = "tcp://localhost:0?wireFormat.maxInactivityDuration=500";
static final Appender appender = new DefaultTestAppender() { static {
@Override appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
public void doAppend(LoggingEvent event) { @Override
if(event.getMessage().toString().contains("Transport Connection") public void append(LogEvent event) {
&& event.getMessage().toString().contains("failed") String message = event.getMessage().getFormattedMessage();
&& (event.getMessage().toString().contains("java.net.SocketException") || event.getMessage().toString().contains("java.io.EOFException"))) { if(message.contains("Transport Connection")
transportConnectionFailed = true; && message.contains("failed")
&& (message.contains("java.net.SocketException") || message.contains("java.io.EOFException"))) {
transportConnectionFailed = true;
}
} }
} };
}; appender.start();
}
class CustomManagementContext extends ManagementContext { class CustomManagementContext extends ManagementContext {
@Override @Override
@ -67,12 +72,12 @@ public class TcpTransportCloseConnectionTest {
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
org.apache.log4j.Logger.getRootLogger().addAppender(appender); org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).addAppender(appender);
} }
@AfterClass @AfterClass
public static void setDown() throws Exception { public static void setDown() throws Exception {
org.apache.log4j.Logger.getRootLogger().removeAppender(appender); org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).removeAppender(appender);
} }
@Before @Before

View File

@ -27,8 +27,9 @@ import javax.management.ObjectName;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.EmbeddedBrokerTestSupport; import org.apache.activemq.EmbeddedBrokerTestSupport;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Logger;
import org.junit.Test; import org.junit.Test;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -112,7 +113,7 @@ public class Log4JConfigTest extends EmbeddedBrokerTestSupport {
String level = log4jConfigView.getLogLevel("not.a.logger"); String level = log4jConfigView.getLogLevel("not.a.logger");
assertNotNull(level); assertNotNull(level);
assertFalse(level.isEmpty()); assertFalse(level.isEmpty());
assertEquals(Logger.getRootLogger().getLevel().toString(), level); assertEquals(LogManager.getRootLogger().getLevel().toString(), level);
} }
@Test @Test
@ -166,7 +167,7 @@ public class Log4JConfigTest extends EmbeddedBrokerTestSupport {
assertNotNull(level); assertNotNull(level);
assertFalse(level.isEmpty()); assertFalse(level.isEmpty());
String currentRootLevel = Logger.getRootLogger().getLevel().toString(); String currentRootLevel = LogManager.getRootLogger().getLevel().toString();
assertEquals(currentRootLevel, level); assertEquals(currentRootLevel, level);
} }
@ -177,12 +178,12 @@ public class Log4JConfigTest extends EmbeddedBrokerTestSupport {
Log4JConfigViewMBean log4jConfigView = MBeanServerInvocationHandler.newProxyInstance( Log4JConfigViewMBean log4jConfigView = MBeanServerInvocationHandler.newProxyInstance(
mbeanServer, log4jConfigViewName, Log4JConfigViewMBean.class, true); mbeanServer, log4jConfigViewName, Log4JConfigViewMBean.class, true);
String currentRootLevel = Logger.getRootLogger().getLevel().toString(); String currentRootLevel = LogManager.getRootLogger().getLevel().toString();
log4jConfigView.setRootLogLevel("WARN"); log4jConfigView.setRootLogLevel("WARN");
currentRootLevel = Logger.getRootLogger().getLevel().toString(); currentRootLevel = LogManager.getRootLogger().getLevel().toString();
assertEquals("WARN", currentRootLevel); assertEquals("WARN", currentRootLevel);
log4jConfigView.setRootLogLevel("INFO"); log4jConfigView.setRootLogLevel("INFO");
currentRootLevel = Logger.getRootLogger().getLevel().toString(); currentRootLevel = LogManager.getRootLogger().getLevel().toString();
assertEquals("INFO", currentRootLevel); assertEquals("INFO", currentRootLevel);
Level level; Level level;

View File

@ -24,9 +24,13 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -90,20 +94,22 @@ public class DestinationGCStressTest {
@Test(timeout = 60000) @Test(timeout = 60000)
public void testClashWithPublishAndGC() throws Exception { public void testClashWithPublishAndGC() throws Exception {
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(RegionBroker.class);
final AtomicBoolean failed = new AtomicBoolean(false); final AtomicBoolean failed = new AtomicBoolean(false);
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(RegionBroker.class));
Appender appender = new DefaultTestAppender() { final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().equals(Level.ERROR) && event.getMessage().toString().startsWith("Failed to remove inactive")) { if (event.getLevel().equals(Level.ERROR) && event.getMessage().getFormattedMessage().startsWith("Failed to remove inactive")) {
logger.info("received unexpected log message: " + event.getMessage()); logger.info("received unexpected log message: " + event.getMessage());
failed.set(true); failed.set(true);
} }
} }
}; };
log4jLogger.addAppender(appender); appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try { try {
final AtomicInteger max = new AtomicInteger(20000); final AtomicInteger max = new AtomicInteger(20000);
@ -147,7 +153,7 @@ public class DestinationGCStressTest {
connection.close(); connection.close();
} finally { } finally {
log4jLogger.removeAppender(appender); logger.removeAppender(appender);
} }
assertFalse("failed on unexpected log event", failed.get()); assertFalse("failed on unexpected log event", failed.get());
@ -156,16 +162,14 @@ public class DestinationGCStressTest {
@Test(timeout = 60000) @Test(timeout = 60000)
public void testAddRemoveWildcardWithGc() throws Exception { public void testAddRemoveWildcardWithGc() throws Exception {
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(RegionBroker.class);
final AtomicBoolean failed = new AtomicBoolean(false); final AtomicBoolean failed = new AtomicBoolean(false);
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(RegionBroker.class));
Appender appender = new DefaultTestAppender() { final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().equals(Level.ERROR) && event.getMessage().toString().startsWith("Failed to remove inactive")) { if (event.getLevel().equals(Level.ERROR) && event.getMessage().getFormattedMessage().startsWith("Failed to remove inactive")) {
if (event.getThrowableInformation().getThrowable() != null if (event.getThrown() != null
&& event.getThrowableInformation().getThrowable().getCause() instanceof BrokerStoppedException) { && event.getThrown().getCause() instanceof BrokerStoppedException) {
// ok // ok
} else { } else {
logger.info("received unexpected log message: " + event.getMessage()); logger.info("received unexpected log message: " + event.getMessage());
@ -174,7 +178,11 @@ public class DestinationGCStressTest {
} }
} }
}; };
log4jLogger.addAppender(appender); appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try { try {
final AtomicInteger max = new AtomicInteger(10000); final AtomicInteger max = new AtomicInteger(10000);
@ -241,7 +249,7 @@ public class DestinationGCStressTest {
connection.close(); connection.close();
} finally { } finally {
log4jLogger.removeAppender(appender); logger.removeAppender(appender);
} }
assertFalse("failed on unexpected log event", failed.get()); assertFalse("failed on unexpected log event", failed.get());

View File

@ -43,9 +43,9 @@ import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter; import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender; import org.apache.logging.log4j.core.Appender;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -108,14 +108,15 @@ public class QueuePurgeTest extends CombinationTestSupport {
QueueViewMBean proxy = getProxyToQueueViewMBean(); QueueViewMBean proxy = getProxyToQueueViewMBean();
LOG.info("purging.."); LOG.info("purging..");
org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(org.apache.activemq.broker.jmx.QueueView.class); org.apache.logging.log4j.core.Logger log4jLogger = (org.apache.logging.log4j.core.Logger)LogManager.getLogger(org.apache.activemq.broker.jmx.QueueView.class);
final AtomicBoolean gotPurgeLogMessage = new AtomicBoolean(false); final AtomicBoolean gotPurgeLogMessage = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() { Appender appender = new DefaultTestAppender() {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getMessage() instanceof String) { if (event.getMessage() != null) {
String message = (String) event.getMessage(); String message = event.getMessage().getFormattedMessage();
if (message.contains("purge of " + NUM_TO_SEND +" messages")) { if (message.contains("purge of " + NUM_TO_SEND +" messages")) {
LOG.info("Received a log message: {} ", event.getMessage()); LOG.info("Received a log message: {} ", event.getMessage());
gotPurgeLogMessage.set(true); gotPurgeLogMessage.set(true);
@ -123,16 +124,14 @@ public class QueuePurgeTest extends CombinationTestSupport {
} }
} }
}; };
appender.start();
Level level = log4jLogger.getLevel();
log4jLogger.setLevel(Level.INFO);
log4jLogger.addAppender(appender); log4jLogger.addAppender(appender);
try { try {
proxy.purge(); proxy.purge();
} finally { } finally {
log4jLogger.setLevel(level);
log4jLogger.removeAppender(appender); log4jLogger.removeAppender(appender);
} }

View File

@ -40,9 +40,10 @@ import org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.ProducerThread; import org.apache.activemq.util.ProducerThread;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -224,8 +225,8 @@ public class JmsSchedulerTest extends JobSchedulerTestSupport {
Appender appender = new DefaultTestAppender() { Appender appender = new DefaultTestAppender() {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getMessage().toString().contains("Removed Job past last appened in the journal")) { if (event.getMessage() != null && event.getMessage().getFormattedMessage().contains("Removed Job past last appened in the journal")) {
numberOfDiscardedJobs.incrementAndGet(); numberOfDiscardedJobs.incrementAndGet();
} }
} }
@ -263,8 +264,7 @@ public class JmsSchedulerTest extends JobSchedulerTestSupport {
} }
private void registerLogAppender(final Appender appender) { private void registerLogAppender(final Appender appender) {
org.apache.log4j.Logger log4jLogger = org.apache.logging.log4j.core.Logger log4jLogger = (org.apache.logging.log4j.core.Logger)LogManager.getLogger(JobSchedulerStoreImpl.class);
org.apache.log4j.Logger.getLogger(JobSchedulerStoreImpl.class);
log4jLogger.addAppender(appender); log4jLogger.addAppender(appender);
log4jLogger.setLevel(Level.TRACE); log4jLogger.setLevel(Level.TRACE);
} }

View File

@ -32,7 +32,6 @@ import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.store.kahadb.disk.journal.DataFile; import org.apache.activemq.store.kahadb.disk.journal.DataFile;
import org.apache.activemq.store.kahadb.disk.page.Transaction; import org.apache.activemq.store.kahadb.disk.page.Transaction;
import org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl; import org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl;
import org.apache.log4j.Level;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -49,6 +48,8 @@ import javax.jms.TextMessage;
import org.apache.activemq.ScheduledMessage; import org.apache.activemq.ScheduledMessage;
import org.apache.activemq.command.ActiveMQMessage; import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.util.IdGenerator; import org.apache.activemq.util.IdGenerator;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -69,7 +70,7 @@ public class JobSchedulerManagementTest extends JobSchedulerTestSupport {
@Test @Test
public void testRemoveAllScheduled() throws Exception { public void testRemoveAllScheduled() throws Exception {
org.apache.log4j.Logger.getLogger(Transaction.class).setLevel(Level.DEBUG); org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(Transaction.class)).setLevel(Level.DEBUG);
final int COUNT = 5000; final int COUNT = 5000;
System.setProperty("maxKahaDBTxSize", "" + (500*1024)); System.setProperty("maxKahaDBTxSize", "" + (500*1024));
Connection connection = createConnection(); Connection connection = createConnection();

View File

@ -52,7 +52,8 @@ import org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl;
import org.apache.activemq.util.ByteSequence; import org.apache.activemq.util.ByteSequence;
import org.apache.activemq.util.IOHelper; import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -76,7 +77,7 @@ public class JobSchedulerRedliveryPluginDLQStoreCleanupTest {
public void setUp() throws Exception { public void setUp() throws Exception {
// investigate gc issue - store usage not getting released // investigate gc issue - store usage not getting released
org.apache.log4j.Logger.getLogger(JobSchedulerStoreImpl.class).setLevel(Level.TRACE); org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(JobSchedulerStoreImpl.class)).setLevel(Level.TRACE);
File directory = new File("target/test/ScheduledJobsDB"); File directory = new File("target/test/ScheduledJobsDB");
IOHelper.mkdirs(directory); IOHelper.mkdirs(directory);

View File

@ -29,7 +29,8 @@ import org.apache.activemq.store.kahadb.scheduler.JobSchedulerStoreImpl;
import org.apache.activemq.util.ByteSequence; import org.apache.activemq.util.ByteSequence;
import org.apache.activemq.util.IOHelper; import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -48,7 +49,7 @@ public class JobSchedulerStoreCheckpointTest {
public void setUp() throws Exception { public void setUp() throws Exception {
// investigate gc issue - store usage not getting released // investigate gc issue - store usage not getting released
org.apache.log4j.Logger.getLogger(JobSchedulerStoreImpl.class).setLevel(Level.TRACE); org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(JobSchedulerStoreImpl.class)).setLevel(Level.TRACE);
File directory = new File("target/test/ScheduledJobsDB"); File directory = new File("target/test/ScheduledJobsDB");
IOHelper.mkdirs(directory); IOHelper.mkdirs(directory);

View File

@ -36,7 +36,6 @@ import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.ScheduledMessage; import org.apache.activemq.ScheduledMessage;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.util.IOHelper; import org.apache.activemq.util.IOHelper;
import org.apache.log4j.BasicConfigurator;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -74,7 +73,9 @@ public class LostScheduledMessagesTest {
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
broker.stop(); broker.stop();
BasicConfigurator.resetConfiguration();
// [AMQ-8520] FIXME: Convert or remove if not needed
//BasicConfigurator.resetConfiguration();
} }
@Test @Test

View File

@ -43,14 +43,15 @@ import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.AutoFailTestSupport; import org.apache.activemq.AutoFailTestSupport;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* A AMQ1936Test * A AMQ1936Test
* *
*/ */
public class AMQ1936Test extends TestCase { public class AMQ1936Test extends TestCase {
private final static Logger logger = Logger.getLogger(AMQ1936Test.class); private final static Logger logger = LoggerFactory.getLogger(AMQ1936Test.class);
private final static String TEST_QUEUE_NAME = "dynamicQueues/duplicate.message.test.queue"; private final static String TEST_QUEUE_NAME = "dynamicQueues/duplicate.message.test.queue";
// //-- // //--
// //
@ -177,7 +178,7 @@ public class AMQ1936Test extends TestCase {
} }
if (messages.containsKey(message.getJMSMessageID())) { if (messages.containsKey(message.getJMSMessageID())) {
duplicateSignal.countDown(); duplicateSignal.countDown();
logger.fatal("duplicate message id detected:" + message.getJMSMessageID()); logger.error("duplicate message id detected:" + message.getJMSMessageID());
fail("Duplicate message id detected:" + message.getJMSMessageID()); fail("Duplicate message id detected:" + message.getJMSMessageID());
} else { } else {
messages.put(message.getJMSMessageID(), message.getJMSMessageID()); messages.put(message.getJMSMessageID(), message.getJMSMessageID());
@ -275,14 +276,14 @@ public class AMQ1936Test extends TestCase {
try { try {
receiver.close(); receiver.close();
} catch (JMSException e) { } catch (JMSException e) {
logger.warn(e); logger.warn(e.getMessage(), e);
} }
} }
if (session != null) { if (session != null) {
try { try {
session.close(); session.close();
} catch (JMSException e) { } catch (JMSException e) {
logger.warn(e); logger.warn(e.getMessage(), e);
} }
} }
if (queueConnection != null) { if (queueConnection != null) {
@ -290,12 +291,12 @@ public class AMQ1936Test extends TestCase {
} }
} }
} catch (JMSException e) { } catch (JMSException e) {
logger.error(e); logger.error(e.getMessage(), e);
e.printStackTrace(); e.printStackTrace();
} catch (NamingException e) { } catch (NamingException e) {
logger.error(e); logger.error(e.getMessage(), e);
} catch (Exception e) { } catch (Exception e) {
logger.error(e); logger.error(e.getMessage(), e);
e.printStackTrace(); e.printStackTrace();
} }
} }

View File

@ -28,10 +28,10 @@ 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;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.logging.log4j.core.Appender;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
public class AMQ2902Test extends TestCase { public class AMQ2902Test extends TestCase {
@ -41,10 +41,11 @@ public class AMQ2902Test extends TestCase {
final AtomicBoolean failedToFindMDC = new AtomicBoolean(Boolean.FALSE); final AtomicBoolean failedToFindMDC = new AtomicBoolean(Boolean.FALSE);
Appender appender = new DefaultTestAppender() { Appender appender = new DefaultTestAppender() {
@SuppressWarnings("deprecation")
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getThrowableInformation() != null if (event.getThrown() != null
&& event.getThrowableInformation().getThrowable() instanceof TransportDisposedIOException) { && event.getThrown() instanceof TransportDisposedIOException) {
// Prevent StackOverflowException so we can see a sane stack trace. // Prevent StackOverflowException so we can see a sane stack trace.
if (gotExceptionInLog.get()) { if (gotExceptionInLog.get()) {
@ -52,11 +53,11 @@ public class AMQ2902Test extends TestCase {
} }
gotExceptionInLog.set(Boolean.TRUE); gotExceptionInLog.set(Boolean.TRUE);
LOG.error("got event: " + event + ", ex:" + event.getThrowableInformation().getThrowable(), event.getThrowableInformation().getThrowable()); LOG.error("got event: " + event + ", ex:" + event.getThrown(), event);
LOG.error("Event source: ", new Throwable("Here")); LOG.error("Event source: ", new Throwable("Here"));
} }
if( !((String) event.getMessage()).startsWith("Loaded the Bouncy Castle security provider at position") ) { if( !((String) event.getMessage().getFormattedMessage()).startsWith("Loaded the Bouncy Castle security provider at position") ) {
if (event.getMDC("activemq.broker") == null) { if (event.getContextData().getValue("activemq.broker") == null) {
failedToFindMDC.set(Boolean.TRUE); failedToFindMDC.set(Boolean.TRUE);
} }
} }
@ -84,14 +85,14 @@ public class AMQ2902Test extends TestCase {
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);
Logger.getRootLogger().addAppender(appender); ((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger()).addAppender(appender);
Logger.getLogger(TransportConnection.class.getName() + ".Transport").setLevel(Level.DEBUG); ((org.apache.logging.log4j.core.Logger)LogManager.getLogger(TransportConnection.class.getName() + ".Transport")).setLevel(Level.DEBUG);
Logger.getLogger(TransportConnection.class.getName()).setLevel(Level.DEBUG); ((org.apache.logging.log4j.core.Logger)LogManager.getLogger(TransportConnection.class)).setLevel(Level.DEBUG);
} }
@Override @Override
public void tearDown() throws Exception { public void tearDown() throws Exception {
Logger.getRootLogger().removeAppender(appender); ((org.apache.logging.log4j.core.Logger)LogManager.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());
assertFalse("MDC is there", failedToFindMDC.get()); assertFalse("MDC is there", failedToFindMDC.get());
} }

View File

@ -32,10 +32,15 @@ import javax.jms.Session;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.cursors.AbstractStoreCursor;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -71,15 +76,15 @@ public class AMQ3567Test {
@Test @Test
public void runTest() throws Exception { public void runTest() throws Exception {
produceSingleMessage(); produceSingleMessage();
org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger("org.apache.activemq.util.ServiceSupport"); final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger("org.apache.activemq.util.ServiceSupport"));
final AtomicBoolean failed = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() { final AtomicBoolean failed = new AtomicBoolean(false);
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getThrowableInformation() != null) { if (event.getThrown() != null) {
if (event.getThrowableInformation().getThrowable() instanceof InterruptedException) { if (event.getThrown() instanceof InterruptedException) {
InterruptedException ie = (InterruptedException)event.getThrowableInformation().getThrowable(); InterruptedException ie = (InterruptedException)event.getThrown();
if (ie.getMessage().startsWith("Could not stop service:")) { if (ie.getMessage().startsWith("Could not stop service:")) {
logger.info("Received an interrupted exception : ", ie); logger.info("Received an interrupted exception : ", ie);
failed.set(true); failed.set(true);
@ -88,11 +93,14 @@ public class AMQ3567Test {
} }
} }
}; };
log4jLogger.addAppender(appender); appender.start();
Level level = log4jLogger.getLevel(); Level level = logger.getLevel();
log4jLogger.setLevel(Level.DEBUG);
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
logger.setLevel(Level.DEBUG);
try { try {
stopConsumer(); stopConsumer();
stopBroker(); stopBroker();
@ -101,8 +109,8 @@ public class AMQ3567Test {
} }
} finally { } finally {
log4jLogger.setLevel(level); logger.setLevel(level);
log4jLogger.removeAppender(appender); logger.removeAppender(appender);
} }
} }

View File

@ -30,35 +30,47 @@ import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.transport.stomp.Stomp; import org.apache.activemq.transport.stomp.Stomp;
import org.apache.activemq.transport.stomp.StompConnection; import org.apache.activemq.transport.stomp.StompConnection;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Appender; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.logging.log4j.core.Appender;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
public class AMQ3622Test { public class AMQ3622Test {
protected static final Appender appender;
protected static final AtomicBoolean failed = new AtomicBoolean(false);
protected BrokerService broker; protected BrokerService broker;
protected AtomicBoolean failed = new AtomicBoolean(false);
protected String connectionUri; protected String connectionUri;
protected Appender appender = new DefaultTestAppender() { protected Logger logger;
static {
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
System.err.println(event.getMessage()); System.err.println(event.getMessage());
if (event.getThrowableInformation() != null) { if (event.getThrown() != null) {
if (event.getThrowableInformation().getThrowable() instanceof NullPointerException) { if (event.getThrown() instanceof NullPointerException) {
failed.set(true); failed.set(true);
} }
} }
} }
}; };
appender.start();
}
@Before @Before
public void before() throws Exception { public void before() throws Exception {
Logger.getRootLogger().addAppender(appender);
logger = Logger.class.cast(LogManager.getRootLogger());
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
broker = new BrokerService(); broker = new BrokerService();
broker.setDataDirectory("target" + File.separator + "activemq-data"); broker.setDataDirectory("target" + File.separator + "activemq-data");
@ -88,7 +100,7 @@ public class AMQ3622Test {
public void after() throws Exception { public void after() throws Exception {
broker.stop(); broker.stop();
broker.waitUntilStopped(); broker.waitUntilStopped();
Logger.getRootLogger().removeAppender(appender); logger.removeAppender(appender);
} }
@Test @Test

View File

@ -18,10 +18,13 @@ package org.apache.activemq.bugs;
import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Appender; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.logging.log4j.core.LogEvent;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -80,27 +83,32 @@ public class AMQ3625Test {
@Test @Test
public void go() throws Exception { public void go() throws Exception {
Appender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getMessage().toString().contains("java.lang.SecurityException")) { if (event.getMessage() != null && event.getMessage().getFormattedMessage().contains("java.lang.SecurityException")) {
authenticationFailed.set(true); authenticationFailed.set(true);
} }
if (event.getMessage().toString().contains("NullPointerException")) { if (event.getMessage() != null && event.getMessage().getFormattedMessage().contains("NullPointerException")) {
gotNPE.set(true); gotNPE.set(true);
} }
} }
}; };
Logger.getRootLogger().addAppender(appender); appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
String connectURI = broker1.getConnectorByName("openwire").getConnectUri().toString(); String connectURI = broker1.getConnectorByName("openwire").getConnectUri().toString();
connectURI = connectURI.replace("?needClientAuth=true", "?verifyHostName=false"); connectURI = connectURI.replace("?needClientAuth=true", "?verifyHostName=false");
broker2.addNetworkConnector("static:(" + connectURI + ")").start(); broker2.addNetworkConnector("static:(" + connectURI + ")").start();
Thread.sleep(10 * 1000); Thread.sleep(10 * 1000);
Logger.getRootLogger().removeAppender(appender); logger.removeAppender(appender);
assertTrue(authenticationFailed.get()); assertTrue(authenticationFailed.get());
assertFalse(gotNPE.get()); assertFalse(gotNPE.get());
} }

View File

@ -26,10 +26,15 @@ import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
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.logging.log4j.Level;
import org.apache.log4j.Appender; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.logging.log4j.core.Appender;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -38,8 +43,7 @@ import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
public class AMQ3779Test { public class AMQ3779Test {
private static final Logger LOG = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(AMQ3779Test.class));
private static final Logger LOG = Logger.getLogger(AMQ3779Test.class);
private static final String qName = "QNameToFind"; private static final String qName = "QNameToFind";
private BrokerService brokerService; private BrokerService brokerService;
@ -51,20 +55,28 @@ public class AMQ3779Test {
public void setUp() throws Exception { public void setUp() throws Exception {
ok.set(false); ok.set(false);
appender = new DefaultTestAppender() { final var rootLogger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLoggerName().toString().contains(qName)) { if (event.getLoggerName().toString().contains(qName)) {
ok.set(true); ok.set(true);
} }
if (event.getMessage().toString().contains("Sending") && event.getMessage().toString().contains("size = 0")) { String msg = event.getMessage().getFormattedMessage();
if (msg.contains("Sending") && msg.contains("size = 0")) {
gotZeroSize.set(true); gotZeroSize.set(true);
} }
} }
}; };
appender.start();
Logger.getRootLogger().addAppender(appender); LOG.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
LOG.addAppender(appender);
LOG.setLevel(Level.TRACE);
rootLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
rootLogger.addAppender(appender);
try { try {
brokerService = new BrokerService(); brokerService = new BrokerService();
@ -89,7 +101,7 @@ public class AMQ3779Test {
brokerService.waitUntilStopped(); brokerService.waitUntilStopped();
} }
} finally { } finally {
Logger.getRootLogger().removeAppender(appender); org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).removeAppender(appender);
} }
} }

View File

@ -45,10 +45,13 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.store.kahadb.plist.PListStoreImpl; import org.apache.activemq.store.kahadb.plist.PListStoreImpl;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.LogManager; import org.apache.logging.log4j.core.LogEvent;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -84,17 +87,21 @@ public class AMQ4221Test extends TestSupport {
@Override @Override
public void setUp() throws Exception { public void setUp() throws Exception {
LogManager.getRootLogger().addAppender(new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().isGreaterOrEqual(Level.ERROR)) { if (event.getLevel().isMoreSpecificThan(Level.WARN)) {
System.err.println("Fail on error in log: " + event.getMessage()); System.err.println("Fail on error in log: " + event.getMessage());
done.set(true); done.set(true);
errorsInLog.add(event.getRenderedMessage()); errorsInLog.add(event.getMessage().getFormattedMessage());
} }
} }
}); };
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
done.set(false); done.set(false);
errorsInLog.clear(); errorsInLog.clear();

View File

@ -41,10 +41,13 @@ import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.PolicyEntry; import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.AppenderSkeleton; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Level; import org.apache.logging.log4j.core.LogEvent;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -61,7 +64,6 @@ public class AMQ5426Test {
private AtomicBoolean hasFailureInProducer = new AtomicBoolean(false); private AtomicBoolean hasFailureInProducer = new AtomicBoolean(false);
private Thread producerThread; private Thread producerThread;
private AtomicBoolean hasErrorInLogger; private AtomicBoolean hasErrorInLogger;
private Appender errorDetectorAppender;
protected ConnectionFactory createConnectionFactory() throws Exception { protected ConnectionFactory createConnectionFactory() throws Exception {
ActiveMQConnectionFactory conFactory = new ActiveMQConnectionFactory( ActiveMQConnectionFactory conFactory = new ActiveMQConnectionFactory(
@ -92,25 +94,20 @@ public class AMQ5426Test {
// ActiveMQConnection.setClientInternalExceptionListener // ActiveMQConnection.setClientInternalExceptionListener
// since ActiveMQMessageConsumer.dispatch will silently catch and // since ActiveMQMessageConsumer.dispatch will silently catch and
// discard any RuntimeException // discard any RuntimeException
errorDetectorAppender = new AppenderSkeleton() {
@Override final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
public void close() { final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
// Do nothing @Override
} public void append(LogEvent event) {
if (event.getLevel().isMoreSpecificThan(Level.WARN))
@Override hasErrorInLogger.set(true);
public boolean requiresLayout() { }
return false;
}
@Override
protected void append(LoggingEvent event) {
if (event.getLevel().isGreaterOrEqual(Level.ERROR))
hasErrorInLogger.set(true);
}
}; };
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
org.apache.log4j.Logger.getRootLogger().addAppender(errorDetectorAppender);
producerThread = new Thread(new Runnable() { producerThread = new Thread(new Runnable() {
@Override @Override
public void run() { public void run() {

View File

@ -31,16 +31,18 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.policy.AbortSlowConsumerStrategy;
import org.apache.activemq.broker.region.policy.PolicyEntry; import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.transport.failover.FailoverTransport; import org.apache.activemq.transport.failover.FailoverTransport;
import org.apache.activemq.util.DefaultIOExceptionHandler; import org.apache.activemq.util.DefaultIOExceptionHandler;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -75,26 +77,31 @@ public class AMQ5844Test {
static boolean abortingSlowConsumer = false; static boolean abortingSlowConsumer = false;
static boolean successfullyReconnected = false; static boolean successfullyReconnected = false;
static final AbstractAppender appender;
static final Appender appender = new DefaultTestAppender() { static {
@Override appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
public void doAppend(LoggingEvent event) { @Override
if(event.getMessage().toString().contains("aborting slow consumer")) { public void append(LogEvent event) {
abortingSlowConsumer = true; if(event.getMessage().getFormattedMessage().contains("aborting slow consumer")) {
} abortingSlowConsumer = true;
}
if(event.getMessage().toString().contains("Successfully reconnected to")) { if(event.getMessage().getFormattedMessage().contains("Successfully reconnected to")) {
successfullyReconnected = true; successfullyReconnected = true;
}
} }
} };
}; appender.start();
}
@BeforeClass @BeforeClass
public static void setUp() throws Exception { public static void setUp() throws Exception {
org.apache.log4j.Logger.getRootLogger().addAppender(appender); org.apache.logging.log4j.core.Logger rootLogger = ((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger());
rootLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
rootLogger.addAppender(appender);
} }
@Before @Before
/** /**
* Sets a AbortSlowConsumerStrategy policy entry on the broker and starts the broker. * Sets a AbortSlowConsumerStrategy policy entry on the broker and starts the broker.
@ -133,7 +140,7 @@ public class AMQ5844Test {
broker.stop(); broker.stop();
broker.waitUntilStopped(); broker.waitUntilStopped();
} }
org.apache.log4j.Logger.getRootLogger().removeAppender(appender); ((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger()).removeAppender(appender);
} }
@Test @Test

View File

@ -46,7 +46,7 @@ import org.apache.activemq.util.Wait.Condition;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.TrueFileFilter; import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter; import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -61,7 +61,8 @@ public class AMQ6131Test {
@Before @Before
public void startBroker() throws Exception { public void startBroker() throws Exception {
org.apache.log4j.Logger.getLogger(MessageDatabase.class).setLevel(Level.TRACE); org.apache.logging.log4j.core.Logger logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MessageDatabase.class));
logger.setLevel(org.apache.logging.log4j.Level.TRACE);
setUpBroker(true); setUpBroker(true);
} }

View File

@ -48,7 +48,8 @@ import org.apache.activemq.store.kahadb.MessageDatabase;
import org.apache.commons.io.FileUtils; import org.apache.commons.io.FileUtils;
import org.apache.commons.io.filefilter.TrueFileFilter; import org.apache.commons.io.filefilter.TrueFileFilter;
import org.apache.commons.io.filefilter.WildcardFileFilter; import org.apache.commons.io.filefilter.WildcardFileFilter;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -96,8 +97,7 @@ public class AMQ6133PersistJMSRedeliveryTest {
public void setup() throws Exception { public void setup() throws Exception {
// Investigate loss of messages on message update in store. // Investigate loss of messages on message update in store.
org.apache.log4j.Logger.getLogger(MessageDatabase.class).setLevel(Level.TRACE); ((org.apache.logging.log4j.core.Logger)LogManager.getLogger(MessageDatabase.class)).setLevel(Level.TRACE);
createBroker(true); createBroker(true);
} }

View File

@ -22,11 +22,14 @@ import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter; import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.store.kahadb.MessageDatabase; import org.apache.activemq.store.kahadb.MessageDatabase;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -85,22 +88,26 @@ public class AMQ6432Test {
@Test @Test
public void testTransactedStoreUsageSuspendResume() throws Exception { public void testTransactedStoreUsageSuspendResume() throws Exception {
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(MessageDatabase.class);
final AtomicBoolean failed = new AtomicBoolean(false); final AtomicBoolean failed = new AtomicBoolean(false);
final File journalDataDir = ((KahaDBPersistenceAdapter) broker.getPersistenceAdapter()).getStore().getJournal().getDirectory(); final File journalDataDir = ((KahaDBPersistenceAdapter) broker.getPersistenceAdapter()).getStore().getJournal().getDirectory();
Appender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MessageDatabase.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().toString().startsWith("Failed to load next journal")) { if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().startsWith("Failed to load next journal")) {
LOG.info("received unexpected log message: " + event.getMessage()); LOG.info("received unexpected log message: " + event.getMessage().getFormattedMessage());
failed.set(true); failed.set(true);
} }
} }
}; };
log4jLogger.addAppender(appender); appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try { try {
ExecutorService sendExecutor = Executors.newSingleThreadExecutor(); ExecutorService sendExecutor = Executors.newSingleThreadExecutor();
@ -139,7 +146,7 @@ public class AMQ6432Test {
})); }));
} finally { } finally {
log4jLogger.removeAppender(appender); logger.removeAppender(appender);
} }
assertFalse("failed on unexpected log event", failed.get()); assertFalse("failed on unexpected log event", failed.get());

View File

@ -27,11 +27,16 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.broker.region.policy.VMPendingQueueMessageStoragePolicy; import org.apache.activemq.broker.region.policy.VMPendingQueueMessageStoragePolicy;
import org.apache.activemq.broker.region.policy.VMPendingSubscriberMessageStoragePolicy; import org.apache.activemq.broker.region.policy.VMPendingSubscriberMessageStoragePolicy;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.IOHelper; import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -48,7 +53,7 @@ public class AMQ6463Test extends JmsTestSupport {
ActiveMQQueue queueA = new ActiveMQQueue("QUEUE.A"); ActiveMQQueue queueA = new ActiveMQQueue("QUEUE.A");
protected TransportConnector connector; protected TransportConnector connector;
protected ActiveMQConnection connection; protected ActiveMQConnection connection;
protected DefaultTestAppender appender; protected Appender appender;
final AtomicInteger errors = new AtomicInteger(0); final AtomicInteger errors = new AtomicInteger(0);
final AtomicBoolean gotUsageBlocked = new AtomicBoolean(); final AtomicBoolean gotUsageBlocked = new AtomicBoolean();
@ -120,25 +125,28 @@ public class AMQ6463Test extends JmsTestSupport {
public void setUp() throws Exception { public void setUp() throws Exception {
setAutoFail(true); setAutoFail(true);
appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().equals(Level.ERROR)) { if (event.getLevel().equals(Level.ERROR)) {
errors.incrementAndGet(); errors.incrementAndGet();
} else if (event.getLevel().equals(Level.WARN) && event.getRenderedMessage().contains("Usage Manager Memory Limit")) { } else if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().contains("Usage Manager Memory Limit")) {
gotUsageBlocked.set(true); gotUsageBlocked.set(true);
} }
} }
}; };
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger(); appender.start();
rootLogger.addAppender(appender);
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
super.setUp(); super.setUp();
} }
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger(); org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).removeAppender(appender);
rootLogger.removeAppender(appender);
if (connection != null) { if (connection != null) {
connection.close(); connection.close();

View File

@ -21,6 +21,7 @@ import org.apache.activemq.ActiveMQXAConnection;
import org.apache.activemq.ActiveMQXAConnectionFactory; import org.apache.activemq.ActiveMQXAConnectionFactory;
import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnection;
import org.apache.activemq.broker.jmx.BrokerMBeanSupport; import org.apache.activemq.broker.jmx.BrokerMBeanSupport;
import org.apache.activemq.broker.jmx.BrokerViewMBean; import org.apache.activemq.broker.jmx.BrokerViewMBean;
import org.apache.activemq.broker.jmx.DestinationViewMBean; import org.apache.activemq.broker.jmx.DestinationViewMBean;
@ -34,7 +35,8 @@ import org.apache.activemq.store.kahadb.MessageDatabase;
import org.apache.activemq.util.JMXSupport; import org.apache.activemq.util.JMXSupport;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.commons.lang.StringUtils; import org.apache.commons.lang.StringUtils;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -166,8 +168,8 @@ public class AMQ7067Test {
public void testXAPrepareWithAckCompactionDoesNotLooseInflight() throws Exception { public void testXAPrepareWithAckCompactionDoesNotLooseInflight() throws Exception {
// investigate liner gc issue - store usage not getting released // investigate liner gc issue - store usage not getting released
org.apache.log4j.Logger.getLogger(MessageDatabase.class).setLevel(Level.TRACE); org.apache.logging.log4j.core.Logger logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MessageDatabase.class));
logger.setLevel(org.apache.logging.log4j.Level.TRACE);
setupXAConnection(); setupXAConnection();
@ -242,8 +244,7 @@ public class AMQ7067Test {
((KahaDBPersistenceAdapter)broker.getPersistenceAdapter()).setCompactAcksAfterNoGC(2); ((KahaDBPersistenceAdapter)broker.getPersistenceAdapter()).setCompactAcksAfterNoGC(2);
// investigate liner gc issue - store usage not getting released // investigate liner gc issue - store usage not getting released
org.apache.log4j.Logger.getLogger(MessageDatabase.class).setLevel(Level.TRACE); org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MessageDatabase.class)).setLevel(Level.TRACE);
setupXAConnection(); setupXAConnection();

View File

@ -34,11 +34,14 @@ import org.apache.activemq.store.kahadb.MultiKahaDBPersistenceAdapter;
import org.apache.activemq.store.kahadb.MultiKahaDBTransactionStore; import org.apache.activemq.store.kahadb.MultiKahaDBTransactionStore;
import org.apache.activemq.store.kahadb.disk.journal.Journal; import org.apache.activemq.store.kahadb.disk.journal.Journal;
import org.apache.activemq.util.ByteSequence; import org.apache.activemq.util.ByteSequence;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Test; import org.junit.Test;
import org.slf4j.Logger; import org.slf4j.Logger;
@ -280,20 +283,22 @@ public class MKahaDBTxRecoveryTest {
corruptTxStoreJournal(pathToDataDir); corruptTxStoreJournal(pathToDataDir);
// verify failure to load txStore via logging // verify failure to load txStore via logging
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(MultiKahaDBTransactionStore.class);
AtomicBoolean foundSomeCorruption = new AtomicBoolean(); AtomicBoolean foundSomeCorruption = new AtomicBoolean();
Appender appender = new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MultiKahaDBTransactionStore.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().equals(Level.ERROR) && event.getMessage().toString().startsWith("Corrupt ")) { if (Level.ERROR.equals(event.getLevel()) && event.getMessage().getFormattedMessage().startsWith("Corrupt ")) {
LOG.info("received expected log message: " + event.getMessage()); LOG.info("received expected log message: " + event.getMessage());
foundSomeCorruption.set(true); foundSomeCorruption.set(true);
} }
} }
}; };
log4jLogger.addAppender(appender); appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try { try {
prepareBrokerWithMultiStore(false); prepareBrokerWithMultiStore(false);
@ -367,7 +372,7 @@ public class MKahaDBTxRecoveryTest {
assertEquals(101, destination.getMessageStore().getMessageCount()); assertEquals(101, destination.getMessageStore().getMessageCount());
} finally { } finally {
log4jLogger.removeAppender(appender); logger.removeAppender(appender);
} }
} }
@ -401,24 +406,26 @@ public class MKahaDBTxRecoveryTest {
corruptTxStoreJournalAndTruncate(pathToDataDir); corruptTxStoreJournalAndTruncate(pathToDataDir);
// verify failure to load txStore via logging // verify failure to load txStore via logging
org.apache.log4j.Logger log4jLogger =
org.apache.log4j.Logger.getLogger(MultiKahaDBTransactionStore.class);
AtomicBoolean foundSomeCorruption = new AtomicBoolean(); AtomicBoolean foundSomeCorruption = new AtomicBoolean();
AtomicBoolean ignoringCorruption = new AtomicBoolean(); AtomicBoolean ignoringCorruption = new AtomicBoolean();
Appender appender = new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MultiKahaDBTransactionStore.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().equals(Level.ERROR) && event.getMessage().toString().startsWith("Corrupt ")) { if (Level.ERROR.equals(event.getLevel()) && event.getMessage().getFormattedMessage().startsWith("Corrupt ")) {
LOG.info("received expected log message: " + event.getMessage()); LOG.info("received expected log message: " + event.getMessage());
foundSomeCorruption.set(true); foundSomeCorruption.set(true);
} else if (event.getLevel().equals(Level.INFO) && event.getMessage().toString().contains("auto resolving")) { } else if (Level.INFO.equals(event.getLevel()) && event.getMessage().getFormattedMessage().contains("auto resolving")) {
ignoringCorruption.set(true); ignoringCorruption.set(true);
} }
} }
}; };
log4jLogger.addAppender(appender); appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try { try {
prepareBrokerWithMultiStore(false); prepareBrokerWithMultiStore(false);
@ -453,7 +460,7 @@ public class MKahaDBTxRecoveryTest {
broker.stop(); broker.stop();
} finally { } finally {
log4jLogger.removeAppender(appender); logger.removeAppender(appender);
} }
} }

View File

@ -38,7 +38,8 @@ import org.apache.activemq.TestSupport;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter; import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.store.kahadb.MessageDatabase; import org.apache.activemq.store.kahadb.MessageDatabase;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.junit.After; import org.junit.After;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Before; import org.junit.Before;
@ -108,7 +109,7 @@ public class TransactedStoreUsageSuspendResumeTest {
public void setup() throws Exception { public void setup() throws Exception {
// investigate liner gc issue - store usage not getting released // investigate liner gc issue - store usage not getting released
org.apache.log4j.Logger.getLogger(MessageDatabase.class).setLevel(Level.TRACE); org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MessageDatabase.class)).setLevel(Level.TRACE);
broker = new BrokerService(); broker = new BrokerService();
broker.setDeleteAllMessagesOnStartup(true); broker.setDeleteAllMessagesOnStartup(true);

View File

@ -41,7 +41,8 @@ import org.apache.activemq.store.jdbc.TransactionContext;
import org.apache.activemq.util.IOHelper; import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.LeaseLockerIOExceptionHandler; import org.apache.activemq.util.LeaseLockerIOExceptionHandler;
import org.apache.derby.jdbc.EmbeddedDataSource; import org.apache.derby.jdbc.EmbeddedDataSource;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -109,7 +110,7 @@ public class TrapMessageInJDBCStoreTest extends TestCase {
public void testDBCommitException() throws Exception { public void testDBCommitException() throws Exception {
org.apache.log4j.Logger serviceLogger = org.apache.log4j.Logger.getLogger(TransportConnection.class.getName() + ".Service"); org.apache.logging.log4j.core.Logger serviceLogger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(TransportConnection.class.getName() + ".Service"));
serviceLogger.setLevel (Level.TRACE); serviceLogger.setLevel (Level.TRACE);
broker = this.createBroker(false); broker = this.createBroker(false);

View File

@ -26,12 +26,13 @@ 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.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.log4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class EmbeddedActiveMQ public class EmbeddedActiveMQ
{ {
private static Logger logger = Logger.getLogger(EmbeddedActiveMQ.class); private static Logger logger = LoggerFactory.getLogger(EmbeddedActiveMQ.class);
public static void main(String[] args) public static void main(String[] args)
{ {

View File

@ -18,11 +18,13 @@ package org.apache.activemq.bugs.embedded;
import java.util.regex.Matcher; import java.util.regex.Matcher;
import java.util.regex.Pattern; import java.util.regex.Pattern;
import org.apache.log4j.Logger;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class ThreadExplorer public class ThreadExplorer
{ {
static Logger logger = Logger.getLogger(ThreadExplorer.class); static Logger logger = LoggerFactory.getLogger(ThreadExplorer.class);
public static Thread[] listThreads() public static Thread[] listThreads()
{ {

View File

@ -35,11 +35,14 @@ import org.apache.activemq.broker.jmx.BrokerMBeanSupport;
import org.apache.activemq.broker.jmx.ManagementContext; import org.apache.activemq.broker.jmx.ManagementContext;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Appender; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Level; import org.apache.logging.log4j.core.LogEvent;
import org.apache.log4j.Logger; import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.Test; import org.junit.Test;
import static org.apache.activemq.broker.util.JMXAuditLogEntry.VERBS; import static org.apache.activemq.broker.util.JMXAuditLogEntry.VERBS;
@ -119,31 +122,33 @@ public class JmxAuditLogTest extends TestSupport
@Test @Test
public void testPasswordsAreNotLoggedWhenAuditIsTurnedOn() throws Exception public void testPasswordsAreNotLoggedWhenAuditIsTurnedOn() throws Exception
{ {
Logger log4jLogger = Logger.getLogger("org.apache.activemq.audit"); final var log4jLogger = (org.apache.logging.log4j.core.Logger)LogManager.getLogger("org.apache.activemq.audit");
log4jLogger.setLevel(Level.INFO); Configurator.setLevel("org.apache.activemq.audit", Level.INFO);
final AtomicInteger logCount = new AtomicInteger(0); final AtomicInteger logCount = new AtomicInteger(0);
final AtomicBoolean gotEnded = new AtomicBoolean(false); final AtomicBoolean gotEnded = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() // start new
{ final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) public void append(LogEvent event) {
{ if (event.getMessage() != null)
if (event.getMessage() instanceof String) {
{ String message = event.getMessage().getFormattedMessage();
String message = (String) event.getMessage(); System.out.println(message);
System.out.println(message); if (message.contains("testPassword"))
if (message.contains("testPassword")) {
{ fail("Password should not appear in log file");
fail("Password should not appear in log file"); }
} if (message.contains(VERBS[1])) {
if (message.contains(VERBS[1])) { gotEnded.set(true);
gotEnded.set(true); }
} }
} logCount.incrementAndGet();
logCount.incrementAndGet(); }
}
}; };
appender.start();
log4jLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
log4jLogger.addAppender(appender); log4jLogger.addAppender(appender);
MBeanServerConnection conn = createJMXConnector(portToUse); MBeanServerConnection conn = createJMXConnector(portToUse);
@ -163,8 +168,6 @@ public class JmxAuditLogTest extends TestSupport
@Test @Test
public void testNameTargetVisible() throws Exception public void testNameTargetVisible() throws Exception
{ {
Logger log4jLogger = Logger.getLogger("org.apache.activemq.audit");
log4jLogger.setLevel(Level.INFO);
final AtomicInteger logCount = new AtomicInteger(0); final AtomicInteger logCount = new AtomicInteger(0);
final AtomicBoolean gotEnded = new AtomicBoolean(false); final AtomicBoolean gotEnded = new AtomicBoolean(false);
final AtomicBoolean gotQueueName = new AtomicBoolean(false); final AtomicBoolean gotQueueName = new AtomicBoolean(false);
@ -172,36 +175,41 @@ public class JmxAuditLogTest extends TestSupport
final AtomicBoolean gotConnectorName = new AtomicBoolean(false); final AtomicBoolean gotConnectorName = new AtomicBoolean(false);
final String queueName = queue.getQueueName(); final String queueName = queue.getQueueName();
Appender appender = new DefaultTestAppender()
{ // start new
@Override final var logger = (org.apache.logging.log4j.core.Logger)LogManager.getLogger("org.apache.activemq.audit");
public void doAppend(LoggingEvent event) Configurator.setLevel("org.apache.activemq.audit", Level.INFO);
{ final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
if (event.getMessage() instanceof String) @Override
{ public void append(LogEvent event) {
String message = (String) event.getMessage(); if (event.getMessage() != null)
System.out.println(message); {
if (message.contains(VERBS[0])) { String message = event.getMessage().getFormattedMessage();
if (message.contains(queueName)) { System.out.println(message);
gotQueueName.set(true); if (message.contains(VERBS[0])) {
} if (message.contains(queueName)) {
if (message.contains(broker.getBrokerName())) { gotQueueName.set(true);
gotBrokerName.set(true); }
} if (message.contains(broker.getBrokerName())) {
gotBrokerName.set(true);
}
if (message.contains("TCP")) { if (message.contains("TCP")) {
gotConnectorName.set(true); gotConnectorName.set(true);
} }
} }
if (message.contains(VERBS[1])) { if (message.contains(VERBS[1])) {
gotEnded.set(true); gotEnded.set(true);
} }
} }
logCount.incrementAndGet(); logCount.incrementAndGet();
} }
}; };
log4jLogger.addAppender(appender); appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
MBeanServerConnection conn = createJMXConnector(portToUse); MBeanServerConnection conn = createJMXConnector(portToUse);
ObjectName queueObjName = new ObjectName(broker.getBrokerObjectName() + ",destinationType=Queue,destinationName=" + queueName); ObjectName queueObjName = new ObjectName(broker.getBrokerObjectName() + ",destinationType=Queue,destinationName=" + queueName);
@ -226,7 +234,6 @@ public class JmxAuditLogTest extends TestSupport
assertEquals("got messages", 6, logCount.get()); assertEquals("got messages", 6, logCount.get());
assertTrue("got connectorName in called statement", gotConnectorName.get()); assertTrue("got connectorName in called statement", gotConnectorName.get());
log4jLogger.removeAppender(appender); logger.removeAppender(appender);
} }
} }

View File

@ -45,8 +45,9 @@ import org.apache.activemq.broker.jmx.QueueViewMBean;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.transport.stomp.StompConnection; import org.apache.activemq.transport.stomp.StompConnection;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -71,17 +72,17 @@ public class SecurityJMXTest extends TestCase {
final AtomicReference<Object> stackTrace = new AtomicReference<Object>(); final AtomicReference<Object> stackTrace = new AtomicReference<Object>();
final Appender appender = new DefaultTestAppender() { final Appender appender = new DefaultTestAppender() {
public void doAppend(LoggingEvent event) { @Override
String message = event.getMessage().toString(); public void append(LogEvent event) {
String message = event.getMessage().getFormattedMessage();
if (message.contains("Async error occurred")) { if (message.contains("Async error occurred")) {
gotExpected.set(true); gotExpected.set(true);
stackTrace.set(event.getThrowableInformation()); stackTrace.set(event.getThrown());
} }
} }
}; };
final org.apache.log4j.Logger toVerify = org.apache.log4j.Logger.getLogger(TransportConnection.class.getName() + ".Service"); org.apache.logging.log4j.core.Logger toVerify = (org.apache.logging.log4j.core.Logger)LogManager.getLogger(TransportConnection.class.getName() + ".Service");
toVerify.addAppender(appender); toVerify.addAppender(appender);
try { try {

View File

@ -27,14 +27,18 @@ import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.AtomicLong;
import org.apache.activemq.broker.LockableServiceSupport; import org.apache.activemq.broker.LockableServiceSupport;
import org.apache.activemq.broker.Locker; import org.apache.activemq.broker.Locker;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.IOHelper; import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.LockFile; import org.apache.activemq.util.LockFile;
import org.apache.activemq.util.ServiceStopper; import org.apache.activemq.util.ServiceStopper;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.log4j.Logger; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.Assert; import org.junit.Assert;
import org.junit.Rule; import org.junit.Rule;
import org.junit.Test; import org.junit.Test;
@ -86,16 +90,22 @@ public class SharedFileLockerTest {
private void internalLoop(long timewait) throws Exception { private void internalLoop(long timewait) throws Exception {
final AtomicInteger logCounts = new AtomicInteger(0); final AtomicInteger logCounts = new AtomicInteger(0);
DefaultTestAppender appender = new DefaultTestAppender() {
// start new
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel() == Level.INFO) { if (Level.INFO.equals(event.getLevel())) {
logCounts.incrementAndGet(); logCounts.incrementAndGet();
} }
} }
}; };
appender.start();
Logger.getRootLogger().addAppender(appender); Configurator.setRootLevel(Level.DEBUG);
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
final AtomicInteger errors = new AtomicInteger(0); final AtomicInteger errors = new AtomicInteger(0);
@ -163,8 +173,7 @@ public class SharedFileLockerTest {
} finally { } finally {
logger.removeAppender(appender);
Logger.getRootLogger().removeAppender(appender);
// to make sure we won't leak threads if the test ever failed for any reason // to make sure we won't leak threads if the test ever failed for any reason
thread.join(1000); thread.join(1000);
@ -182,14 +191,18 @@ public class SharedFileLockerTest {
public void verifyLockAcquireWaitsForLockDrop() throws Exception { public void verifyLockAcquireWaitsForLockDrop() throws Exception {
final AtomicInteger logCounts = new AtomicInteger(0); final AtomicInteger logCounts = new AtomicInteger(0);
DefaultTestAppender appender = new DefaultTestAppender() { // start new
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(SharedFileLocker.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
logCounts.incrementAndGet(); logCounts.incrementAndGet();
} }
}; };
Logger sharedFileLogger = Logger.getLogger(SharedFileLocker.class); appender.start();
sharedFileLogger.addAppender(appender);
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
LockableServiceSupport config = new LockableServiceSupport() { LockableServiceSupport config = new LockableServiceSupport() {
@ -261,7 +274,7 @@ public class SharedFileLockerTest {
executorService.shutdownNow(); executorService.shutdownNow();
underTest.stop(); underTest.stop();
lockFile.delete(); lockFile.delete();
sharedFileLogger.removeAppender(appender); logger.removeAppender(appender);
} }
} }
} }

View File

@ -23,9 +23,14 @@ import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.region.RegionBroker; import org.apache.activemq.broker.region.RegionBroker;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.DefaultIOExceptionHandler; import org.apache.activemq.util.DefaultIOExceptionHandler;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Appender; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Level; import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -61,22 +66,31 @@ public class JDBCConcurrentDLQTest {
broker.start(); broker.start();
broker.waitUntilStarted(); broker.waitUntilStarted();
appender = new DefaultTestAppender() { final var jdbcLogger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(JDBCPersistenceAdapter.class));
final var regionLogger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(RegionBroker.class));
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(org.apache.log4j.spi.LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().toInt() > Level.INFO_INT) { if (event.getLevel().isMoreSpecificThan(Level.INFO)) {
LOG.error("Got error from log:" + event.getRenderedMessage()); LOG.error("Got error from log:" + event.getMessage().getFormattedMessage());
gotError.set(true); gotError.set(true);
} }
} }
}; };
appender.start();
jdbcLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
jdbcLogger.addAppender(appender);
regionLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
regionLogger.addAppender(appender);
} }
@After @After
public void tearDown() throws Exception { public void tearDown() throws Exception {
org.apache.log4j.Logger.getLogger(RegionBroker.class).removeAppender(appender); ((org.apache.logging.log4j.core.Logger)LogManager.getLogger(RegionBroker.class)).removeAppender(appender);
org.apache.log4j.Logger.getLogger(JDBCPersistenceAdapter.class).removeAppender(appender); ((org.apache.logging.log4j.core.Logger)LogManager.getLogger(JDBCPersistenceAdapter.class)).removeAppender(appender);
broker.stop(); broker.stop();
} }
@ -108,8 +122,15 @@ public class JDBCConcurrentDLQTest {
gotError.set(true); gotError.set(true);
} }
}); });
org.apache.log4j.Logger.getLogger(RegionBroker.class).addAppender(appender);
org.apache.log4j.Logger.getLogger(JDBCPersistenceAdapter.class).addAppender(appender); final var loggerRB = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(RegionBroker.class));
final var loggerJDBC = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(JDBCPersistenceAdapter.class));
loggerRB.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
loggerRB.addAppender(appender);
loggerJDBC.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
loggerJDBC.addAppender(appender);
final int numMessages = 100; final int numMessages = 100;
final AtomicInteger consumed = new AtomicInteger(numMessages); final AtomicInteger consumed = new AtomicInteger(numMessages);

View File

@ -48,8 +48,13 @@ import org.apache.activemq.util.IOHelper;
import org.apache.activemq.util.LeaseLockerIOExceptionHandler; import org.apache.activemq.util.LeaseLockerIOExceptionHandler;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.derby.jdbc.EmbeddedDataSource; import org.apache.derby.jdbc.EmbeddedDataSource;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -124,25 +129,27 @@ public class JDBCIOExceptionHandlerTest {
final AtomicBoolean connectorStarted = new AtomicBoolean(false); final AtomicBoolean connectorStarted = new AtomicBoolean(false);
final AtomicBoolean connectorStopped = new AtomicBoolean(false); final AtomicBoolean connectorStopped = new AtomicBoolean(false);
DefaultTestAppender appender = new DefaultTestAppender() { // start new
final var rootLogger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getMessage().toString().startsWith("JMX consoles can connect to")) { if (event.getMessage().getFormattedMessage().startsWith("JMX consoles can connect to")) {
connectorStarted.set(true); connectorStarted.set(true);
} }
if (event.getMessage().toString().equals("Stopping jmx connector")) { if (event.getMessage().getFormattedMessage().equals("Stopping jmx connector")) {
connectorStopped.set(true); connectorStopped.set(true);
} }
} }
}; };
appender.start();
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger();
Level previousLevel = rootLogger.getLevel(); Level previousLevel = rootLogger.getLevel();
rootLogger.setLevel(Level.DEBUG); rootLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
rootLogger.addAppender(appender); rootLogger.addAppender(appender);
rootLogger.setLevel(Level.DEBUG);
// end new
BrokerService broker = new BrokerService(); BrokerService broker = new BrokerService();
broker.getManagementContext().setCreateConnector(true); broker.getManagementContext().setCreateConnector(true);

View File

@ -20,14 +20,15 @@ import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.store.PersistenceAdapter; import org.apache.activemq.store.PersistenceAdapter;
import org.apache.activemq.store.PersistenceAdapterTestSupport; import org.apache.activemq.store.PersistenceAdapterTestSupport;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.logging.log4j.core.Appender;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.logging.log4j.core.config.Configurator;
/** /**
* *
@ -53,19 +54,20 @@ public class KahaDBPersistenceAdapterTest extends PersistenceAdapterTestSupport
Appender appender = new DefaultTestAppender() { Appender appender = new DefaultTestAppender() {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
trappedLogMessages.set(true); trappedLogMessages.set(true);
if (event.getLevel().equals(Level.INFO)) { if (event.getLevel().equals(Level.INFO)) {
if (event.getMessage().toString().contains("Recovery replayed ")) { if (event.getMessage() != null && event.getMessage().getFormattedMessage().contains("Recovery replayed ")) {
gotSomeReplay.set(true); gotSomeReplay.set(true);
} }
} }
} }
}; };
appender.start();
try { try {
Logger.getLogger(MessageDatabase.class.getName()).addAppender(appender); Configurator.setLevel(MessageDatabase.class.getName(), Level.INFO);
Logger.getLogger(MessageDatabase.class.getName()).setLevel(Level.INFO); ((org.apache.logging.log4j.core.Logger)LogManager.getLogger(MessageDatabase.class)).addAppender(appender);
brokerService = new BrokerService(); brokerService = new BrokerService();
pa = createPersistenceAdapter(false); pa = createPersistenceAdapter(false);
@ -73,8 +75,9 @@ public class KahaDBPersistenceAdapterTest extends PersistenceAdapterTestSupport
brokerService.start(); brokerService.start();
} finally { } finally {
Logger.getRootLogger().removeAppender(appender); appender.stop();
Logger.getLogger(MessageDatabase.class.getName()).removeAppender(appender); ((org.apache.logging.log4j.core.Logger)LogManager.getRootLogger()).removeAppender(appender);
((org.apache.logging.log4j.core.Logger)LogManager.getLogger(MessageDatabase.class)).removeAppender(appender);
} }
assertTrue("log capture working", trappedLogMessages.get()); assertTrue("log capture working", trappedLogMessages.get());
assertFalse("no replay message in the log", gotSomeReplay.get()); assertFalse("no replay message in the log", gotSomeReplay.get());

View File

@ -32,10 +32,13 @@ import junit.framework.TestCase;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.logging.log4j.core.LogEvent;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
/** /**
* @author chirino * @author chirino
@ -209,16 +212,19 @@ public class KahaDBTest extends TestCase {
kaha.setCheckForCorruptJournalFiles(true); kaha.setCheckForCorruptJournalFiles(true);
final AtomicBoolean didSomeRecovery = new AtomicBoolean(false); final AtomicBoolean didSomeRecovery = new AtomicBoolean(false);
DefaultTestAppender appender = new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel() == Level.INFO && event.getRenderedMessage().contains("Recovering from the journal @")) { if (Level.INFO.equals(event.getLevel()) && event.getMessage().getFormattedMessage().contains("Recovering from the journal @")) {
didSomeRecovery.set(true); didSomeRecovery.set(true);
} }
} }
}; };
appender.start();
Logger.getRootLogger().addAppender(appender); logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
broker = createBroker(kaha); broker = createBroker(kaha);
@ -226,7 +232,7 @@ public class KahaDBTest extends TestCase {
assertEquals("Expected to received all messages.", count, 100); assertEquals("Expected to received all messages.", count, 100);
broker.stop(); broker.stop();
Logger.getRootLogger().removeAppender(appender); logger.removeAppender(appender);
assertFalse("Did not replay any records from the journal", didSomeRecovery.get()); assertFalse("Did not replay any records from the journal", didSomeRecovery.get());
} }

View File

@ -43,7 +43,8 @@ import org.apache.activemq.broker.region.Destination;
import org.apache.activemq.broker.region.Queue; import org.apache.activemq.broker.region.Queue;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.util.ServiceStopper; import org.apache.activemq.util.ServiceStopper;
import org.apache.log4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
/** /**
* TestCase showing the message-destroying described in AMQ-1925 * TestCase showing the message-destroying described in AMQ-1925
@ -51,7 +52,7 @@ import org.apache.log4j.Logger;
* *
*/ */
public class AMQ1925Test extends TestCase implements ExceptionListener { public class AMQ1925Test extends TestCase implements ExceptionListener {
private static final Logger log = Logger.getLogger(AMQ1925Test.class); private static final Logger log = LoggerFactory.getLogger(AMQ1925Test.class);
private static final String QUEUE_NAME = "test.amq1925"; private static final String QUEUE_NAME = "test.amq1925";
private static final String PROPERTY_MSG_NUMBER = "NUMBER"; private static final String PROPERTY_MSG_NUMBER = "NUMBER";

View File

@ -33,12 +33,13 @@ import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.network.NetworkConnector; import org.apache.activemq.network.NetworkConnector;
import org.apache.log4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
public class FailoverUpdateURIsTest extends TestCase { public class FailoverUpdateURIsTest extends TestCase {
private static final String QUEUE_NAME = "test.failoverupdateuris"; private static final String QUEUE_NAME = "test.failoverupdateuris";
private static final Logger LOG = Logger.getLogger(FailoverUpdateURIsTest.class); private static final Logger LOG = LoggerFactory.getLogger(FailoverUpdateURIsTest.class);
String firstTcpUri = "tcp://localhost:61616"; String firstTcpUri = "tcp://localhost:61616";
String secondTcpUri = "tcp://localhost:61626"; String secondTcpUri = "tcp://localhost:61626";
@ -64,10 +65,10 @@ public class FailoverUpdateURIsTest extends TestCase {
String targetDir = "target/" + getName(); String targetDir = "target/" + getName();
new File(targetDir).mkdir(); new File(targetDir).mkdir();
File updateFile = new File(targetDir + "/updateURIsFile.txt"); File updateFile = new File(targetDir + "/updateURIsFile.txt");
LOG.info(updateFile); LOG.info("updateFile:" + updateFile);
LOG.info(updateFile.toURI()); LOG.info("updateFileUri:" + updateFile.toURI());
LOG.info(updateFile.getAbsoluteFile()); LOG.info("updateFileAbsoluteFile:" + updateFile.getAbsoluteFile());
LOG.info(updateFile.getAbsoluteFile().toURI()); LOG.info("updateFileAbsoluteFileUri:" + updateFile.getAbsoluteFile().toURI());
FileOutputStream out = new FileOutputStream(updateFile); FileOutputStream out = new FileOutputStream(updateFile);
out.write(firstTcpUri.getBytes()); out.write(firstTcpUri.getBytes());
out.close(); out.close();

View File

@ -17,21 +17,23 @@
package org.apache.activemq.transport.nio; package org.apache.activemq.transport.nio;
import javax.jms.Connection; import javax.jms.Connection;
import javax.jms.JMSException;
import javax.jms.Message; import javax.jms.Message;
import javax.jms.MessageConsumer; import javax.jms.MessageConsumer;
import javax.jms.MessageProducer; import javax.jms.MessageProducer;
import javax.jms.Queue; import javax.jms.Queue;
import javax.jms.Session; import javax.jms.Session;
import javax.jms.TextMessage; import javax.jms.TextMessage;
import javax.net.ssl.SSLHandshakeException;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Level;
import org.apache.log4j.spi.LoggingEvent;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -114,21 +116,25 @@ public class NIOSSLBasicTest {
final CountDownLatch gotLogMessage = new CountDownLatch(1); final CountDownLatch gotLogMessage = new CountDownLatch(1);
final AtomicBoolean gotRemoteAddressInLog = new AtomicBoolean(); final AtomicBoolean gotRemoteAddressInLog = new AtomicBoolean();
final DefaultTestAppender appender = new DefaultTestAppender() { // start new
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getRenderedMessage().contains("Could not accept connection")) { if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().contains("Could not accept connection")) {
gotLogMessage.countDown(); gotLogMessage.countDown();
if (event.getRenderedMessage().contains("tcp")) { if (event.getMessage().getFormattedMessage().contains("tcp")) {
// got remote address // got remote address
gotRemoteAddressInLog.set(true); gotRemoteAddressInLog.set(true);
} }
} }
} }
}; };
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger(); appender.start();
rootLogger.addAppender(appender);
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
BrokerService broker = null; BrokerService broker = null;
try { try {
broker = createBroker("nio+ssl", getTransportType() + "://localhost:61616?transport.needClientAuth=true"); broker = createBroker("nio+ssl", getTransportType() + "://localhost:61616?transport.needClientAuth=true");
@ -138,7 +144,7 @@ public class NIOSSLBasicTest {
if (broker != null) { if (broker != null) {
stopBroker(broker); stopBroker(broker);
} }
rootLogger.removeAppender(appender); logger.removeAppender(appender);
assertTrue("Got remote address in log", gotRemoteAddressInLog.get()); assertTrue("Got remote address in log", gotRemoteAddressInLog.get());
} }
} }

View File

@ -19,11 +19,16 @@ package org.apache.activemq.transport.tcp;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnection; import org.apache.activemq.broker.TransportConnection;
import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.logging.log4j.core.Appender;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.Logger;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -32,7 +37,6 @@ import org.slf4j.LoggerFactory;
import javax.net.ssl.*; import javax.net.ssl.*;
import java.net.Socket; import java.net.Socket;
import java.net.URI; import java.net.URI;
import java.sql.Time;
import java.util.concurrent.CountDownLatch; import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit; import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
@ -48,9 +52,11 @@ public class TcpTransportCloseSocketNoWarnTest {
public static final String PASSWORD = "password"; public static final String PASSWORD = "password";
public static final String SERVER_KEYSTORE = "src/test/resources/server.keystore"; public static final String SERVER_KEYSTORE = "src/test/resources/server.keystore";
public static final String TRUST_KEYSTORE = "src/test/resources/client.keystore"; public static final String TRUST_KEYSTORE = "src/test/resources/client.keystore";
public static final Appender appender;
public static final AtomicBoolean gotExceptionInLog = new AtomicBoolean();
private BrokerService brokerService; private BrokerService brokerService;
private Logger rootLogger;
static { static {
System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE); System.setProperty("javax.net.ssl.trustStore", TRUST_KEYSTORE);
@ -59,20 +65,20 @@ public class TcpTransportCloseSocketNoWarnTest {
System.setProperty("javax.net.ssl.keyStore", SERVER_KEYSTORE); System.setProperty("javax.net.ssl.keyStore", SERVER_KEYSTORE);
System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD); System.setProperty("javax.net.ssl.keyStorePassword", PASSWORD);
System.setProperty("javax.net.ssl.keyStoreType", KEYSTORE_TYPE); System.setProperty("javax.net.ssl.keyStoreType", KEYSTORE_TYPE);
}
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
final AtomicBoolean gotExceptionInLog = new AtomicBoolean(); @Override
Appender appender = new DefaultTestAppender() { public void append(LogEvent event) {
@Override if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().contains("failed:")) {
public void doAppend(LoggingEvent event) { gotExceptionInLog.set(Boolean.TRUE);
if (event.getLevel().equals(Level.WARN) && event.getRenderedMessage().contains("failed:")) { LOG.error("got event: " + event + ", ex:" + event.getMessage().getFormattedMessage());
gotExceptionInLog.set(Boolean.TRUE); LOG.error("Event source: ", new Throwable("Here"));
LOG.error("got event: " + event + ", ex:" + event.getRenderedMessage()); }
LOG.error("Event source: ", new Throwable("Here")); return;
} }
return; };
} appender.start();
}; }
@Before @Before
public void before() throws Exception { public void before() throws Exception {
@ -80,8 +86,11 @@ public class TcpTransportCloseSocketNoWarnTest {
brokerService.setPersistent(false); brokerService.setPersistent(false);
brokerService.setUseJmx(false); brokerService.setUseJmx(false);
Logger.getRootLogger().addAppender(appender); rootLogger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
Logger.getLogger(TransportConnection.class.getName() + ".Transport").setLevel(Level.WARN); rootLogger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
rootLogger.addAppender(appender);
org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(TransportConnection.class.getName() + ".Transport")).setLevel(Level.WARN);
} }
@After @After
@ -90,7 +99,7 @@ public class TcpTransportCloseSocketNoWarnTest {
brokerService.stop(); brokerService.stop();
brokerService.waitUntilStopped(); brokerService.waitUntilStopped();
} }
Logger.getRootLogger().removeAppender(appender); rootLogger.removeAppender(appender);
} }
@Test(timeout = 60000) @Test(timeout = 60000)

View File

@ -18,10 +18,15 @@ package org.apache.activemq.transport.tcp;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -59,7 +64,7 @@ public class TcpTransportInactiveDuringHandshakeTest {
} }
private BrokerService brokerService; private BrokerService brokerService;
private DefaultTestAppender appender; private Appender appender;
CountDownLatch inactivityMonitorFired; CountDownLatch inactivityMonitorFired;
CountDownLatch handShakeComplete; CountDownLatch handShakeComplete;
@ -71,23 +76,24 @@ public class TcpTransportInactiveDuringHandshakeTest {
inactivityMonitorFired = new CountDownLatch(1); inactivityMonitorFired = new CountDownLatch(1);
handShakeComplete = new CountDownLatch(1); handShakeComplete = new CountDownLatch(1);
appender = new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getRenderedMessage().contains("InactivityIOException")) { if (Level.WARN.equals(event.getLevel()) && event.getMessage().getFormattedMessage().contains("InactivityIOException")) {
inactivityMonitorFired.countDown(); inactivityMonitorFired.countDown();
} }
} }
}; };
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger(); appender.start();
rootLogger.addAppender(appender);
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
} }
@After @After
public void after() throws Exception { public void after() throws Exception {
org.apache.log4j.Logger rootLogger = org.apache.log4j.Logger.getRootLogger(); org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).removeAppender(appender);;
rootLogger.removeAppender(appender);
if (brokerService != null) { if (brokerService != null) {
brokerService.stop(); brokerService.stop();

View File

@ -35,10 +35,14 @@ import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.network.DurableConduitBridge; import org.apache.activemq.network.DurableConduitBridge;
import org.apache.activemq.network.NetworkConnector; import org.apache.activemq.network.NetworkConnector;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Level; import org.apache.logging.log4j.Level;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.Ignore; import org.junit.Ignore;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -158,16 +162,20 @@ public class VmTransportNetworkBrokerTest extends TestCase {
vmConnection.close(); vmConnection.close();
final AtomicInteger logCounts = new AtomicInteger(0); final AtomicInteger logCounts = new AtomicInteger(0);
DefaultTestAppender appender = new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(DurableConduitBridge.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel() == Level.ERROR) { if (Level.ERROR.equals(event.getLevel())) {
logCounts.incrementAndGet(); logCounts.incrementAndGet();
} }
} }
}; };
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
org.apache.log4j.Logger.getLogger(DurableConduitBridge.class).addAppender(appender);
try { try {
NetworkConnector networkConnector = forwarder.addNetworkConnector("static:(" NetworkConnector networkConnector = forwarder.addNetworkConnector("static:("
@ -185,7 +193,7 @@ public class VmTransportNetworkBrokerTest extends TestCase {
assertEquals("no errors", 0, logCounts.get()); assertEquals("no errors", 0, logCounts.get());
} finally { } finally {
org.apache.log4j.Logger.getLogger(DurableConduitBridge.class).removeAppender(appender); logger.removeAppender(appender);
} }
} }

View File

@ -24,11 +24,13 @@ import org.apache.activemq.ConfigurationException;
import org.junit.Test; import org.junit.Test;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.logging.log4j.core.LogEvent;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import static org.junit.Assert.assertTrue; import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail; import static org.junit.Assert.fail;
@ -52,42 +54,50 @@ public class StoreUsageLimitsTest {
public void testCheckLimitsLogLevel() throws Exception { public void testCheckLimitsLogLevel() throws Exception {
final CountDownLatch foundMessage = new CountDownLatch(1); final CountDownLatch foundMessage = new CountDownLatch(1);
DefaultTestAppender appender = new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
String message = (String) event.getMessage(); String message = event.getMessage().getFormattedMessage();
if (message.contains(toMatch) && event.getLevel().equals(Level.WARN)) { if (message.contains(toMatch) && event.getLevel().equals(Level.WARN)) {
foundMessage.countDown(); foundMessage.countDown();
} }
} }
}; };
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
Logger.getRootLogger().addAppender(appender);
BrokerService brokerService = createBroker(); BrokerService brokerService = createBroker();
brokerService.start(); brokerService.start();
brokerService.stop(); brokerService.stop();
assertTrue("Fount log message", foundMessage.await(WAIT_TIME_MILLS, TimeUnit.MILLISECONDS)); assertTrue("Fount log message", foundMessage.await(WAIT_TIME_MILLS, TimeUnit.MILLISECONDS));
Logger.getRootLogger().removeAppender(appender); logger.removeAppender(appender);
} }
@Test @Test
public void testCheckLimitsFailStart() throws Exception { public void testCheckLimitsFailStart() throws Exception {
final CountDownLatch foundMessage = new CountDownLatch(1); final CountDownLatch foundMessage = new CountDownLatch(1);
DefaultTestAppender appender = new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
String message = (String) event.getMessage(); String message = event.getMessage().getFormattedMessage();
if (message.contains(toMatch) && event.getLevel().equals(Level.ERROR)) { if (message.contains(toMatch) && event.getLevel().equals(Level.ERROR)) {
foundMessage.countDown(); foundMessage.countDown();
} }
} }
}; };
appender.start();
Logger.getRootLogger().addAppender(appender); logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
BrokerService brokerService = createBroker(); logger.addAppender(appender);
BrokerService brokerService = createBroker();
brokerService.setAdjustUsageLimits(false); brokerService.setAdjustUsageLimits(false);
try { try {
brokerService.start(); brokerService.start();
@ -99,6 +109,6 @@ public class StoreUsageLimitsTest {
assertTrue("Fount log message", foundMessage.await(WAIT_TIME_MILLS, TimeUnit.MILLISECONDS)); assertTrue("Fount log message", foundMessage.await(WAIT_TIME_MILLS, TimeUnit.MILLISECONDS));
Logger.getRootLogger().removeAppender(appender); logger.removeAppender(appender);
} }
} }

View File

@ -19,12 +19,15 @@ package org.apache.activemq.usecases;
import org.apache.activemq.ActiveMQConnectionFactory; import org.apache.activemq.ActiveMQConnectionFactory;
import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerFactory;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Logger; import org.apache.logging.log4j.core.LogEvent;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Configurator;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Before;
import org.junit.Test; import org.junit.Test;
import javax.jms.Connection; import javax.jms.Connection;
@ -49,16 +52,19 @@ public class AMQ6446Test {
final HashSet<String> loggers = new HashSet<String>(); final HashSet<String> loggers = new HashSet<String>();
final HashSet<String> messages = new HashSet<String>(); final HashSet<String> messages = new HashSet<String>();
DefaultTestAppender appender = new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
loggers.add(event.getLoggerName()); loggers.add(event.getLoggerName());
messages.add(event.getRenderedMessage()); messages.add(event.getMessage().getFormattedMessage());
} }
}; };
appender.start();
Logger.getRootLogger().addAppender(appender); logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
Logger.getRootLogger().setLevel(Level.DEBUG); logger.addAppender(appender);
Configurator.setRootLevel(Level.DEBUG);
String brokerUrlWithTrace = brokerService.getTransportConnectorByScheme("tcp").getPublishableConnectString() + String brokerUrlWithTrace = brokerService.getTransportConnectorByScheme("tcp").getPublishableConnectString() +
urlTraceParam; urlTraceParam;
@ -70,7 +76,7 @@ public class AMQ6446Test {
connections.add(c); connections.add(c);
} }
Logger.getRootLogger().removeAppender(appender); logger.removeAppender(appender);
// no logger ends with :2 // no logger ends with :2
assertFalse(foundMatch(loggers, ".*:2$")); assertFalse(foundMatch(loggers, ".*:2$"));
@ -101,16 +107,19 @@ public class AMQ6446Test {
final HashSet<String> loggers = new HashSet<String>(); final HashSet<String> loggers = new HashSet<String>();
final HashSet<String> messages = new HashSet<String>(); final HashSet<String> messages = new HashSet<String>();
DefaultTestAppender appender = new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
loggers.add(event.getLoggerName()); loggers.add(event.getLoggerName());
messages.add(event.getRenderedMessage()); messages.add(event.getMessage().getFormattedMessage());
} }
}; };
appender.start();
Logger.getRootLogger().addAppender(appender); logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
Logger.getRootLogger().setLevel(Level.TRACE); logger.addAppender(appender);
Configurator.setRootLevel(Level.TRACE);
String brokerUrlWithTrace = brokerService.getTransportConnectorByScheme("tcp").getPublishableConnectString() + String brokerUrlWithTrace = brokerService.getTransportConnectorByScheme("tcp").getPublishableConnectString() +
legacySupportParam; legacySupportParam;
@ -122,7 +131,7 @@ public class AMQ6446Test {
connections.add(c); connections.add(c);
} }
Logger.getRootLogger().removeAppender(appender); logger.removeAppender(appender);
// logger ends with :2 // logger ends with :2
assertTrue(foundMatch(loggers, ".*:2$")); assertTrue(foundMatch(loggers, ".*:2$"));

View File

@ -30,11 +30,12 @@ import org.apache.activemq.JmsMultipleBrokersTestSupport;
import org.apache.activemq.broker.TransportConnection; import org.apache.activemq.broker.TransportConnection;
import org.apache.activemq.broker.TransportConnector; import org.apache.activemq.broker.TransportConnector;
import org.apache.activemq.command.ConnectionControl; import org.apache.activemq.command.ConnectionControl;
import org.apache.log4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.core.io.ClassPathResource; import org.springframework.core.io.ClassPathResource;
public class ClientRebalanceTest extends JmsMultipleBrokersTestSupport { public class ClientRebalanceTest extends JmsMultipleBrokersTestSupport {
private static final Logger LOG = Logger.getLogger(ClientRebalanceTest.class); private static final Logger LOG = LoggerFactory.getLogger(ClientRebalanceTest.class);
private static final String QUEUE_NAME = "Test.ClientRebalanceTest"; private static final String QUEUE_NAME = "Test.ClientRebalanceTest";
protected void setUp() throws Exception { protected void setUp() throws Exception {

View File

@ -23,10 +23,13 @@ import org.apache.activemq.broker.region.cursors.AbstractStoreCursor;
import org.apache.activemq.broker.region.policy.PolicyEntry; import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Appender; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.Level; import org.apache.logging.log4j.core.LogEvent;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.junit.After; import org.junit.After;
import org.junit.Before; import org.junit.Before;
import org.junit.Test; import org.junit.Test;
@ -99,24 +102,26 @@ public class DurableSubCacheTest {
publishMesssages(topic, 20); publishMesssages(topic, 20);
org.apache.log4j.Logger log4jLogger = org.apache.log4j.Logger.getLogger(AbstractStoreCursor.class.getCanonicalName());
final AtomicBoolean failed = new AtomicBoolean(false); final AtomicBoolean failed = new AtomicBoolean(false);
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(AbstractStoreCursor.class));
Appender appender = new DefaultTestAppender() { final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel() == Level.WARN) { if (Level.WARN.equals(event.getLevel())) {
LOG.info("Got warn event:" + event.getRenderedMessage()); LOG.info("Got warn event:" + event.getMessage().getFormattedMessage());
failed.set(true); failed.set(true);
} }
} }
}; };
log4jLogger.addAppender(appender); appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try { try {
consumeDurableSub(topic, "my_sub_1", 20, prefetch); consumeDurableSub(topic, "my_sub_1", 20, prefetch);
} finally { } finally {
log4jLogger.removeAppender(appender); logger.removeAppender(appender);
} }
assertFalse("no warning from the cursor", failed.get()); assertFalse("no warning from the cursor", failed.get());

View File

@ -22,9 +22,6 @@ import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter; import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.store.kahadb.MessageDatabase; import org.apache.activemq.store.kahadb.MessageDatabase;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.spi.LoggingEvent;
import org.junit.experimental.theories.Theories;
import javax.jms.Connection; import javax.jms.Connection;
import javax.jms.DeliveryMode; import javax.jms.DeliveryMode;
@ -34,6 +31,14 @@ import javax.jms.Session;
import javax.jms.TextMessage; import javax.jms.TextMessage;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import org.apache.logging.log4j.Level;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
public class EmptyTransactionTest extends TestCase { public class EmptyTransactionTest extends TestCase {
private static final int CHECKPOINT_INTERVAL = 500; private static final int CHECKPOINT_INTERVAL = 500;
@ -42,16 +47,20 @@ public class EmptyTransactionTest extends TestCase {
public void testEmptyTransactionsCheckpoint() throws Exception { public void testEmptyTransactionsCheckpoint() throws Exception {
AtomicBoolean hadRecovery = new AtomicBoolean(false); AtomicBoolean hadRecovery = new AtomicBoolean(false);
DefaultTestAppender appender = new DefaultTestAppender() {
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(MessageDatabase.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getMessage().toString().contains("Recovering from the journal @")) { if (event.getMessage().toString().contains("Recovering from the journal @")) {
hadRecovery.set(true); hadRecovery.set(true);
} }
} }
}; };
appender.start();
org.apache.log4j.Logger.getLogger(MessageDatabase.class).addAppender(appender); logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
start(true); start(true);

View File

@ -30,11 +30,14 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter; import org.apache.activemq.store.kahadb.KahaDBPersistenceAdapter;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -119,23 +122,25 @@ public class OfflineDurableSubscriberTimeoutTest extends org.apache.activemq.Tes
public void testOfflineDurableSubscriberTimeout() throws Exception { public void testOfflineDurableSubscriberTimeout() throws Exception {
final AtomicBoolean foundLogMessage = new AtomicBoolean(false); final AtomicBoolean foundLogMessage = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() { // start new
final var loggerMRB = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(ManagedRegionBroker.class));
final var loggerTopic = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(org.apache.activemq.broker.region.Topic.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().isGreaterOrEqual(Level.WARN)) { if (event.getLevel().isLessSpecificThan(Level.WARN)) {
LOG.info("received unexpected log message: " + event.getMessage()); LOG.info("received unexpected log message: " + event.getMessage());
foundLogMessage.set(true); foundLogMessage.set(true);
} }
} }
}; };
appender.start();
org.apache.log4j.Logger log4jLoggerMRB = loggerMRB.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
org.apache.log4j.Logger.getLogger(ManagedRegionBroker.class); loggerMRB.addAppender(appender);
org.apache.log4j.Logger log4jLoggerT =
org.apache.log4j.Logger.getLogger(org.apache.activemq.broker.region.Topic.class);
log4jLoggerMRB.addAppender(appender); loggerTopic.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
log4jLoggerT.addAppender(appender); loggerTopic.addAppender(appender);
try { try {
@ -199,8 +204,8 @@ public class OfflineDurableSubscriberTimeoutTest extends org.apache.activemq.Tes
assertFalse("have not found any log warn/error", foundLogMessage.get()); assertFalse("have not found any log warn/error", foundLogMessage.get());
} finally { } finally {
log4jLoggerMRB.removeAppender(appender); loggerMRB.removeAppender(appender);
log4jLoggerT.removeAppender(appender); loggerTopic.removeAppender(appender);
} }
} }

View File

@ -52,9 +52,13 @@ import org.apache.activemq.network.DemandForwardingBridgeSupport;
import org.apache.activemq.network.NetworkBridge; import org.apache.activemq.network.NetworkBridge;
import org.apache.activemq.network.NetworkConnector; import org.apache.activemq.network.NetworkConnector;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -85,7 +89,7 @@ public class RequestReplyTempDestRemovalAdvisoryRaceTest extends JmsMultipleBrok
protected final AtomicBoolean shutdown = new AtomicBoolean(false); protected final AtomicBoolean shutdown = new AtomicBoolean(false);
HashSet<NetworkConnector> networkConnectors = new HashSet<NetworkConnector>(); HashSet<NetworkConnector> networkConnectors = new HashSet<NetworkConnector>();
HashSet<Connection> advisoryConsumerConnections = new HashSet<Connection>(); HashSet<Connection> advisoryConsumerConnections = new HashSet<Connection>();
Appender slowDownAppender; AbstractAppender slowDownAppender;
CountDownLatch consumerDemandExists; CountDownLatch consumerDemandExists;
@ -263,15 +267,16 @@ public class RequestReplyTempDestRemovalAdvisoryRaceTest extends JmsMultipleBrok
private void slowDownAdvisoryDispatch() throws Exception { private void slowDownAdvisoryDispatch() throws Exception {
org.apache.log4j.Logger.getLogger(DemandForwardingBridgeSupport.class).setLevel(Level.DEBUG); org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(DemandForwardingBridgeSupport.class)).setLevel(Level.DEBUG);
// instrument a logger to block the processing of a remove sub advisory // instrument a logger to block the processing of a remove sub advisory
// simulate a slow thread // simulate a slow thread
slowDownAppender = new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger());
slowDownAppender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent loggingEvent) { public void append(LogEvent event) {
if (Level.DEBUG.equals(loggingEvent.getLevel())) { if (Level.DEBUG.equals(event.getLevel())) {
String message = loggingEvent.getMessage().toString(); String message = event.getMessage().getFormattedMessage();
if (message.startsWith("BrokerB") && message.contains("remove local subscription")) { if (message.startsWith("BrokerB") && message.contains("remove local subscription")) {
// sleep for a bit // sleep for a bit
try { try {
@ -285,8 +290,10 @@ public class RequestReplyTempDestRemovalAdvisoryRaceTest extends JmsMultipleBrok
} }
} }
}; };
slowDownAppender.start();
org.apache.log4j.Logger.getRootLogger().addAppender(slowDownAppender); logger.get().addAppender(slowDownAppender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(slowDownAppender);
} }
@Override @Override
@ -320,7 +327,7 @@ public class RequestReplyTempDestRemovalAdvisoryRaceTest extends JmsMultipleBrok
@Override @Override
protected void tearDown() throws Exception { protected void tearDown() throws Exception {
if (slowDownAppender != null) { if (slowDownAppender != null) {
org.apache.log4j.Logger.getRootLogger().removeAppender(slowDownAppender); org.apache.logging.log4j.core.Logger.class.cast(LogManager.getRootLogger()).removeAppender(slowDownAppender);
} }
for (Connection connection : advisoryConsumerConnections) { for (Connection connection : advisoryConsumerConnections) {
connection.close(); connection.close();

View File

@ -35,17 +35,19 @@ import org.apache.activemq.ActiveMQPrefetchPolicy;
import org.apache.activemq.advisory.AdvisorySupport; import org.apache.activemq.advisory.AdvisorySupport;
import org.apache.activemq.broker.BrokerService; import org.apache.activemq.broker.BrokerService;
import org.apache.activemq.broker.TransportConnection; import org.apache.activemq.broker.TransportConnection;
import org.apache.activemq.broker.region.RegionBroker;
import org.apache.activemq.broker.region.Topic; import org.apache.activemq.broker.region.Topic;
import org.apache.activemq.broker.region.policy.PolicyEntry; import org.apache.activemq.broker.region.policy.PolicyEntry;
import org.apache.activemq.broker.region.policy.PolicyMap; import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQDestination; import org.apache.activemq.command.ActiveMQDestination;
import org.apache.activemq.command.ActiveMQTopic; import org.apache.activemq.command.ActiveMQTopic;
import org.apache.activemq.util.DefaultTestAppender;
import org.apache.activemq.util.Wait; import org.apache.activemq.util.Wait;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
@ -141,18 +143,21 @@ public class TopicProducerFlowControlTest extends TestCase implements MessageLis
}); });
final AtomicInteger warnings = new AtomicInteger(); final AtomicInteger warnings = new AtomicInteger();
Appender appender = new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(Topic.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().toString().contains("Usage Manager memory limit reached")) { if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().contains("Usage Manager memory limit reached")) {
LOG.info("received log message: " + event.getMessage()); LOG.info("received log message: " + event.getMessage());
warnings.incrementAndGet(); warnings.incrementAndGet();
} }
} }
}; };
org.apache.log4j.Logger log4jLogger = appender.start();
org.apache.log4j.Logger.getLogger(Topic.class);
log4jLogger.addAppender(appender); logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try { try {
// Start producing the test messages // Start producing the test messages
@ -204,7 +209,7 @@ public class TopicProducerFlowControlTest extends TestCase implements MessageLis
assertTrue("warning limited", warnings.get() < blockedCounter.get()); assertTrue("warning limited", warnings.get() < blockedCounter.get());
} finally { } finally {
log4jLogger.removeAppender(appender); logger.removeAppender(appender);
} }
} }
@ -234,20 +239,22 @@ public class TopicProducerFlowControlTest extends TestCase implements MessageLis
Session listenerSession = c.createSession(false, 1); Session listenerSession = c.createSession(false, 1);
Destination destination = createDestination(listenerSession); Destination destination = createDestination(listenerSession);
final AtomicInteger warnings = new AtomicInteger(); final AtomicInteger warnings = new AtomicInteger();
Appender appender = new DefaultTestAppender() { final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(Topic.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel().equals(Level.WARN) && event.getMessage().toString().contains("Usage Manager memory limit reached")) { if (event.getLevel().equals(Level.WARN) && event.getMessage().getFormattedMessage().contains("Usage Manager memory limit reached")) {
LOG.info("received log message: " + event.getMessage()); LOG.info("received log message: " + event.getMessage());
warnings.incrementAndGet(); warnings.incrementAndGet();
} }
} }
}; };
org.apache.log4j.Logger log4jLogger = appender.start();
org.apache.log4j.Logger.getLogger(Topic.class);
log4jLogger.addAppender(appender); logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try { try {
// Start producing the test messages // Start producing the test messages
@ -319,7 +326,7 @@ public class TopicProducerFlowControlTest extends TestCase implements MessageLis
assertEquals("nothing sent during close", enqueueCountWhenBlocked, broker.getDestination(ActiveMQDestination.transform(destination)).getDestinationStatistics().getEnqueues().getCount()); assertEquals("nothing sent during close", enqueueCountWhenBlocked, broker.getDestination(ActiveMQDestination.transform(destination)).getDestinationStatistics().getEnqueues().getCount());
} }
} finally { } finally {
log4jLogger.removeAppender(appender); logger.removeAppender(appender);
} }
} }

View File

@ -26,10 +26,13 @@ import org.apache.activemq.broker.region.policy.PolicyMap;
import org.apache.activemq.command.ActiveMQQueue; import org.apache.activemq.command.ActiveMQQueue;
import org.apache.activemq.usage.SystemUsage; import org.apache.activemq.usage.SystemUsage;
import org.apache.activemq.util.DefaultTestAppender; import org.apache.activemq.util.DefaultTestAppender;
import org.apache.log4j.Appender; import org.apache.logging.log4j.Level;
import org.apache.log4j.Level; import org.apache.logging.log4j.LogManager;
import org.apache.log4j.spi.LoggingEvent; import org.apache.logging.log4j.core.LogEvent;
import org.apache.logging.log4j.core.appender.AbstractAppender;
import org.apache.logging.log4j.core.config.Property;
import org.apache.logging.log4j.core.filter.AbstractFilter;
import org.apache.logging.log4j.core.layout.MessageLayout;
import javax.jms.*; import javax.jms.*;
import java.io.File; import java.io.File;
import java.io.IOException; import java.io.IOException;
@ -134,18 +137,22 @@ public class UsageBlockedDispatchTest extends TestSupport {
consumer.receive(messageReceiveTimeout); consumer.receive(messageReceiveTimeout);
final AtomicBoolean gotExpectedLogEvent = new AtomicBoolean(false); final AtomicBoolean gotExpectedLogEvent = new AtomicBoolean(false);
Appender appender = new DefaultTestAppender() { // start new
final var logger = org.apache.logging.log4j.core.Logger.class.cast(LogManager.getLogger(Queue.class));
final var appender = new AbstractAppender("testAppender", new AbstractFilter() {}, new MessageLayout(), false, new Property[0]) {
@Override @Override
public void doAppend(LoggingEvent event) { public void append(LogEvent event) {
if (event.getLevel() == Level.WARN && event.getRenderedMessage().contains("cursor blocked")) { if (Level.WARN.equals(event.getLevel()) && event.getMessage().getFormattedMessage().contains("cursor blocked")) {
gotExpectedLogEvent.set(true); gotExpectedLogEvent.set(true);
} }
} }
}; };
appender.start();
logger.get().addAppender(appender, Level.DEBUG, new AbstractFilter() {});
logger.addAppender(appender);
try { try {
org.apache.log4j.Logger.getLogger(Queue.class).addAppender(appender);
MessageConsumer noDispatchConsumer = consumerSession.createConsumer(shouldBeStuckForDispatch); MessageConsumer noDispatchConsumer = consumerSession.createConsumer(shouldBeStuckForDispatch);
@ -154,8 +161,7 @@ public class UsageBlockedDispatchTest extends TestSupport {
assertTrue("Got the new warning about the blocked cursor", gotExpectedLogEvent.get()); assertTrue("Got the new warning about the blocked cursor", gotExpectedLogEvent.get());
} finally { } finally {
org.apache.log4j.Logger.getLogger(Queue.class).removeAppender(appender); logger.removeAppender(appender);
org.apache.log4j.Logger.getRootLogger().removeAppender(appender);
} }
} }
} }

View File

@ -1,47 +0,0 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
#
# The logging properties used during tests..
#
log4j.rootLogger=INFO, out, stdout
#log4j.logger.org.apache.activemq.broker.scheduler=DEBUG
#log4j.logger.org.apache.activemq.store.kahadb.scheduler=DEBUG
#log4j.logger.org.apache.activemq.network.DemandForwardingBridgeSupport=DEBUG
#log4j.logger.org.apache.activemq.transport.failover=TRACE
#log4j.logger.org.apache.activemq.transport.TransportLogger.Connection=TRACE
#log4j.logger.org.apache.activemq.store.jdbc=TRACE
#log4j.logger.org.apache.activemq.store.kahadb=TRACE
#log4j.logger.org.apache.activemq.broker.region.cursors.AbstractStoreCursor=DEBUG
#log4j.logger.org.apache.activemq.store.jdbc.JDBCMessageStore=DEBUG
#log4j.logger.org.apache.activemq.store.kahadb.disk.journal=DEBUG
#log4j.logger.org.apache.activemq.store.kahadb.AbstractKahaDBStore=DEBUG
# CONSOLE appender not used by default
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n
#log4j.appender.stdout.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %-10.10X{activemq.broker} %-20.20X{activemq.connector} %-10.10X{activemq.destination} - %m%n
# File appender
log4j.appender.out=org.apache.log4j.FileAppender
log4j.appender.out.layout=org.apache.log4j.PatternLayout
log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n
#log4j.appender.out.layout.ConversionPattern=%d [%-15.15t] - %-5p %-30.30c{1} - %-10.10X{activemq.broker} %-20.20X{activemq.connector} %-10.10X{activemq.destination} - %m%n
log4j.appender.out.file=target/activemq-test.log
log4j.appender.out.append=true

View File

@ -0,0 +1,55 @@
## ---------------------------------------------------------------------------
## Licensed to the Apache Software Foundation (ASF) under one or more
## contributor license agreements. See the NOTICE file distributed with
## this work for additional information regarding copyright ownership.
## The ASF licenses this file to You under the Apache License, Version 2.0
## (the "License"); you may not use this file except in compliance with
## the License. You may obtain a copy of the License at
##
## http://www.apache.org/licenses/LICENSE-2.0
##
## Unless required by applicable law or agreed to in writing, software
## distributed under the License is distributed on an "AS IS" BASIS,
## WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
## See the License for the specific language governing permissions and
## limitations under the License.
## ---------------------------------------------------------------------------
#
# The logging properties used during tests
#
rootLogger.level=INFO
rootLogger.appenderRef.console.ref=Console
rootLogger.appenderRef.logfile.ref=RollingFile
#logger.scheduler.name=org.apache.activemq.broker.scheduler
#logger.scheduler.level=DEBUG
#logger.network.name=org.apache.activemq.network.DemandForwardingBridgeSupport
#logger.network.level=DEBUG
#logger.failover.name=org.apache.activemq.transport.failover
#logger.failover.level=TRACE
#logger.jdbc.name=org.apache.activemq.store.jdbc
#logger.jdbc.level=TRACE
#logger.cursors.name=org.apache.activemq.broker.region.cursors.AbstractStoreCursor
#logger.cursors.level=DEBUG
# Console appender
appender.console.type=Console
appender.console.name=Console
appender.console.layout.type=PatternLayout
appender.console.layout.pattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n
#appender.console.layout.pattern=%d [%-15.15t] - %-5p %-30.30c{1} - %-10.10X{activemq.broker} %-20.20X{activemq.connector} %-10.10X{activemq.destination} - %m%n
# RollingFile appender
appender.logfile.type=RollingRandomAccessFile
appender.logfile.name=RollingFile
appender.logfile.fileName=target/activemq-test.log
appender.logfile.filePattern=target/activemq-test.log.%i
appender.logfile.append=true
appender.logfile.layout.type=PatternLayout
appender.logfile.layout.pattern=%d [%-15.15t] - %-5p %-30.30c{1} - %m%n
#appender.logfile.layout.pattern=%d [%-15.15t] - %-5p %-30.30c{1} - %-10.10X{activemq.broker} %-20.20X{activemq.connector} %-10.10X{activemq.destination} - %m%n
appender.logfile.policies.type=Policies
appender.logfile.policies.size.type=SizeBasedTriggeringPolicy
appender.logfile.policies.size.size=1MB