use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLockboxTest method testSyncFromStorageWithMissingTaskPriority.
@Test
public void testSyncFromStorageWithMissingTaskPriority() throws EntryExistsException {
final Task task = NoopTask.create();
taskStorage.insert(task, TaskStatus.running(task.getId()));
taskStorage.addLock(task.getId(), new TimeChunkLock(TaskLockType.EXCLUSIVE, task.getGroupId(), task.getDataSource(), Intervals.of("2017/2018"), "v1", task.getPriority()));
final List<TaskLock> beforeLocksInStorage = taskStorage.getActiveTasks().stream().flatMap(t -> taskStorage.getLocks(t.getId()).stream()).collect(Collectors.toList());
final TaskLockbox lockbox = new TaskLockbox(taskStorage, metadataStorageCoordinator);
lockbox.syncFromStorage();
final List<TaskLock> afterLocksInStorage = taskStorage.getActiveTasks().stream().flatMap(t -> taskStorage.getLocks(t.getId()).stream()).collect(Collectors.toList());
Assert.assertEquals(beforeLocksInStorage, afterLocksInStorage);
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLockboxTest method testSyncFromStorageWithInvalidPriority.
@Test
public void testSyncFromStorageWithInvalidPriority() throws EntryExistsException {
final Task task = NoopTask.create();
taskStorage.insert(task, TaskStatus.running(task.getId()));
taskStorage.addLock(task.getId(), new TimeChunkLock(TaskLockType.EXCLUSIVE, task.getGroupId(), task.getDataSource(), Intervals.of("2017/2018"), "v1", 10));
final TaskLockbox lockbox = new TaskLockbox(taskStorage, metadataStorageCoordinator);
expectedException.expect(IllegalArgumentException.class);
expectedException.expectMessage("lock priority[10] is different from task priority[50]");
lockbox.syncFromStorage();
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLockboxTest method testGetLockedIntervalsForEqualPriorityTask.
@Test
public void testGetLockedIntervalsForEqualPriorityTask() throws Exception {
// Acquire lock for a low priority task
final Task task = NoopTask.create(5);
lockbox.add(task);
taskStorage.insert(task, TaskStatus.running(task.getId()));
tryTimeChunkLock(TaskLockType.EXCLUSIVE, task, Intervals.of("2017/2018"));
final Map<String, Integer> minTaskPriority = new HashMap<>();
minTaskPriority.put(task.getDataSource(), 5);
Map<String, List<Interval>> lockedIntervals = lockbox.getLockedIntervals(minTaskPriority);
Assert.assertEquals(1, lockedIntervals.size());
Assert.assertEquals(Collections.singletonList(Intervals.of("2017/2018")), lockedIntervals.get(task.getDataSource()));
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLockboxTest method testRequestForNewSegmentWithHashPartition.
@Test
public void testRequestForNewSegmentWithHashPartition() {
final Task task = NoopTask.create();
lockbox.add(task);
allocateSegmentsAndAssert(task, "seq", 3, new HashBasedNumberedPartialShardSpec(null, 1, 3, null));
allocateSegmentsAndAssert(task, "seq2", 5, new HashBasedNumberedPartialShardSpec(null, 3, 5, null));
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class ForkingTaskRunnerTest method testTaskStatusWhenTaskProcessSucceedsTaskFails.
@Test
public void testTaskStatusWhenTaskProcessSucceedsTaskFails() throws ExecutionException, InterruptedException {
ObjectMapper mapper = new DefaultObjectMapper();
Task task = NoopTask.create();
ForkingTaskRunner forkingTaskRunner = new ForkingTaskRunner(new ForkingTaskRunnerConfig(), new TaskConfig(null, null, null, null, ImmutableList.of(), false, new Period("PT0S"), new Period("PT10S"), ImmutableList.of(), false, false, TaskConfig.BATCH_PROCESSING_MODE_DEFAULT.name()), new WorkerConfig(), new Properties(), new NoopTaskLogs(), mapper, new DruidNode("middleManager", "host", false, 8091, null, true, false), new StartupLoggingConfig()) {
@Override
ProcessHolder runTaskProcess(List<String> command, File logFile, TaskLocation taskLocation) throws IOException {
ProcessHolder processHolder = Mockito.mock(ProcessHolder.class);
Mockito.doNothing().when(processHolder).registerWithCloser(ArgumentMatchers.any());
Mockito.doNothing().when(processHolder).shutdown();
for (String param : command) {
if (param.endsWith("status.json")) {
mapper.writeValue(new File(param), TaskStatus.failure(task.getId(), "task failure test"));
break;
}
}
return processHolder;
}
@Override
int waitForTaskProcessToComplete(Task task, ProcessHolder processHolder, File logFile, File reportsFile) {
return 0;
}
};
final TaskStatus status = forkingTaskRunner.run(task).get();
Assert.assertEquals(TaskState.FAILED, status.getStatusCode());
Assert.assertEquals("task failure test", status.getErrorMsg());
}
Aggregations