https://issues.apache.org/jira/browse/AMQ-4682 - take account of granularity of filesystem lastModified in tests, > 2seconds, resolved intermittent failures

This commit is contained in:
gtully 2013-10-03 16:16:23 +01:00
parent 5eb4e6b8ae
commit 1fdc2c477b
2 changed files with 24 additions and 2 deletions

View File

@ -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

View File

@ -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");