use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLockboxTest method testSegmentAndTimeChunkLockForSameInterval.
@Test
public void testSegmentAndTimeChunkLockForSameInterval() {
final Task task1 = NoopTask.create();
lockbox.add(task1);
final Task task2 = NoopTask.create();
lockbox.add(task2);
Assert.assertTrue(lockbox.tryLock(task1, new SpecificSegmentLockRequest(TaskLockType.EXCLUSIVE, task1, Intervals.of("2015-01-01/2015-01-02"), "v1", 3)).isOk());
Assert.assertFalse(lockbox.tryLock(task2, new TimeChunkLockRequest(TaskLockType.EXCLUSIVE, task2, Intervals.of("2015-01-01/2015-01-02"), "v1")).isOk());
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLockboxTest method testSegmentLock.
@Test
public void testSegmentLock() throws InterruptedException {
final Task task = NoopTask.create();
lockbox.add(task);
final LockResult lockResult = lockbox.lock(task, new SpecificSegmentLockRequest(TaskLockType.EXCLUSIVE, task, Intervals.of("2015-01-01/2015-01-02"), "v1", 3));
Assert.assertTrue(lockResult.isOk());
Assert.assertNull(lockResult.getNewSegmentId());
Assert.assertTrue(lockResult.getTaskLock() instanceof SegmentLock);
final SegmentLock segmentLock = (SegmentLock) lockResult.getTaskLock();
Assert.assertEquals(TaskLockType.EXCLUSIVE, segmentLock.getType());
Assert.assertEquals(task.getGroupId(), segmentLock.getGroupId());
Assert.assertEquals(task.getDataSource(), segmentLock.getDataSource());
Assert.assertEquals(Intervals.of("2015-01-01/2015-01-02"), segmentLock.getInterval());
Assert.assertEquals("v1", segmentLock.getVersion());
Assert.assertEquals(3, segmentLock.getPartitionId());
Assert.assertEquals(task.getPriority(), segmentLock.getPriority().intValue());
Assert.assertFalse(segmentLock.isRevoked());
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLockboxTest method testSegmentAndTimeChunkLockForSameIntervalWithDifferentPriority.
@Test
public void testSegmentAndTimeChunkLockForSameIntervalWithDifferentPriority() throws EntryExistsException {
final Task task1 = NoopTask.create(10);
lockbox.add(task1);
taskStorage.insert(task1, TaskStatus.running(task1.getId()));
final Task task2 = NoopTask.create(100);
lockbox.add(task2);
taskStorage.insert(task2, TaskStatus.running(task2.getId()));
Assert.assertTrue(lockbox.tryLock(task1, new SpecificSegmentLockRequest(TaskLockType.EXCLUSIVE, task1, Intervals.of("2015-01-01/2015-01-02"), "v1", 3)).isOk());
Assert.assertTrue(lockbox.tryLock(task2, new TimeChunkLockRequest(TaskLockType.EXCLUSIVE, task2, Intervals.of("2015-01-01/2015-01-02"), "v1")).isOk());
final LockResult resultOfTask1 = lockbox.tryLock(task1, new SpecificSegmentLockRequest(TaskLockType.EXCLUSIVE, task1, Intervals.of("2015-01-01/2015-01-02"), "v1", 3));
Assert.assertFalse(resultOfTask1.isOk());
Assert.assertTrue(resultOfTask1.isRevoked());
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLockboxTest method testTrySharedLock.
@Test
public void testTrySharedLock() {
final Interval interval = Intervals.of("2017-01/2017-02");
final List<Task> tasks = new ArrayList<>();
final Set<TaskLock> actualLocks = new HashSet<>();
// test creating new locks
for (int i = 0; i < 5; i++) {
// the first two tasks have the same priority
final Task task = NoopTask.create(Math.min(0, (i - 1) * 10));
tasks.add(task);
lockbox.add(task);
final TaskLock lock = tryTimeChunkLock(TaskLockType.SHARED, task, interval).getTaskLock();
Assert.assertNotNull(lock);
actualLocks.add(lock);
}
Assert.assertEquals(5, getAllLocks(tasks).size());
Assert.assertEquals(getAllLocks(tasks), actualLocks);
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLockboxTest method testRevokedLockSyncFromStorage.
@Test
public void testRevokedLockSyncFromStorage() throws EntryExistsException {
final TaskLockbox originalBox = new TaskLockbox(taskStorage, metadataStorageCoordinator);
final Task task1 = NoopTask.create("task1", 10);
taskStorage.insert(task1, TaskStatus.running(task1.getId()));
originalBox.add(task1);
Assert.assertTrue(originalBox.tryLock(task1, new TimeChunkLockRequest(TaskLockType.EXCLUSIVE, task1, Intervals.of("2017/2018"), null)).isOk());
// task2 revokes task1
final Task task2 = NoopTask.create("task2", 100);
taskStorage.insert(task2, TaskStatus.running(task2.getId()));
originalBox.add(task2);
Assert.assertTrue(originalBox.tryLock(task2, new TimeChunkLockRequest(TaskLockType.EXCLUSIVE, task2, Intervals.of("2017/2018"), null)).isOk());
final Map<String, List<TaskLock>> beforeLocksInStorage = taskStorage.getActiveTasks().stream().collect(Collectors.toMap(Task::getId, task -> taskStorage.getLocks(task.getId())));
final List<TaskLock> task1Locks = beforeLocksInStorage.get("task1");
Assert.assertEquals(1, task1Locks.size());
Assert.assertTrue(task1Locks.get(0).isRevoked());
final List<TaskLock> task2Locks = beforeLocksInStorage.get("task1");
Assert.assertEquals(1, task2Locks.size());
Assert.assertTrue(task2Locks.get(0).isRevoked());
final TaskLockbox newBox = new TaskLockbox(taskStorage, metadataStorageCoordinator);
newBox.syncFromStorage();
final Set<TaskLock> afterLocksInStorage = taskStorage.getActiveTasks().stream().flatMap(task -> taskStorage.getLocks(task.getId()).stream()).collect(Collectors.toSet());
Assert.assertEquals(beforeLocksInStorage.values().stream().flatMap(Collection::stream).collect(Collectors.toSet()), afterLocksInStorage);
}
Aggregations