From bddbc5b6fb6b59d624f1945efebf090685ed14e5 Mon Sep 17 00:00:00 2001 From: Gary Russell Date: Fri, 27 Sep 2013 20:12:11 +0300 Subject: [PATCH] INT-3152 Speed Up Build Times Add a `@Rule` to skip long-runing tests during normal builds. Add the rule to long-running tests in gemfire, ip, jms, jmx. Add an environment variable `RUN_LONG_INTEGRATION_TESTS`; when set to true, all tests are run. Set the environment variable to true on all nightly builds. Build now runs in 13 minutes on my 3 year old laptop. Polishing - Switch to TestWatcher TestWatchMan is deprecated. INT-3152 Polishing Show Skipped Tests as 'Ignored' In test report. JIRA: https://jira.springsource.org/browse/INT-3152 --- .../gemfire/store/GemfireGroupStoreTests.java | 19 ++++--- .../connection/ConnectionTimeoutTests.java | 5 ++ .../jms/request_reply/PipelineJmsTests.java | 11 ++++ .../PipelineNamedReplyQueuesJmsTests.java | 11 ++++ ...eplyScenariosWithCachedConsumersTests.java | 6 ++ ...nariosWithCorrelationKeyProvidedTests.java | 5 ++ ...yScenariosWithNonCachedConsumersTests.java | 6 ++ ...eplyScenariosWithTempReplyQueuesTests.java | 5 ++ .../mbeanexporterhelper/Int2307Tests.java | 8 ++- .../support/LongRunningIntegrationTest.java | 55 +++++++++++++++++++ 10 files changed, 123 insertions(+), 8 deletions(-) create mode 100644 spring-integration-test/src/main/java/org/springframework/integration/test/support/LongRunningIntegrationTest.java diff --git a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/GemfireGroupStoreTests.java b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/GemfireGroupStoreTests.java index 93dbfea660..59f90d9c80 100644 --- a/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/GemfireGroupStoreTests.java +++ b/spring-integration-gemfire/src/test/java/org/springframework/integration/gemfire/store/GemfireGroupStoreTests.java @@ -1,5 +1,5 @@ /* - * Copyright 2007-2011 the original author or authors + * Copyright 2007-2013 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. @@ -15,6 +15,12 @@ */ package org.springframework.integration.gemfire.store; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertNotNull; +import static org.junit.Assert.assertNotSame; +import static org.junit.Assert.assertNull; +import static org.junit.Assert.assertTrue; + import java.util.ArrayList; import java.util.Iterator; import java.util.List; @@ -28,6 +34,7 @@ import junit.framework.AssertionFailedError; import org.junit.After; import org.junit.Before; import org.junit.Ignore; +import org.junit.Rule; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -41,16 +48,11 @@ import org.springframework.integration.message.GenericMessage; import org.springframework.integration.store.MessageGroup; import org.springframework.integration.store.SimpleMessageGroup; import org.springframework.integration.support.MessageBuilder; +import org.springframework.integration.test.support.LongRunningIntegrationTest; import org.springframework.util.Assert; import com.gemstone.gemfire.cache.Cache; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertNotNull; -import static org.junit.Assert.assertNotSame; -import static org.junit.Assert.assertNull; -import static org.junit.Assert.assertTrue; - /** * @author Oleg Zhurakousky * @@ -59,6 +61,9 @@ public class GemfireGroupStoreTests { private Cache cache; + @Rule + public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); + @Test public void testNonExistingEmptyMessageGroup() throws Exception{ GemfireMessageStore store = new GemfireMessageStore(this.cache); diff --git a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionTimeoutTests.java b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionTimeoutTests.java index c379bcc474..753d8d6a9c 100644 --- a/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionTimeoutTests.java +++ b/spring-integration-ip/src/test/java/org/springframework/integration/ip/tcp/connection/ConnectionTimeoutTests.java @@ -24,10 +24,12 @@ import static org.junit.Assert.assertTrue; import java.net.Socket; import java.util.concurrent.atomic.AtomicReference; +import org.junit.Rule; import org.junit.Test; import org.springframework.integration.Message; import org.springframework.integration.ip.util.TestingUtilities; import org.springframework.integration.support.MessageBuilder; +import org.springframework.integration.test.support.LongRunningIntegrationTest; import org.springframework.integration.test.util.SocketUtils; import org.springframework.integration.test.util.TestUtils; @@ -38,6 +40,9 @@ import org.springframework.integration.test.util.TestUtils; */ public class ConnectionTimeoutTests { + @Rule + public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); + @Test public void testDefaultTimeout() throws Exception { int port = SocketUtils.findAvailableServerSocket(); diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/PipelineJmsTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/PipelineJmsTests.java index 922b0375f5..57257b7f99 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/PipelineJmsTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/PipelineJmsTests.java @@ -23,12 +23,14 @@ import java.util.concurrent.Executor; import java.util.concurrent.Executors; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.Rule; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.MessageTimeoutException; import org.springframework.integration.gateway.RequestReplyExchanger; import org.springframework.integration.jms.config.ActiveMqTestUtils; import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.test.support.LongRunningIntegrationTest; /** * @author Oleg Zhurakousky */ @@ -36,6 +38,15 @@ public class PipelineJmsTests { private final Executor executor = Executors.newFixedThreadPool(30); +private static final Log logger = LogFactory.getLog(PipelineJmsTests.class); + + @Rule + public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); + + @Before + public void setLogLevel() { + LogManager.getLogger(getClass()).setLevel(Level.INFO); + } int requests = 50; /** diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/PipelineNamedReplyQueuesJmsTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/PipelineNamedReplyQueuesJmsTests.java index 86e14bee52..587caf75d3 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/PipelineNamedReplyQueuesJmsTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/PipelineNamedReplyQueuesJmsTests.java @@ -24,12 +24,14 @@ import java.util.concurrent.Executors; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicInteger; +import org.junit.Rule; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.MessageTimeoutException; import org.springframework.integration.gateway.RequestReplyExchanger; import org.springframework.integration.jms.config.ActiveMqTestUtils; import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.test.support.LongRunningIntegrationTest; /** * @author Oleg Zhurakousky * @author Gary Russell @@ -39,6 +41,15 @@ public class PipelineNamedReplyQueuesJmsTests { private final Executor executor = Executors.newFixedThreadPool(30); + private static final Log logger = LogFactory.getLog(PipelineJmsTests.class); + + @Rule + public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); + + @Before + public void setLogLevel() { + LogManager.getLogger(getClass()).setLevel(Level.INFO); + } int requests = 50; /** diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithCachedConsumersTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithCachedConsumersTests.java index d8ba775b31..62d07037e5 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithCachedConsumersTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithCachedConsumersTests.java @@ -28,13 +28,16 @@ import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; +import org.junit.Rule; import org.junit.Test; + import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.MessageTimeoutException; import org.springframework.integration.gateway.RequestReplyExchanger; import org.springframework.integration.jms.JmsOutboundGateway; import org.springframework.integration.jms.config.ActiveMqTestUtils; import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.test.support.LongRunningIntegrationTest; import org.springframework.integration.test.util.TestUtils; import org.springframework.jms.connection.CachingConnectionFactory; import org.springframework.jms.core.JmsTemplate; @@ -49,6 +52,9 @@ public class RequestReplyScenariosWithCachedConsumersTests { private final SimpleMessageConverter converter = new SimpleMessageConverter(); + @Rule + public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); + @Test(expected=MessageTimeoutException.class) public void messageCorrelationBasedOnRequestMessageIdOptimized() throws Exception{ ActiveMqTestUtils.prepare(); diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithCorrelationKeyProvidedTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithCorrelationKeyProvidedTests.java index 1a9c34ae06..d3c0366af8 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithCorrelationKeyProvidedTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithCorrelationKeyProvidedTests.java @@ -17,6 +17,7 @@ package org.springframework.integration.jms.request_reply; import static org.junit.Assert.assertEquals; +import org.junit.Rule; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -24,12 +25,16 @@ import org.springframework.integration.gateway.RequestReplyExchanger; import org.springframework.integration.jms.JmsOutboundGateway; import org.springframework.integration.jms.config.ActiveMqTestUtils; import org.springframework.integration.support.MessageBuilder; +import org.springframework.integration.test.support.LongRunningIntegrationTest; import org.springframework.integration.test.util.TestUtils; /** * @author Oleg Zhurakousky */ public class RequestReplyScenariosWithCorrelationKeyProvidedTests { + @Rule + public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); + @Test public void messageCorrelationBasedCustomCorrelationKey() throws Exception{ ActiveMqTestUtils.prepare(); diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithNonCachedConsumersTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithNonCachedConsumersTests.java index 981880a978..4fb2a1cb00 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithNonCachedConsumersTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithNonCachedConsumersTests.java @@ -24,13 +24,16 @@ import javax.jms.Message; import javax.jms.Session; import javax.jms.TextMessage; +import org.junit.Rule; import org.junit.Test; + import org.springframework.context.support.AbstractApplicationContext; import org.springframework.context.support.ClassPathXmlApplicationContext; import org.springframework.integration.MessageTimeoutException; import org.springframework.integration.gateway.RequestReplyExchanger; import org.springframework.integration.jms.config.ActiveMqTestUtils; import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.test.support.LongRunningIntegrationTest; import org.springframework.jms.core.JmsTemplate; import org.springframework.jms.core.MessageCreator; /** @@ -38,6 +41,9 @@ import org.springframework.jms.core.MessageCreator; */ public class RequestReplyScenariosWithNonCachedConsumersTests { + @Rule + public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); + @Test(expected=MessageTimeoutException.class) public void messageCorrelationBasedOnRequestMessageIdOptimized() throws Exception{ ActiveMqTestUtils.prepare(); diff --git a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithTempReplyQueuesTests.java b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithTempReplyQueuesTests.java index 78909846d0..a4c60d7b28 100644 --- a/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithTempReplyQueuesTests.java +++ b/spring-integration-jms/src/test/java/org/springframework/integration/jms/request_reply/RequestReplyScenariosWithTempReplyQueuesTests.java @@ -36,6 +36,7 @@ import javax.jms.TextMessage; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.command.ActiveMQDestination; +import org.junit.Rule; import org.junit.Test; import org.springframework.context.support.ClassPathXmlApplicationContext; @@ -43,6 +44,7 @@ import org.springframework.integration.MessageDeliveryException; import org.springframework.integration.gateway.RequestReplyExchanger; import org.springframework.integration.jms.config.ActiveMqTestUtils; import org.springframework.integration.message.GenericMessage; +import org.springframework.integration.test.support.LongRunningIntegrationTest; import org.springframework.integration.test.util.TestUtils; import org.springframework.jms.connection.CachingConnectionFactory; import org.springframework.jms.core.JmsTemplate; @@ -57,6 +59,9 @@ public class RequestReplyScenariosWithTempReplyQueuesTests { private final SimpleMessageConverter converter = new SimpleMessageConverter(); + @Rule + public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); + @Test public void messageCorrelationBasedOnRequestMessageId() throws Exception{ ActiveMqTestUtils.prepare(); diff --git a/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java b/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java index 9a4c7dc464..b748093e79 100644 --- a/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java +++ b/spring-integration-jmx/src/test/java/org/springframework/integration_/mbeanexporterhelper/Int2307Tests.java @@ -1,5 +1,5 @@ /* - * Copyright 2002-2011 the original author or authors. + * Copyright 2002-2013 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. You may obtain a copy of the License at @@ -22,8 +22,11 @@ import javax.management.MBeanServer; import javax.management.MBeanServerFactory; import javax.management.ObjectInstance; +import org.junit.Rule; import org.junit.Test; + import org.springframework.context.support.ClassPathXmlApplicationContext; +import org.springframework.integration.test.support.LongRunningIntegrationTest; import org.springframework.integration.test.util.TestUtils; import org.springframework.jmx.export.MBeanExporter; @@ -34,6 +37,9 @@ import org.springframework.jmx.export.MBeanExporter; */ public class Int2307Tests { + @Rule + public LongRunningIntegrationTest longTests = new LongRunningIntegrationTest(); + @SuppressWarnings("unchecked") @Test public void testInt2307_DefaultMBeanExporter() throws Exception{ diff --git a/spring-integration-test/src/main/java/org/springframework/integration/test/support/LongRunningIntegrationTest.java b/spring-integration-test/src/main/java/org/springframework/integration/test/support/LongRunningIntegrationTest.java new file mode 100644 index 0000000000..5c850fee76 --- /dev/null +++ b/spring-integration-test/src/main/java/org/springframework/integration/test/support/LongRunningIntegrationTest.java @@ -0,0 +1,55 @@ +/* + * Copyright 2013 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. + * 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. + */ +package org.springframework.integration.test.support; + +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; +import org.junit.Assume; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; +import org.junit.runners.model.Statement; + +/** + * Rule to prevent long running tests from running on every build; set environment + * variable RUN_LONG_INTEGRATION_TESTS on a CI nightly build to ensure coverage. + * + * @author Gary Russell + * @since 3.0 + * + */ +public class LongRunningIntegrationTest extends TestWatcher { + + private final static Log logger = LogFactory.getLog(LongRunningIntegrationTest.class); + + @Override + public Statement apply(Statement base, Description description) { + boolean shouldRun = "true".equalsIgnoreCase(System.getenv("RUN_LONG_INTEGRATION_TESTS")); + if (!shouldRun) { + logger.info("Skipping long running test " + description.getDisplayName()); + return new Statement() { + + @Override + public void evaluate() throws Throwable { + Assume.assumeTrue(false); + } + }; + } + else { + return super.apply(base, description); + } + } + +}