ExecutorService badKeyReaderService = Executors.newSingleThreadExecutor();
CountDownLatch allBadKeysReadLatch = new CountDownLatch(1);
// Submit file of bad keys to (appropriate) BadKeyReader
BadKeyReader bkr = null;
if(orphan) {
bkr = new BadKeyOrphanReader(allBadKeysReadLatch,
fileName,
consistencyFix,
consistencyFixWorkers,
badKeyQOut);
} else {
bkr = new BadKeyReader(allBadKeysReadLatch,
fileName,
consistencyFix,
consistencyFixWorkers,
badKeyQOut);
}
badKeyReaderService.submit(bkr);
// Wait for file to be processed.
try {
allBadKeysReadLatch.await();
badKeyReaderService.shutdown();
consistencyFixWorkers.shutdown();
} catch(InterruptedException e) {
e.printStackTrace();
fail("Unexpected exception");
}
consistencyFix.close();
// Make sure everything worked as expected.
assertFalse(bkr.hasException());
assertEquals(0, badKeyQOut.size());
}