* should continue getLedgerToRereplicate() task
*/
@Test(timeout = 20000)
public void testEnableLedegerReplication() throws Exception {
isLedgerReplicationDisabled = true;
final LedgerUnderreplicationManager replicaMgr = lmf1
.newLedgerUnderreplicationManager();
// simulate few urLedgers before disabling
final Long ledgerA = 0xfeadeefdacL;
final String missingReplica = "localhost:3181";
try {
replicaMgr.markLedgerUnderreplicated(ledgerA, missingReplica);
} catch (UnavailableException e) {
LOG.debug("Unexpected exception while marking urLedger", e);
fail("Unexpected exception while marking urLedger" + e.getMessage());
}
// disabling replication
replicaMgr.disableLedgerReplication();
LOG.debug("Disabled Ledeger Replication");
String znodeA = getUrLedgerZnode(ledgerA);
final CountDownLatch znodeLatch = new CountDownLatch(2);
String urledgerA = StringUtils.substringAfterLast(znodeA, "/");
String urLockLedgerA = basePath + "/locks/" + urledgerA;
zkc1.exists(urLockLedgerA, new Watcher(){
@Override
public void process(WatchedEvent event) {
if (event.getType() == EventType.NodeCreated) {
znodeLatch.countDown();
LOG.debug("Recieved node creation event for the zNodePath:"
+ event.getPath());
}
}});
// getLedgerToRereplicate is waiting until enable rereplication
Thread thread1 = new Thread() {
@Override
public void run() {
try {
Long lA = replicaMgr.getLedgerToRereplicate();
assertEquals("Should be the ledger I just marked", lA,
ledgerA);
isLedgerReplicationDisabled = false;
znodeLatch.countDown();
} catch (UnavailableException e) {
LOG.debug("Unexpected exception while marking urLedger", e);
isLedgerReplicationDisabled = false;
}
}
};
thread1.start();
try {
znodeLatch.await(5, TimeUnit.SECONDS);
assertTrue("Ledger replication is not disabled!",
isLedgerReplicationDisabled);
assertEquals("Failed to disable ledger replication!", 2, znodeLatch
.getCount());
replicaMgr.enableLedgerReplication();
znodeLatch.await(5, TimeUnit.SECONDS);
LOG.debug("Enabled Ledeger Replication");
assertTrue("Ledger replication is not disabled!",
!isLedgerReplicationDisabled);
assertEquals("Failed to disable ledger replication!", 0, znodeLatch