// Set up bad key writer
BlockingQueue<BadKeyStatus> bq = new ArrayBlockingQueue<BadKeyStatus>(5);
ExecutorService badKeyWriterService = Executors.newSingleThreadExecutor();
BadKeyWriter badKeyWriter = new BadKeyWriter(fileName, bq);
badKeyWriterService.submit(badKeyWriter);
// Enqueue stuff for bad key writer to write
try {
for(int i = 0; i < 100; ++i) {
BadKey badKey = new BadKey(Integer.toHexString(i), Integer.toHexString(i) + "\n");
bq.put(new BadKeyStatus(badKey, ConsistencyFix.Status.REPAIR_EXCEPTION));
}
// Poison bad key writer
bq.put(new BadKeyStatus());
} catch(InterruptedException e) {
e.printStackTrace();
fail("Unexpected exception");
}
// wait for bad key writer to shutdown
badKeyWriterService.shutdown();
try {
badKeyWriterService.awaitTermination(Long.MAX_VALUE, TimeUnit.NANOSECONDS);
} catch(InterruptedException e) {
e.printStackTrace();
fail("Unexpected exception");
}
assertFalse(badKeyWriter.hasException());
// Read output file & verify.
try {
BufferedReader fileReader = new BufferedReader(new FileReader(fileName));