use of voldemort.utils.ConsistencyFix.BadKeyWriter in project voldemort by voldemort.
the class ConsistencyFixTest method testBadKeyWriter.
@Test
public void testBadKeyWriter() {
String tmpDir = TestUtils.createTempDir().getAbsolutePath();
String fileName = tmpDir + "BadKeyFile";
// 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));
int i = 0;
for (String keyLine = fileReader.readLine(); keyLine != null; keyLine = fileReader.readLine()) {
assertEquals(keyLine, Integer.toHexString(i));
i++;
}
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
fail("Unexpected exception");
} catch (IOException ioe) {
ioe.printStackTrace();
fail("Unexpected exception");
}
}
Aggregations