use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TaskLocksTest method testCheckSegmentLockCoversSegments.
@Test
public void testCheckSegmentLockCoversSegments() {
final Set<DataSegment> segments = createNumberedPartitionedSegments();
final Interval interval = Intervals.of("2017-01-01/2017-01-02");
final String version = DateTimes.nowUtc().toString();
final List<TaskLock> locks = IntStream.range(0, 5).mapToObj(partitionId -> {
final TaskLock lock = trySegmentLock(task, interval, version, partitionId).getTaskLock();
Assert.assertNotNull(lock);
return lock;
}).collect(Collectors.toList());
Assert.assertEquals(5, locks.size());
Assert.assertTrue(TaskLocks.isLockCoversSegments(task, lockbox, segments));
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class TimeChunkLockTryAcquireActionTest method testWithLockType.
@Test(timeout = 60_000L)
public void testWithLockType() {
final Task task = NoopTask.create();
final TimeChunkLockTryAcquireAction action = new TimeChunkLockTryAcquireAction(TaskLockType.EXCLUSIVE, Intervals.of("2017-01-01/2017-01-02"));
actionTestKit.getTaskLockbox().add(task);
final TaskLock lock = action.perform(task, actionTestKit.getTaskActionToolbox());
Assert.assertNotNull(lock);
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class SegmentTransactionalInsertActionTest method testFailBadVersion.
@Test
public void testFailBadVersion() throws Exception {
final Task task = NoopTask.create();
final SegmentTransactionalInsertAction action = SegmentTransactionalInsertAction.overwriteAction(null, null, ImmutableSet.of(SEGMENT3));
actionTestKit.getTaskLockbox().add(task);
acquireTimeChunkLock(TaskLockType.EXCLUSIVE, task, INTERVAL, 5000);
thrown.expect(IllegalStateException.class);
thrown.expectMessage(CoreMatchers.containsString("are not covered by locks"));
SegmentPublishResult result = action.perform(task, actionTestKit.getTaskActionToolbox());
Assert.assertEquals(SegmentPublishResult.ok(ImmutableSet.of(SEGMENT3)), result);
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class SegmentTransactionalInsertActionTest method testFailTransactionalDropSegment.
@Test
public void testFailTransactionalDropSegment() throws Exception {
final Task task = NoopTask.create();
actionTestKit.getTaskLockbox().add(task);
acquireTimeChunkLock(TaskLockType.EXCLUSIVE, task, INTERVAL, 5000);
SegmentPublishResult result = SegmentTransactionalInsertAction.overwriteAction(null, // SEGMENT1 does not exist, hence will fail to drop
ImmutableSet.of(SEGMENT1), ImmutableSet.of(SEGMENT2)).perform(task, actionTestKit.getTaskActionToolbox());
Assert.assertEquals(SegmentPublishResult.fail("org.apache.druid.metadata.RetryTransactionException: Aborting transaction!"), result);
}
use of org.apache.druid.indexing.common.task.Task in project druid by druid-io.
the class SegmentTransactionalInsertActionTest method testTransactionalUpdateDataSourceMetadata.
@Test
public void testTransactionalUpdateDataSourceMetadata() throws Exception {
final Task task = NoopTask.create();
actionTestKit.getTaskLockbox().add(task);
acquireTimeChunkLock(TaskLockType.EXCLUSIVE, task, INTERVAL, 5000);
SegmentPublishResult result1 = SegmentTransactionalInsertAction.appendAction(ImmutableSet.of(SEGMENT1), new ObjectMetadata(null), new ObjectMetadata(ImmutableList.of(1))).perform(task, actionTestKit.getTaskActionToolbox());
Assert.assertEquals(SegmentPublishResult.ok(ImmutableSet.of(SEGMENT1)), result1);
SegmentPublishResult result2 = SegmentTransactionalInsertAction.appendAction(ImmutableSet.of(SEGMENT2), new ObjectMetadata(ImmutableList.of(1)), new ObjectMetadata(ImmutableList.of(2))).perform(task, actionTestKit.getTaskActionToolbox());
Assert.assertEquals(SegmentPublishResult.ok(ImmutableSet.of(SEGMENT2)), result2);
Assertions.assertThat(actionTestKit.getMetadataStorageCoordinator().retrieveUsedSegmentsForInterval(DATA_SOURCE, INTERVAL, Segments.ONLY_VISIBLE)).containsExactlyInAnyOrder(SEGMENT1, SEGMENT2);
Assert.assertEquals(new ObjectMetadata(ImmutableList.of(2)), actionTestKit.getMetadataStorageCoordinator().retrieveDataSourceMetadata(DATA_SOURCE));
}
Aggregations