From 79745c8b08f74c40c04d136aef12147d047a13e8 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Tue, 10 Nov 2015 12:37:49 -0500 Subject: [PATCH] Add Debug for Amqp Channel Tests --- .../amqp/channel/ChannelTests.java | 7 ++++- .../test/util/LogAdjustingTestSupport.java | 30 +++++++++++++++---- .../test/support/LogAdjustingTestSupport.java | 30 +++++++++++++++---- 3 files changed, 56 insertions(+), 11 deletions(-) diff --git a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.java b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.java index 9d01c5e8f3..3658f3f076 100644 --- a/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.java +++ b/spring-integration-amqp/src/test/java/org/springframework/integration/amqp/channel/ChannelTests.java @@ -39,6 +39,7 @@ import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.annotation.Autowired; import org.springframework.integration.amqp.config.AmqpChannelFactoryBean; import org.springframework.integration.amqp.rule.BrokerRunning; +import org.springframework.integration.test.support.LogAdjustingTestSupport; import org.springframework.integration.test.util.TestUtils; import org.springframework.messaging.Message; import org.springframework.messaging.MessageHandler; @@ -58,7 +59,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; @ContextConfiguration @RunWith(SpringJUnit4ClassRunner.class) @DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD) -public class ChannelTests { +public class ChannelTests extends LogAdjustingTestSupport { @ClassRule public static final BrokerRunning brokerIsRunning = BrokerRunning.isRunning(); @@ -69,6 +70,10 @@ public class ChannelTests { @Autowired private CachingConnectionFactory factory; + public ChannelTests() { + super("org.springframework.integration", "org.springframework.integration.amqp", "org.springframework.amqp"); + } + @Test public void pubSubLostConnectionTest() throws Exception { final CyclicBarrier latch = new CyclicBarrier(2); diff --git a/spring-integration-core/src/test/java/org/springframework/integration/test/util/LogAdjustingTestSupport.java b/spring-integration-core/src/test/java/org/springframework/integration/test/util/LogAdjustingTestSupport.java index 9a7641e2b2..e5bca80d9d 100644 --- a/spring-integration-core/src/test/java/org/springframework/integration/test/util/LogAdjustingTestSupport.java +++ b/spring-integration-core/src/test/java/org/springframework/integration/test/util/LogAdjustingTestSupport.java @@ -15,6 +15,10 @@ */ package org.springframework.integration.test.util; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.Level; @@ -41,21 +45,37 @@ public class LogAdjustingTestSupport { protected final Log logger = LogFactory.getLog(this.getClass()); - private final Logger loggerToAdjust = LogManager.getLogger("org.springframework.integration"); + private final Collection loggersToAdjust = new ArrayList(); - private Level oldCategory; + private final Collection oldCategories = new ArrayList(); + + + public LogAdjustingTestSupport() { + this("org.springframework.integration"); + } + + public LogAdjustingTestSupport(String... loggersToAdjust) { + for (String loggerToAdjust : loggersToAdjust) { + this.loggersToAdjust.add(LogManager.getLogger(loggerToAdjust)); + } + } @Before public void beforeTest() { - this.oldCategory = loggerToAdjust.getEffectiveLevel(); - this.loggerToAdjust.setLevel(Level.TRACE); + for (Logger loggerToAdjust : this.loggersToAdjust) { + this.oldCategories.add(loggerToAdjust.getEffectiveLevel()); + loggerToAdjust.setLevel(Level.TRACE); + } this.logger.debug("!!!! Starting test: " + this.testName.getMethodName() + " !!!!"); } @After public void afterTest() { logger.debug("!!!! Finished test: " + this.testName.getMethodName() + " !!!!"); - this.loggerToAdjust.setLevel(this.oldCategory); + Iterator oldCategory = this.oldCategories.iterator(); + for (Logger loggerToAdjust : this.loggersToAdjust) { + loggerToAdjust.setLevel(oldCategory.next()); + } } } diff --git a/spring-integration-test/src/main/java/org/springframework/integration/test/support/LogAdjustingTestSupport.java b/spring-integration-test/src/main/java/org/springframework/integration/test/support/LogAdjustingTestSupport.java index 1735667caa..f86d88af4b 100644 --- a/spring-integration-test/src/main/java/org/springframework/integration/test/support/LogAdjustingTestSupport.java +++ b/spring-integration-test/src/main/java/org/springframework/integration/test/support/LogAdjustingTestSupport.java @@ -15,6 +15,10 @@ */ package org.springframework.integration.test.support; +import java.util.ArrayList; +import java.util.Collection; +import java.util.Iterator; + import org.apache.commons.logging.Log; import org.apache.commons.logging.LogFactory; import org.apache.log4j.Level; @@ -45,21 +49,37 @@ public class LogAdjustingTestSupport { protected final Log logger = LogFactory.getLog(this.getClass()); - private final Logger loggerToAdjust = LogManager.getLogger("org.springframework.integration"); + private final Collection loggersToAdjust = new ArrayList(); - private Level oldCategory; + private final Collection oldCategories = new ArrayList(); + + + public LogAdjustingTestSupport() { + this("org.springframework.integration"); + } + + public LogAdjustingTestSupport(String... loggersToAdjust) { + for (String loggerToAdjust : loggersToAdjust) { + this.loggersToAdjust.add(LogManager.getLogger(loggerToAdjust)); + } + } @Before public void beforeTest() { - this.oldCategory = loggerToAdjust.getEffectiveLevel(); - this.loggerToAdjust.setLevel(Level.TRACE); + for (Logger loggerToAdjust : this.loggersToAdjust) { + this.oldCategories.add(loggerToAdjust.getEffectiveLevel()); + loggerToAdjust.setLevel(Level.TRACE); + } this.logger.debug("!!!! Starting test: " + this.testName.getMethodName() + " !!!!"); } @After public void afterTest() { logger.debug("!!!! Finished test: " + this.testName.getMethodName() + " !!!!"); - this.loggerToAdjust.setLevel(this.oldCategory); + Iterator oldCategory = this.oldCategories.iterator(); + for (Logger loggerToAdjust : this.loggersToAdjust) { + loggerToAdjust.setLevel(oldCategory.next()); + } } }