https://issues.apache.org/jira/browse/AMQ-4705 - harden test - ensure existance before attempted mod

This commit is contained in:
gtully 2015-05-13 16:29:49 +01:00
parent eaf766b35d
commit fee7c1cf4c
1 changed files with 15 additions and 4 deletions

View File

@ -41,6 +41,7 @@ public class KahaDBDeleteLockTest {
@Before @Before
public void createMaster() throws Exception{ public void createMaster() throws Exception{
master = new BrokerService(); master = new BrokerService();
master.setDeleteAllMessagesOnStartup(true);
master.setBrokerName("Master"); master.setBrokerName("Master");
master.setDataDirectoryFile(testDataDir); master.setDataDirectoryFile(testDataDir);
@ -56,6 +57,7 @@ public class KahaDBDeleteLockTest {
public void stopBrokerJustInCase() throws Exception { public void stopBrokerJustInCase() throws Exception {
if (master != null) { if (master != null) {
master.stop(); master.stop();
master.waitUntilStopped();
} }
} }
@ -91,10 +93,19 @@ public class KahaDBDeleteLockTest {
public void testModifyLockFile() throws Exception { public void testModifyLockFile() throws Exception {
assertTrue(master.isStarted()); 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 // ensure modification will be seen, milisecond granularity
TimeUnit.MILLISECONDS.sleep(1); TimeUnit.MILLISECONDS.sleep(10);
RandomAccessFile file = new RandomAccessFile(new File(kahaDataDir, "lock"), "rw"); RandomAccessFile file = new RandomAccessFile(lockFile, "rw");
file.write(4); file.write(4);
file.getChannel().force(true);
file.close(); file.close();
assertTrue("Master stops on lock file modification", Wait.waitFor(new Wait.Condition() { assertTrue("Master stops on lock file modification", Wait.waitFor(new Wait.Condition() {
@ -102,7 +113,7 @@ public class KahaDBDeleteLockTest {
public boolean isSatisified() throws Exception { public boolean isSatisified() throws Exception {
return master.isStopped(); return master.isStopped();
} }
}, 5000)); }, 10000));
} }
} }