use of org.apache.hadoop.ozone.container.keyvalue.statemachine.background.BlockDeletingService in project ozone by apache.
the class TestContainerDeletionChoosingPolicy method getBlockDeletingService.
private BlockDeletingService getBlockDeletingService() {
ozoneContainer = Mockito.mock(OzoneContainer.class);
Mockito.when(ozoneContainer.getContainerSet()).thenReturn(containerSet);
Mockito.when(ozoneContainer.getWriteChannel()).thenReturn(null);
blockDeletingService = new BlockDeletingService(ozoneContainer, SERVICE_INTERVAL_IN_MILLISECONDS, SERVICE_TIMEOUT_IN_MILLISECONDS, TimeUnit.MILLISECONDS, 10, conf);
return blockDeletingService;
}
use of org.apache.hadoop.ozone.container.keyvalue.statemachine.background.BlockDeletingService in project ozone by apache.
the class TestBlockDeletingService method testBlockDeletionTimeout.
@Test
public void testBlockDeletionTimeout() throws Exception {
DatanodeConfiguration dnConf = conf.getObject(DatanodeConfiguration.class);
dnConf.setBlockDeletionLimit(3);
blockLimitPerInterval = dnConf.getBlockDeletionLimit();
conf.setFromObject(dnConf);
ContainerSet containerSet = new ContainerSet();
createToDeleteBlocks(containerSet, 1, 3, 1);
ContainerMetrics metrics = ContainerMetrics.create(conf);
KeyValueHandler keyValueHandler = new KeyValueHandler(conf, datanodeUuid, containerSet, volumeSet, metrics, c -> {
});
// set timeout value as 1ns to trigger timeout behavior
long timeout = 1;
OzoneContainer ozoneContainer = mockDependencies(containerSet, keyValueHandler);
BlockDeletingService svc = new BlockDeletingService(ozoneContainer, TimeUnit.MILLISECONDS.toNanos(1000), timeout, TimeUnit.NANOSECONDS, 10, conf);
svc.start();
LogCapturer log = LogCapturer.captureLogs(BackgroundService.LOG);
GenericTestUtils.waitFor(() -> {
if (log.getOutput().contains("Background task execution took")) {
log.stopCapturing();
return true;
}
return false;
}, 100, 1000);
log.stopCapturing();
svc.shutdown();
// test for normal case that doesn't have timeout limitation
createToDeleteBlocks(containerSet, 1, 3, 1);
timeout = 0;
svc = new BlockDeletingService(ozoneContainer, TimeUnit.MILLISECONDS.toNanos(1000), timeout, TimeUnit.MILLISECONDS, 10, conf);
svc.start();
// get container meta data
KeyValueContainer container = (KeyValueContainer) containerSet.getContainerIterator().next();
KeyValueContainerData data = container.getContainerData();
try (ReferenceCountedDB meta = BlockUtils.getDB(data, conf)) {
LogCapturer newLog = LogCapturer.captureLogs(BackgroundService.LOG);
GenericTestUtils.waitFor(() -> {
try {
return getUnderDeletionBlocksCount(meta, data) == 0;
} catch (IOException ignored) {
}
return false;
}, 100, 1000);
newLog.stopCapturing();
// The block deleting successfully and shouldn't catch timed
// out warning log.
Assert.assertFalse(newLog.getOutput().contains("Background task executes timed out, retrying in next interval"));
}
svc.shutdown();
}
Aggregations