* {@see https://issues.apache.org/jira/browse/BOOKKEEPER-664}
*/
@Test(timeout=60000)
public void testCompactionSafety() throws Exception {
tearDown(); // I dont want the test infrastructure
ServerConfiguration conf = new ServerConfiguration().setAllowLoopback(true);
final Set<Long> ledgers = Collections.newSetFromMap(new ConcurrentHashMap<Long, Boolean>());
LedgerManager manager = new LedgerManager() {
@Override
public void createLedger(LedgerMetadata metadata, GenericCallback<Long> cb) {
unsupported();
}
@Override
public void removeLedgerMetadata(long ledgerId, Version version,
GenericCallback<Void> vb) {
unsupported();
}
@Override
public void readLedgerMetadata(long ledgerId, GenericCallback<LedgerMetadata> readCb) {
unsupported();
}
@Override
public void writeLedgerMetadata(long ledgerId, LedgerMetadata metadata,
GenericCallback<Void> cb) {
unsupported();
}
@Override
public void asyncProcessLedgers(Processor<Long> processor,
AsyncCallback.VoidCallback finalCb,
Object context, int successRc, int failureRc) {
unsupported();
}
@Override
public void registerLedgerMetadataListener(long ledgerId,
LedgerMetadataListener listener) {
unsupported();
}
@Override
public void unregisterLedgerMetadataListener(long ledgerId,
LedgerMetadataListener listener) {
unsupported();
}
@Override
public void close() throws IOException {}
void unsupported() {
LOG.error("Unsupported operation called", new Exception());
throw new RuntimeException("Unsupported op");
}
@Override
public LedgerRangeIterator getLedgerRanges() {
final AtomicBoolean hasnext = new AtomicBoolean(true);
return new LedgerManager.LedgerRangeIterator() {
@Override
public boolean hasNext() throws IOException {
return hasnext.get();
}
@Override
public LedgerManager.LedgerRange next() throws IOException {
hasnext.set(false);
return new LedgerManager.LedgerRange(ledgers);
}
};
}
};
File tmpDir = File.createTempFile("bkTest", ".dir");
tmpDir.delete();
tmpDir.mkdir();
File curDir = Bookie.getCurrentDirectory(tmpDir);
Bookie.checkDirectoryStructure(curDir);
conf.setLedgerDirNames(new String[] {tmpDir.toString()});
conf.setEntryLogSizeLimit(EntryLogger.LOGFILE_HEADER_SIZE + 3 * (4+ENTRY_SIZE));
conf.setGcWaitTime(100);
conf.setMinorCompactionThreshold(0.7f);
conf.setMajorCompactionThreshold(0.0f);
conf.setMinorCompactionInterval(1);
conf.setMajorCompactionInterval(10);
conf.setPageLimit(1);
final byte[] KEY = "foobar".getBytes();
File log0 = new File(curDir, "0.log");
LedgerDirsManager dirs = new LedgerDirsManager(conf);
assertFalse("Log shouldnt exist", log0.exists());