FileSupport.toRichFile(masterDir).recursiveDelete();
FileSupport.toRichFile(slaveDir).recursiveDelete();
final MasterLevelDBStore master = createMaster(masterDir);
master.setReplicas(2);
CountDownFuture masterStartLatch = asyncStart(master);
// Start the store should not complete since we don't have enough
// replicas.
assertFalse(masterStartLatch.await(2, TimeUnit.SECONDS));
// Adding a slave should allow the master startup to complete.
SlaveLevelDBStore slave = createSlave(master, slaveDir);
slave.start();
assertTrue(masterStartLatch.await(2, TimeUnit.SECONDS));
// New updates should complete quickly now..
MessageStore ms = master.createQueueMessageStore(new ActiveMQQueue("TEST"));
CountDownFuture f = asyncAddMessage(ms, "m1");
assertTrue(f.await(1, TimeUnit.SECONDS));
// If the slave goes offline, then updates should once again
// not complete.
slave.stop();
f = asyncAddMessage(ms, "m2");
assertFalse(f.await(2, TimeUnit.SECONDS));
// Restart and the op should complete.
slave = createSlave(master, slaveDir);
slave.start();
assertTrue(f.await(2, TimeUnit.SECONDS));
master.stop();
slave.stop();
}