use of org.apache.druid.indexing.common.task.KillUnusedSegmentsTask in project druid by druid-io.
the class TaskLifecycleTest method testKillUnusedSegmentsTask.
@Test
public void testKillUnusedSegmentsTask() throws Exception {
final File tmpSegmentDir = temporaryFolder.newFolder();
List<DataSegment> expectedUnusedSegments = Lists.transform(ImmutableList.of("2011-04-01/2011-04-02", "2011-04-02/2011-04-03", "2011-04-04/2011-04-05"), new Function<String, DataSegment>() {
@Override
public DataSegment apply(String input) {
final Interval interval = Intervals.of(input);
try {
return DataSegment.builder().dataSource("test_kill_task").interval(interval).loadSpec(ImmutableMap.of("type", "local", "path", tmpSegmentDir.getCanonicalPath() + "/druid/localStorage/wikipedia/" + interval.getStart() + "-" + interval.getEnd() + "/" + "2011-04-6T16:52:46.119-05:00" + "/0/index.zip")).version("2011-04-6T16:52:46.119-05:00").dimensions(ImmutableList.of()).metrics(ImmutableList.of()).shardSpec(NoneShardSpec.instance()).binaryVersion(9).size(0).build();
} catch (IOException e) {
throw new ISE(e, "Error creating segments");
}
}
});
mdc.setUnusedSegments(expectedUnusedSegments);
// manually create local segments files
List<File> segmentFiles = new ArrayList<>();
for (DataSegment segment : mdc.retrieveUnusedSegmentsForInterval("test_kill_task", Intervals.of("2011-04-01/P4D"))) {
File file = new File((String) segment.getLoadSpec().get("path"));
FileUtils.mkdirp(file);
segmentFiles.add(file);
}
final Task killUnusedSegmentsTask = new KillUnusedSegmentsTask(null, "test_kill_task", Intervals.of("2011-04-01/P4D"), null, false);
final TaskStatus status = runTask(killUnusedSegmentsTask);
Assert.assertEquals(taskLocation, status.getLocation());
Assert.assertEquals("merged statusCode", TaskState.SUCCESS, status.getStatusCode());
Assert.assertEquals("num segments published", 0, mdc.getPublished().size());
Assert.assertEquals("num segments nuked", 3, mdc.getNuked().size());
Assert.assertTrue("expected unused segments get killed", expectedUnusedSegments.containsAll(mdc.getNuked()) && mdc.getNuked().containsAll(expectedUnusedSegments));
for (File file : segmentFiles) {
Assert.assertFalse("unused segments files get deleted", file.exists());
}
}
Aggregations