use of org.apache.bookkeeper.util.DiskChecker in project bookkeeper by apache.
the class CompactionTest method testWhenNoLogsToCompact.
/**
* Test that compaction should execute silently when there is no entry logs
* to compact. {@see https://issues.apache.org/jira/browse/BOOKKEEPER-700}
*/
@Test
public void testWhenNoLogsToCompact() throws Exception {
// I dont want the test infrastructure
tearDown();
ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
File tmpDir = createTempDir("bkTest", ".dir");
File curDir = Bookie.getCurrentDirectory(tmpDir);
Bookie.checkDirectoryStructure(curDir);
conf.setLedgerDirNames(new String[] { tmpDir.toString() });
LedgerDirsManager dirs = new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()));
final Set<Long> ledgers = Collections.newSetFromMap(new ConcurrentHashMap<Long, Boolean>());
LedgerManager manager = getLedgerManager(ledgers);
CheckpointSource checkpointSource = new CheckpointSource() {
@Override
public Checkpoint newCheckpoint() {
return null;
}
@Override
public void checkpointComplete(Checkpoint checkpoint, boolean compact) throws IOException {
}
};
InterleavedLedgerStorage storage = new InterleavedLedgerStorage();
storage.initialize(conf, manager, dirs, dirs, null, checkpointSource, Checkpointer.NULL, NullStatsLogger.INSTANCE);
double threshold = 0.1;
// shouldn't throw exception
storage.gcThread.doCompactEntryLogs(threshold);
}
use of org.apache.bookkeeper.util.DiskChecker in project bookkeeper by apache.
the class CreateNewLogTest method testCreateNewLog.
/**
* Checks if new log file id is verified against all directories.
*
* {@link https://issues.apache.org/jira/browse/BOOKKEEPER-465}
*
* @throws Exception
*/
@Test
public void testCreateNewLog() throws Exception {
ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
// Creating a new configuration with a number of
// ledger directories.
conf.setLedgerDirNames(ledgerDirs);
LedgerDirsManager ledgerDirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()));
// Extracted from createNewLog()
String logFileName = Long.toHexString(1) + ".log";
File dir = ledgerDirsManager.pickRandomWritableDir();
LOG.info("Picked this directory: " + dir);
File newLogFile = new File(dir, logFileName);
newLogFile.createNewFile();
EntryLogger el = new EntryLogger(conf, ledgerDirsManager);
// Calls createNewLog, and with the number of directories we
// are using, if it picks one at random it will fail.
el.createNewLog();
LOG.info("This is the current log id: " + el.getCurrentLogId());
assertTrue("Wrong log id", el.getCurrentLogId() > 1);
}
use of org.apache.bookkeeper.util.DiskChecker in project bookkeeper by apache.
the class CreateNewLogTest method testCreateNewLogWithNoWritableLedgerDirs.
@Test
public void testCreateNewLogWithNoWritableLedgerDirs() throws Exception {
ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
// Creating a new configuration with a number of ledger directories.
conf.setLedgerDirNames(ledgerDirs);
conf.setIsForceGCAllowWhenNoSpace(true);
LedgerDirsManager ledgerDirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()));
// Extracted from createNewLog()
String logFileName = Long.toHexString(1) + ".log";
File dir = ledgerDirsManager.pickRandomWritableDir();
LOG.info("Picked this directory: " + dir);
File newLogFile = new File(dir, logFileName);
newLogFile.createNewFile();
// Now let us move all dirs to filled dirs
List<File> wDirs = ledgerDirsManager.getWritableLedgerDirs();
for (File tdir : wDirs) {
ledgerDirsManager.addToFilledDirs(tdir);
}
EntryLogger el = new EntryLogger(conf, ledgerDirsManager);
// Calls createNewLog, and with the number of directories we
// are using, if it picks one at random it will fail.
el.createNewLog();
LOG.info("This is the current log id: " + el.getCurrentLogId());
assertTrue("Wrong log id", el.getCurrentLogId() > 1);
}
use of org.apache.bookkeeper.util.DiskChecker in project bookkeeper by apache.
the class EntryLogTest method testEntryLoggerShouldThrowFNFEIfDirectoriesDoesNotExist.
@Test
public /**
* Test that EntryLogger Should fail with FNFE, if entry logger directories does not exist.
*/
void testEntryLoggerShouldThrowFNFEIfDirectoriesDoesNotExist() throws Exception {
File tmpDir = createTempDir("bkTest", ".dir");
ServerConfiguration conf = TestBKConfiguration.newServerConfiguration();
conf.setLedgerDirNames(new String[] { tmpDir.toString() });
EntryLogger entryLogger = null;
try {
entryLogger = new EntryLogger(conf, new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold())));
fail("Expecting FileNotFoundException");
} catch (FileNotFoundException e) {
assertEquals("Entry log directory does not exist", e.getLocalizedMessage());
} finally {
if (entryLogger != null) {
entryLogger.shutdown();
}
}
}
use of org.apache.bookkeeper.util.DiskChecker in project bookkeeper by apache.
the class TestLedgerDirsManager method setUp.
@Before
public void setUp() throws Exception {
PowerMockito.mockStatic(Executors.class);
File tmpDir = createTempDir("bkTest", ".dir");
curDir = Bookie.getCurrentDirectory(tmpDir);
Bookie.checkDirectoryStructure(curDir);
conf = TestBKConfiguration.newServerConfiguration();
conf.setLedgerDirNames(new String[] { tmpDir.toString() });
conf.setDiskLowWaterMarkUsageThreshold(conf.getDiskUsageThreshold());
conf.setDiskCheckInterval(diskCheckInterval);
conf.setIsForceGCAllowWhenNoSpace(true);
executor = PowerMockito.mock(ScheduledExecutorService.class);
executorController = new MockExecutorController().controlScheduleAtFixedRate(executor, 10);
PowerMockito.when(Executors.newSingleThreadScheduledExecutor(any())).thenReturn(executor);
mockDiskChecker = new MockDiskChecker(threshold, warnThreshold);
statsProvider = new TestStatsProvider();
statsLogger = statsProvider.getStatsLogger("test");
dirsManager = new LedgerDirsManager(conf, conf.getLedgerDirs(), new DiskChecker(conf.getDiskUsageThreshold(), conf.getDiskUsageWarnThreshold()), statsLogger);
ledgerMonitor = new LedgerDirsMonitor(conf, mockDiskChecker, dirsManager);
ledgerMonitor.init();
}
Aggregations