use of io.druid.indexing.common.task.KillTask in project druid by druid-io.
the class TaskLifecycleTest method testKillTask.
@Test
public void testKillTask() throws Exception {
final File tmpSegmentDir = temporaryFolder.newFolder();
List<DataSegment> expectedUnusedSegments = Lists.transform(ImmutableList.<String>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 = new Interval(input);
try {
return DataSegment.builder().dataSource("test_kill_task").interval(interval).loadSpec(ImmutableMap.<String, Object>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.<String>of()).metrics(ImmutableList.<String>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 = Lists.newArrayList();
for (DataSegment segment : mdc.getUnusedSegmentsForInterval("test_kill_task", new Interval("2011-04-01/P4D"))) {
File file = new File((String) segment.getLoadSpec().get("path"));
file.mkdirs();
segmentFiles.add(file);
}
final Task killTask = new KillTask(null, "test_kill_task", new Interval("2011-04-01/P4D"), null);
final TaskStatus status = runTask(killTask);
Assert.assertEquals("merged statusCode", TaskStatus.Status.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