use of voldemort.utils.ConsistencyFix.BadKeyOrphanReader in project voldemort by voldemort.
the class ConsistencyFixTest method badKeyReaderHelper.
/**
* @param orphan true for testing orphan, false for testing normal...
*/
public void badKeyReaderHelper(boolean orphan) {
String tmpDir = TestUtils.createTempDir().getAbsolutePath();
String fileName = tmpDir + "BadKeyFile";
if (orphan) {
badKeyReaderWriteOrphanKeys(fileName, true);
} else {
badKeyReaderWriteBadKeys(fileName, true);
}
// Get cluster bootstrap url
String url = setUpCluster();
// Construct ConsistencyFix with parseOnly true
ConsistencyFix consistencyFix = new ConsistencyFix(url, STORE_NAME, 100, 100, false, true);
// Do set up for BadKeyReader akin to consistencyFix.execute...
int parallelism = 1;
BlockingQueue<Runnable> blockingQ = new ArrayBlockingQueue<Runnable>(parallelism);
RejectedExecutionHandler rejectedExecutionHandler = new ThreadPoolExecutor.CallerRunsPolicy();
ExecutorService consistencyFixWorkers = new ThreadPoolExecutor(parallelism, parallelism, 0L, TimeUnit.MILLISECONDS, blockingQ, rejectedExecutionHandler);
BlockingQueue<BadKeyStatus> badKeyQOut = new ArrayBlockingQueue<BadKeyStatus>(10000);
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());
}
Aggregations