From fee7c1cf4ca5361eda416ac13f253f5fa37ef6ac Mon Sep 17 00:00:00 2001 From: gtully Date: Wed, 13 May 2015 16:29:49 +0100 Subject: [PATCH] https://issues.apache.org/jira/browse/AMQ-4705 - harden test - ensure existance before attempted mod --- .../store/kahadb/KahaDBDeleteLockTest.java | 19 +++++++++++++++---- 1 file changed, 15 insertions(+), 4 deletions(-) diff --git a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/KahaDBDeleteLockTest.java b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/KahaDBDeleteLockTest.java index b57a5c799c..53de60335b 100644 --- a/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/KahaDBDeleteLockTest.java +++ b/activemq-unit-tests/src/test/java/org/apache/activemq/store/kahadb/KahaDBDeleteLockTest.java @@ -41,6 +41,7 @@ public class KahaDBDeleteLockTest { @Before public void createMaster() throws Exception{ master = new BrokerService(); + master.setDeleteAllMessagesOnStartup(true); master.setBrokerName("Master"); master.setDataDirectoryFile(testDataDir); @@ -56,6 +57,7 @@ public class KahaDBDeleteLockTest { public void stopBrokerJustInCase() throws Exception { if (master != null) { master.stop(); + master.waitUntilStopped(); } } @@ -91,10 +93,19 @@ public class KahaDBDeleteLockTest { public void testModifyLockFile() throws Exception { assertTrue(master.isStarted()); + final File lockFile = new File(kahaDataDir, "lock"); + assertTrue("lock file exists via modification time", Wait.waitFor(new Wait.Condition() { + @Override + public boolean isSatisified() throws Exception { + return lockFile.lastModified() > 0; + } + })); + // ensure modification will be seen, milisecond granularity - TimeUnit.MILLISECONDS.sleep(1); - RandomAccessFile file = new RandomAccessFile(new File(kahaDataDir, "lock"), "rw"); + TimeUnit.MILLISECONDS.sleep(10); + RandomAccessFile file = new RandomAccessFile(lockFile, "rw"); file.write(4); + file.getChannel().force(true); file.close(); assertTrue("Master stops on lock file modification", Wait.waitFor(new Wait.Condition() { @@ -102,7 +113,7 @@ public class KahaDBDeleteLockTest { public boolean isSatisified() throws Exception { return master.isStopped(); } - }, 5000)); + }, 10000)); } -} \ No newline at end of file +}