* the bookie index files
*/
@Test(timeout=30000)
public void testIndexCorruption() throws Exception {
LedgerManagerFactory mFactory = LedgerManagerFactory.newLedgerManagerFactory(bsConfs.get(0), zkc);
LedgerUnderreplicationManager underReplicationManager = mFactory.newLedgerUnderreplicationManager();
LedgerHandle lh = bkc.createLedger(3, 3, DigestType.CRC32, "passwd".getBytes());
long ledgerToCorrupt = lh.getId();
for (int i = 0; i < 100; i++) {
lh.addEntry("testdata".getBytes());
}
lh.close();
// push ledgerToCorrupt out of page cache (bookie is configured to only use 1 page)
lh = bkc.createLedger(3, 3, DigestType.CRC32, "passwd".getBytes());
for (int i = 0; i < 100; i++) {
lh.addEntry("testdata".getBytes());
}
lh.close();
BookieAccessor.forceFlush(bs.get(0).getBookie());
File ledgerDir = bsConfs.get(0).getLedgerDirs()[0];
ledgerDir = Bookie.getCurrentDirectory(ledgerDir);
// corrupt of entryLogs
File index = new File(ledgerDir, LedgerCacheImpl.getLedgerName(ledgerToCorrupt));
LOG.info("file to corrupt{}" , index);
ByteBuffer junk = ByteBuffer.allocate(1024*1024);
FileOutputStream out = new FileOutputStream(index);
out.getChannel().write(junk);
out.close();
long underReplicatedLedger = -1;
for (int i = 0; i < 10; i++) {
underReplicatedLedger = underReplicationManager.pollLedgerToRereplicate();
if (underReplicatedLedger != -1) {
break;
}
Thread.sleep(CHECK_INTERVAL);
}
assertEquals("Ledger should be under replicated", ledgerToCorrupt, underReplicatedLedger);
underReplicationManager.close();
}