Search in sources :

Example 1 with KillTask

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());
    }
}
Also used : IndexTask(io.druid.indexing.common.task.IndexTask) RealtimeIndexTask(io.druid.indexing.common.task.RealtimeIndexTask) Task(io.druid.indexing.common.task.Task) AbstractFixedIntervalTask(io.druid.indexing.common.task.AbstractFixedIntervalTask) KillTask(io.druid.indexing.common.task.KillTask) KillTask(io.druid.indexing.common.task.KillTask) IOException(java.io.IOException) TaskStatus(io.druid.indexing.common.TaskStatus) DataSegment(io.druid.timeline.DataSegment) ISE(io.druid.java.util.common.ISE) File(java.io.File) Interval(org.joda.time.Interval) FireDepartmentTest(io.druid.segment.realtime.FireDepartmentTest) Test(org.junit.Test)

Aggregations

TaskStatus (io.druid.indexing.common.TaskStatus)1 AbstractFixedIntervalTask (io.druid.indexing.common.task.AbstractFixedIntervalTask)1 IndexTask (io.druid.indexing.common.task.IndexTask)1 KillTask (io.druid.indexing.common.task.KillTask)1 RealtimeIndexTask (io.druid.indexing.common.task.RealtimeIndexTask)1 Task (io.druid.indexing.common.task.Task)1 ISE (io.druid.java.util.common.ISE)1 FireDepartmentTest (io.druid.segment.realtime.FireDepartmentTest)1 DataSegment (io.druid.timeline.DataSegment)1 File (java.io.File)1 IOException (java.io.IOException)1 Interval (org.joda.time.Interval)1 Test (org.junit.Test)1