From 1fdc2c477ba5628123bbe7702635af69c333d091 Mon Sep 17 00:00:00 2001 From: gtully Date: Thu, 3 Oct 2013 16:16:23 +0100 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-4682 - take account of granularity of filesystem lastModified in tests, > 2seconds, resolved intermittent failures --- .../activemq/RuntimeConfigTestSupport.java | 18 +++++++++++++++++- .../org/apache/activemq/VirtualDestTest.java | 8 +++++++- 2 files changed, 24 insertions(+), 2 deletions(-) diff --git a/activemq-runtime-config/src/test/java/org/apache/activemq/RuntimeConfigTestSupport.java b/activemq-runtime-config/src/test/java/org/apache/activemq/RuntimeConfigTestSupport.java index 44afa58872..24894c3afb 100644 --- a/activemq-runtime-config/src/test/java/org/apache/activemq/RuntimeConfigTestSupport.java +++ b/activemq-runtime-config/src/test/java/org/apache/activemq/RuntimeConfigTestSupport.java @@ -19,11 +19,15 @@ package org.apache.activemq; import java.io.File; import java.io.FileInputStream; import java.io.FileOutputStream; +import java.util.Date; import java.util.concurrent.TimeUnit; import org.apache.activemq.broker.BrokerFactory; import org.apache.activemq.broker.BrokerService; import org.apache.activemq.spring.Utils; import org.junit.After; +import org.junit.Rule; +import org.junit.rules.TestWatcher; +import org.junit.runner.Description; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.springframework.core.io.Resource; @@ -35,10 +39,21 @@ public class RuntimeConfigTestSupport { public static final String EMPTY_UPDATABLE_CONFIG = "emptyUpdatableConfig1000" ; BrokerService brokerService; + @Rule + public TestWatcher watchman = new TestWatcher() { + @Override + public void starting(Description description) { + LOG.info("{} being run...", description.getMethodName()); + } + }; + public void startBroker(String configFileName) throws Exception { brokerService = createBroker(configFileName); brokerService.start(); brokerService.waitUntilStarted(); + + // File system lastMod time granularity can be up to 2 seconds + TimeUnit.SECONDS.sleep(SLEEP); } public BrokerService createBroker(String configFileName) throws Exception { @@ -57,9 +72,10 @@ public class RuntimeConfigTestSupport { FileInputStream modifications = new FileInputStream(new File(resource.getFile(), newConfigName + ".xml")); modifications.getChannel().transferTo(0, Long.MAX_VALUE, current.getChannel()); current.flush(); + current.getChannel().force(true); current.close(); modifications.close(); - LOG.info("Updated: " + file); + LOG.info("Updated: " + file + " (" + file.lastModified() + ") " + new Date(file.lastModified())); if (sleep > 0) { // wait for mods to kick in diff --git a/activemq-runtime-config/src/test/java/org/apache/activemq/VirtualDestTest.java b/activemq-runtime-config/src/test/java/org/apache/activemq/VirtualDestTest.java index 73ce790594..e408afdee0 100644 --- a/activemq-runtime-config/src/test/java/org/apache/activemq/VirtualDestTest.java +++ b/activemq-runtime-config/src/test/java/org/apache/activemq/VirtualDestTest.java @@ -16,8 +16,8 @@ */ package org.apache.activemq; +import java.util.concurrent.TimeUnit; import javax.jms.Message; -import javax.jms.MessageConsumer; import javax.jms.MessageProducer; import javax.jms.Session; import javax.jms.TextMessage; @@ -78,6 +78,8 @@ public class VirtualDestTest extends RuntimeConfigTestSupport { brokerService.start(); brokerService.waitUntilStarted(); + TimeUnit.SECONDS.sleep(SLEEP); + assertTrue("broker alive", brokerService.isStarted()); DestinationInterceptor[] interceptors = brokerService.getDestinationInterceptors(); @@ -108,6 +110,8 @@ public class VirtualDestTest extends RuntimeConfigTestSupport { brokerService.start(); brokerService.waitUntilStarted(); + TimeUnit.SECONDS.sleep(SLEEP); + assertTrue("broker alive", brokerService.isStarted()); DestinationInterceptor[] interceptors = brokerService.getDestinationInterceptors(); @@ -194,6 +198,8 @@ public class VirtualDestTest extends RuntimeConfigTestSupport { brokerService.start(); brokerService.waitUntilStarted(); + TimeUnit.SECONDS.sleep(SLEEP); + assertEquals("one interceptor", 1, brokerService.getDestinationInterceptors().length); exerciseVirtualTopic("A.Default");