use of org.apache.druid.indexing.overlord.ObjectMetadata in project druid by druid-io.
the class IndexerSQLMetadataStorageCoordinatorTest method testTransactionalAnnounceFailDbNotNullWantNull.
@Test
public void testTransactionalAnnounceFailDbNotNullWantNull() throws IOException {
final SegmentPublishResult result1 = coordinator.announceHistoricalSegments(ImmutableSet.of(defaultSegment), ImmutableSet.of(), new ObjectMetadata(null), new ObjectMetadata(ImmutableMap.of("foo", "baz")));
Assert.assertEquals(SegmentPublishResult.ok(ImmutableSet.of(defaultSegment)), result1);
final SegmentPublishResult result2 = coordinator.announceHistoricalSegments(ImmutableSet.of(defaultSegment2), ImmutableSet.of(), new ObjectMetadata(null), new ObjectMetadata(ImmutableMap.of("foo", "baz")));
Assert.assertEquals(SegmentPublishResult.fail("java.lang.RuntimeException: Aborting transaction!"), result2);
// Should only be tried once per call.
Assert.assertEquals(2, metadataUpdateCounter.get());
}
use of org.apache.druid.indexing.overlord.ObjectMetadata in project druid by druid-io.
the class IndexerSQLMetadataStorageCoordinatorTest method testTransactionalAnnounceSuccess.
@Test
public void testTransactionalAnnounceSuccess() throws IOException {
// Insert first segment.
final SegmentPublishResult result1 = coordinator.announceHistoricalSegments(ImmutableSet.of(defaultSegment), ImmutableSet.of(), new ObjectMetadata(null), new ObjectMetadata(ImmutableMap.of("foo", "bar")));
Assert.assertEquals(SegmentPublishResult.ok(ImmutableSet.of(defaultSegment)), result1);
Assert.assertArrayEquals(mapper.writeValueAsString(defaultSegment).getBytes(StandardCharsets.UTF_8), derbyConnector.lookup(derbyConnectorRule.metadataTablesConfigSupplier().get().getSegmentsTable(), "id", "payload", defaultSegment.getId().toString()));
// Insert second segment.
final SegmentPublishResult result2 = coordinator.announceHistoricalSegments(ImmutableSet.of(defaultSegment2), ImmutableSet.of(), new ObjectMetadata(ImmutableMap.of("foo", "bar")), new ObjectMetadata(ImmutableMap.of("foo", "baz")));
Assert.assertEquals(SegmentPublishResult.ok(ImmutableSet.of(defaultSegment2)), result2);
Assert.assertArrayEquals(mapper.writeValueAsString(defaultSegment2).getBytes(StandardCharsets.UTF_8), derbyConnector.lookup(derbyConnectorRule.metadataTablesConfigSupplier().get().getSegmentsTable(), "id", "payload", defaultSegment2.getId().toString()));
// Examine metadata.
Assert.assertEquals(new ObjectMetadata(ImmutableMap.of("foo", "baz")), coordinator.retrieveDataSourceMetadata("fooDataSource"));
// Should only be tried once per call.
Assert.assertEquals(2, metadataUpdateCounter.get());
}
use of org.apache.druid.indexing.overlord.ObjectMetadata in project druid by druid-io.
the class IndexerSQLMetadataStorageCoordinatorTest method testRemoveDataSourceMetadataOlderThanDatasourceActiveShouldNotBeDeleted.
@Test
public void testRemoveDataSourceMetadataOlderThanDatasourceActiveShouldNotBeDeleted() throws Exception {
coordinator.announceHistoricalSegments(ImmutableSet.of(defaultSegment), ImmutableSet.of(), new ObjectMetadata(null), new ObjectMetadata(ImmutableMap.of("foo", "bar")));
Assert.assertEquals(new ObjectMetadata(ImmutableMap.of("foo", "bar")), coordinator.retrieveDataSourceMetadata("fooDataSource"));
// Try delete. Datasource should not be deleted as it is in excluded set
int deletedCount = coordinator.removeDataSourceMetadataOlderThan(System.currentTimeMillis(), ImmutableSet.of("fooDataSource"));
// Datasource should not be deleted
Assert.assertEquals(new ObjectMetadata(ImmutableMap.of("foo", "bar")), coordinator.retrieveDataSourceMetadata("fooDataSource"));
Assert.assertEquals(0, deletedCount);
}
use of org.apache.druid.indexing.overlord.ObjectMetadata 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));
}
use of org.apache.druid.indexing.overlord.ObjectMetadata in project druid by druid-io.
the class SegmentTransactionalInsertActionTest method testFailTransactionalUpdateDataSourceMetadata.
@Test
public void testFailTransactionalUpdateDataSourceMetadata() throws Exception {
final Task task = NoopTask.create();
actionTestKit.getTaskLockbox().add(task);
acquireTimeChunkLock(TaskLockType.EXCLUSIVE, task, INTERVAL, 5000);
SegmentPublishResult result = SegmentTransactionalInsertAction.appendAction(ImmutableSet.of(SEGMENT1), new ObjectMetadata(ImmutableList.of(1)), new ObjectMetadata(ImmutableList.of(2))).perform(task, actionTestKit.getTaskActionToolbox());
Assert.assertEquals(SegmentPublishResult.fail("java.lang.RuntimeException: Aborting transaction!"), result);
}
Aggregations