use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLifecycleTest method testBadInterval.
@Test
public void testBadInterval() throws Exception {
final Task task = new AbstractFixedIntervalTask("id1", "id1", "ds", Intervals.of("2012-01-01/P1D"), null) {
@Override
public String getType() {
return "test";
}
@Override
public void stopGracefully(TaskConfig taskConfig) {
}
@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
final TaskLock myLock = Iterables.getOnlyElement(toolbox.getTaskActionClient().submit(new LockListAction()));
final DataSegment segment = DataSegment.builder().dataSource("ds").interval(Intervals.of("2012-01-01/P2D")).version(myLock.getVersion()).size(0).build();
toolbox.getTaskActionClient().submit(new SegmentInsertAction(ImmutableSet.of(segment)));
return TaskStatus.success(getId());
}
};
final TaskStatus status = runTask(task);
Assert.assertEquals("statusCode", TaskState.FAILED, status.getStatusCode());
Assert.assertEquals(taskLocation, status.getLocation());
Assert.assertEquals("segments published", 0, mdc.getPublished().size());
Assert.assertEquals("segments nuked", 0, mdc.getNuked().size());
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLifecycleTest method testLockRevoked.
@Test
public void testLockRevoked() throws Exception {
final Task task = new AbstractFixedIntervalTask("id1", "id1", new TaskResource("id1", 1), "ds", Intervals.of("2012-01-01/P1D"), null) {
@Override
public String getType() {
return "test";
}
@Override
public void stopGracefully(TaskConfig taskConfig) {
}
@Override
public TaskStatus run(TaskToolbox toolbox) throws Exception {
final Interval interval = Intervals.of("2012-01-01/P1D");
final TimeChunkLockTryAcquireAction action = new TimeChunkLockTryAcquireAction(TaskLockType.EXCLUSIVE, interval);
final TaskLock lock = toolbox.getTaskActionClient().submit(action);
if (lock == null) {
throw new ISE("Failed to get a lock");
}
final TaskLock lockBeforeRevoke = toolbox.getTaskActionClient().submit(action);
Assert.assertFalse(lockBeforeRevoke.isRevoked());
taskLockbox.revokeLock(getId(), lock);
final TaskLock lockAfterRevoke = toolbox.getTaskActionClient().submit(action);
Assert.assertTrue(lockAfterRevoke.isRevoked());
return TaskStatus.failure(getId(), "lock revoked test");
}
};
final TaskStatus status = runTask(task);
Assert.assertEquals(taskLocation, status.getLocation());
Assert.assertEquals("statusCode", TaskState.FAILED, status.getStatusCode());
Assert.assertEquals("segments published", 0, mdc.getPublished().size());
Assert.assertEquals("segments nuked", 0, mdc.getNuked().size());
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLifecycleTest method testRealtimeishTask.
@Test
public void testRealtimeishTask() throws Exception {
final Task rtishTask = new RealtimeishTask();
final TaskStatus status = runTask(rtishTask);
Assert.assertEquals("statusCode", TaskState.SUCCESS, status.getStatusCode());
Assert.assertEquals(taskLocation, status.getLocation());
Assert.assertEquals("num segments published", 2, mdc.getPublished().size());
Assert.assertEquals("num segments nuked", 0, mdc.getNuked().size());
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLockConfigTest method testOverwriteDefault.
@Test
public void testOverwriteDefault() throws EntryExistsException {
final TaskQueue taskQueue = createTaskQueue(null);
taskQueue.start();
final Task task = NoopTask.create();
task.addToContext(Tasks.FORCE_TIME_CHUNK_LOCK_KEY, false);
Assert.assertTrue(taskQueue.add(task));
taskQueue.stop();
final Optional<Task> optionalTask = taskStorage.getTask(task.getId());
Assert.assertTrue(optionalTask.isPresent());
final Task fromTaskStorage = optionalTask.get();
Assert.assertFalse(fromTaskStorage.getContextValue(Tasks.FORCE_TIME_CHUNK_LOCK_KEY));
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLockConfigTest method testDefault.
@Test
public void testDefault() throws EntryExistsException {
final TaskQueue taskQueue = createTaskQueue(null);
taskQueue.start();
final Task task = NoopTask.create();
Assert.assertTrue(taskQueue.add(task));
taskQueue.stop();
final Optional<Task> optionalTask = taskStorage.getTask(task.getId());
Assert.assertTrue(optionalTask.isPresent());
final Task fromTaskStorage = optionalTask.get();
Assert.assertTrue(fromTaskStorage.getContextValue(Tasks.FORCE_TIME_CHUNK_LOCK_KEY));
}
Aggregations