INT-4376: Upgage to Log4J 2 (#2321)

* INT-4376: Upgage to Log4J 2

JIRA: https://jira.spring.io/browse/INT-4376

* Deprecate Log4J 1.x components in favor of newly added
a `Log4j2LevelAdjuster` JUnit `@Rule`
* Update all the logging configuration to Log4J 2

* Polishing after testing
This commit is contained in:
Artem Bilan
2018-01-11 10:59:55 -05:00
committed by Gary Russell
parent 422f651113
commit 30450c48be
97 changed files with 981 additions and 539 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -51,7 +51,10 @@ import java.util.concurrent.atomic.AtomicReference;
import javax.net.ServerSocketFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.ClassRule;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
@@ -70,7 +73,7 @@ import org.springframework.integration.ip.tcp.connection.TcpConnectionSupport;
import org.springframework.integration.ip.tcp.connection.TcpNetClientConnectionFactory;
import org.springframework.integration.ip.tcp.connection.TcpNioClientConnectionFactory;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.support.LogAdjustingTestSupport;
import org.springframework.integration.test.rule.Log4j2LevelAdjuster;
import org.springframework.integration.test.support.LongRunningIntegrationTest;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
@@ -80,13 +83,20 @@ import org.springframework.messaging.support.GenericMessage;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 2.0
*/
public class TcpOutboundGatewayTests extends LogAdjustingTestSupport {
public class TcpOutboundGatewayTests {
private static final Log logger = LogFactory.getLog(TcpOutboundGatewayTests.class);
@ClassRule
public static LongRunningIntegrationTest longTests = new LongRunningIntegrationTest();
@Rule
public Log4j2LevelAdjuster adjuster = Log4j2LevelAdjuster.trace();
@Test
public void testGoodNetSingle() throws Exception {
final CountDownLatch latch = new CountDownLatch(1);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -44,6 +44,7 @@ import java.util.concurrent.TimeUnit;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.ArgumentCaptor;
@@ -56,7 +57,7 @@ import org.springframework.integration.context.IntegrationContextUtils;
import org.springframework.integration.ip.config.TcpConnectionFactoryFactoryBean;
import org.springframework.integration.ip.event.IpIntegrationEvent;
import org.springframework.integration.ip.tcp.TcpReceivingChannelAdapter;
import org.springframework.integration.test.support.LogAdjustingTestSupport;
import org.springframework.integration.test.rule.Log4j2LevelAdjuster;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.scheduling.TaskScheduler;
import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
@@ -64,10 +65,14 @@ import org.springframework.scheduling.concurrent.ThreadPoolTaskScheduler;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 3.0
*
*/
public class ConnectionFactoryTests extends LogAdjustingTestSupport {
public class ConnectionFactoryTests {
@Rule
public Log4j2LevelAdjuster adjuster = Log4j2LevelAdjuster.trace();
@Test
public void factoryBeanTests() {

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2016 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -41,7 +41,6 @@ import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicReference;
import org.apache.log4j.Level;
import org.junit.Rule;
import org.junit.Test;
import org.mockito.Mockito;
@@ -56,7 +55,7 @@ import org.springframework.integration.ip.IpHeaders;
import org.springframework.integration.ip.tcp.TcpInboundGateway;
import org.springframework.integration.ip.tcp.TcpOutboundGateway;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.test.rule.Log4jLevelAdjuster;
import org.springframework.integration.test.rule.Log4j2LevelAdjuster;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.util.SimplePool;
import org.springframework.messaging.Message;
@@ -66,6 +65,8 @@ import org.springframework.messaging.support.GenericMessage;
/**
* @author Gary Russell
* @author Artem Bilan
*
* @since 2.2
*
*/
@@ -85,8 +86,10 @@ public class FailoverClientConnectionFactoryTests {
};
@Rule
public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE,
"org.springframework.integration.ip.tcp", "org.springframework.integration.util.SimplePool");
public Log4j2LevelAdjuster adjuster =
Log4j2LevelAdjuster.trace()
.classes(SimplePool.class)
.categories("org.springframework.integration.ip.tcp");
@Test
public void testFailoverGood() throws Exception {
@@ -227,7 +230,8 @@ public class FailoverClientConnectionFactoryTests {
failoverFactory.getConnection().send(message);
fail("ExpectedFailure");
}
catch (IOException e) { }
catch (IOException e) {
}
failoverFactory.getConnection().send(message);
Mockito.verify(conn2).send(message);
Mockito.verify(conn1, times(3)).send(message);
@@ -572,7 +576,7 @@ public class FailoverClientConnectionFactoryTests {
gateway2.start();
TestingUtilities.waitListening(server1, null);
TestingUtilities.waitListening(server2, null);
Holder holder = new Holder();
Holder holder = new Holder();
holder.exec = exec;
holder.connectionId = connectionId;
holder.server1 = server1;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -64,7 +64,6 @@ import javax.net.SocketFactory;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.junit.Rule;
import org.junit.Test;
import org.junit.rules.TestName;
@@ -81,7 +80,7 @@ import org.springframework.integration.ip.tcp.serializer.MapJsonSerializer;
import org.springframework.integration.ip.util.TestingUtilities;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.support.converter.MapMessageConverter;
import org.springframework.integration.test.rule.Log4jLevelAdjuster;
import org.springframework.integration.test.rule.Log4j2LevelAdjuster;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.integration.util.CompositeExecutor;
import org.springframework.messaging.Message;
@@ -93,6 +92,8 @@ import org.springframework.util.ReflectionUtils;
/**
* @author Gary Russell
* @author John Anderson
* @author Artem Bilan
*
* @since 2.0
*
*/
@@ -101,8 +102,9 @@ public class TcpNioConnectionTests {
private final static Log logger = LogFactory.getLog(TcpNioConnectionTests.class);
@Rule
public final Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.TRACE,
"org.springframework.integration.ip.tcp");
public Log4j2LevelAdjuster adjuster =
Log4j2LevelAdjuster.trace()
.categories("org.springframework.integration.ip.tcp");
@Rule
public TestName testName = new TestName();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2017 the original author or authors.
* Copyright 2002-2018 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@@ -31,20 +31,19 @@ import java.util.concurrent.Executors;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.LogFactory;
import org.apache.log4j.Level;
import org.junit.Rule;
import org.junit.Test;
import org.springframework.beans.factory.BeanFactory;
import org.springframework.integration.ip.IpHeaders;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.rule.Log4jLevelAdjuster;
import org.springframework.messaging.Message;
/**
* @author Mark Fisher
* @author Gary Russell
* @author Artem Bilan
*
* @since 2.0
*/
public class DatagramPacketMulticastSendingHandlerTests {
@@ -52,9 +51,6 @@ public class DatagramPacketMulticastSendingHandlerTests {
@Rule
public MulticastRule multicastRule = new MulticastRule();
@Rule
public Log4jLevelAdjuster adjuster = new Log4jLevelAdjuster(Level.DEBUG, "org.springframework.integration");
@Test
public void verifySendMulticast() throws Exception {
MulticastSocket socket;
@@ -78,8 +74,6 @@ public class DatagramPacketMulticastSendingHandlerTests {
InetAddress group = InetAddress.getByName(multicastAddress);
socket1.joinGroup(group);
listening.countDown();
LogFactory.getLog(getClass())
.debug(Thread.currentThread().getName() + " waiting for packet");
socket1.receive(receivedPacket);
socket1.close();
byte[] src = receivedPacket.getData();
@@ -88,8 +82,6 @@ public class DatagramPacketMulticastSendingHandlerTests {
byte[] dest = new byte[length];
System.arraycopy(src, offset, dest, 0, length);
assertEquals(payload, new String(dest));
LogFactory.getLog(getClass())
.debug(Thread.currentThread().getName() + " received packet");
received.countDown();
}
catch (Exception e) {
@@ -140,7 +132,6 @@ public class DatagramPacketMulticastSendingHandlerTests {
socket1.joinGroup(group);
listening.countDown();
assertTrue(ackListening.await(10, TimeUnit.SECONDS));
LogFactory.getLog(getClass()).debug(Thread.currentThread().getName() + " waiting for packet");
socket1.receive(receivedPacket);
socket1.close();
byte[] src = receivedPacket.getData();
@@ -149,7 +140,6 @@ public class DatagramPacketMulticastSendingHandlerTests {
byte[] dest = new byte[6];
System.arraycopy(src, offset + length - 6, dest, 0, 6);
assertEquals(payload, new String(dest));
LogFactory.getLog(getClass()).debug(Thread.currentThread().getName() + " received packet");
DatagramPacketMessageMapper mapper = new DatagramPacketMessageMapper();
mapper.setAcknowledge(true);
mapper.setLengthCheck(true);
@@ -157,11 +147,9 @@ public class DatagramPacketMulticastSendingHandlerTests {
Object id = message.getHeaders().get(IpHeaders.ACK_ID);
byte[] ack = id.toString().getBytes();
DatagramPacket ackPack = new DatagramPacket(ack, ack.length,
new InetSocketAddress(multicastRule.getNic(), ackPort.get()));
new InetSocketAddress(multicastRule.getNic(), ackPort.get()));
DatagramSocket out = new DatagramSocket();
out.send(ackPack);
LogFactory.getLog(getClass()).debug(Thread.currentThread().getName() + " sent ack to "
+ ackPack.getSocketAddress());
out.close();
ackSent.countDown();
socket1.close();
@@ -176,7 +164,7 @@ public class DatagramPacketMulticastSendingHandlerTests {
executor.execute(catcher);
assertTrue(listening.await(10000, TimeUnit.MILLISECONDS));
MulticastSendingMessageHandler handler =
new MulticastSendingMessageHandler(multicastAddress, testPort, true, true, "localhost", 0, 10000);
new MulticastSendingMessageHandler(multicastAddress, testPort, true, true, "localhost", 0, 10000);
handler.setLocalAddress(this.multicastRule.getNic());
handler.setMinAcksForSuccess(2);
handler.setBeanFactory(mock(BeanFactory.class));

View File

@@ -1,7 +0,0 @@
log4j.rootCategory=WARN, stdout
log4j.appender.stdout=org.apache.log4j.ConsoleAppender
log4j.appender.stdout.layout=org.apache.log4j.PatternLayout
log4j.appender.stdout.layout.ConversionPattern=%d %5p %c{1} [%t] : %m%n
log4j.category.org.springframework.integration=WARN

View File

@@ -0,0 +1,15 @@
<?xml version="1.0" encoding="UTF-8"?>
<Configuration status="WARN">
<Appenders>
<Console name="STDOUT" target="SYSTEM_OUT">
<PatternLayout pattern="%d %p [%t] [%c] - %m%n" />
</Console>
</Appenders>
<Loggers>
<Logger name="org.springframework.integration" level="warn"/>
<Logger name="org.springframework.integration.ip" level="warn"/>
<Root level="warn">
<AppenderRef ref="STDOUT" />
</Root>
</Loggers>
</Configuration>