use of org.apache.druid.client.DruidDataSource in project druid by druid-io.
the class DataSourcesResourceTest method setUp.
@Before
public void setUp() {
request = EasyMock.createStrictMock(HttpServletRequest.class);
inventoryView = EasyMock.createStrictMock(CoordinatorServerView.class);
server = EasyMock.niceMock(DruidServer.class);
dataSegmentList = new ArrayList<>();
dataSegmentList.add(new DataSegment("datasource1", Intervals.of("2010-01-01/P1D"), "v0", null, null, null, null, 0x9, 10));
dataSegmentList.add(new DataSegment("datasource1", Intervals.of("2010-01-22/P1D"), "v0", null, null, null, null, 0x9, 20));
dataSegmentList.add(new DataSegment("datasource2", Intervals.of("2010-01-01/P1D"), "v0", null, null, null, null, 0x9, 30));
listDataSources = new ArrayList<>();
listDataSources.add(new DruidDataSource("datasource1", new HashMap<>()).addSegment(dataSegmentList.get(0)));
listDataSources.add(new DruidDataSource("datasource2", new HashMap<>()).addSegment(dataSegmentList.get(1)));
segmentsMetadataManager = EasyMock.createMock(SegmentsMetadataManager.class);
}
use of org.apache.druid.client.DruidDataSource in project druid by druid-io.
the class DataSourcesResourceTest method testMarkAsUsedNonOvershadowedSegmentsSet.
@Test
public void testMarkAsUsedNonOvershadowedSegmentsSet() throws UnknownSegmentIdsException {
DruidDataSource dataSource = new DruidDataSource("datasource1", new HashMap<>());
Set<String> segmentIds = ImmutableSet.of(dataSegmentList.get(1).getId().toString());
int numUpdatedSegments = segmentsMetadataManager.markAsUsedNonOvershadowedSegments(EasyMock.eq("datasource1"), EasyMock.eq(segmentIds));
EasyMock.expect(numUpdatedSegments).andReturn(3).once();
EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).once();
EasyMock.expect(server.getDataSource("datasource1")).andReturn(dataSource).once();
EasyMock.replay(segmentsMetadataManager, inventoryView, server);
DataSourcesResource dataSourcesResource = new DataSourcesResource(inventoryView, segmentsMetadataManager, null, null, null, null);
Response response = dataSourcesResource.markAsUsedNonOvershadowedSegments("datasource1", new DataSourcesResource.MarkDataSourceSegmentsPayload(null, segmentIds));
Assert.assertEquals(200, response.getStatus());
EasyMock.verify(segmentsMetadataManager, inventoryView, server);
}
use of org.apache.druid.client.DruidDataSource in project druid by druid-io.
the class DataSourcesResourceTest method testMarkSegmentsAsUnused.
@Test
public void testMarkSegmentsAsUnused() {
final DruidDataSource dataSource1 = new DruidDataSource("datasource1", new HashMap<>());
final Set<SegmentId> segmentIds = dataSegmentList.stream().filter(segment -> segment.getDataSource().equals(dataSource1.getName())).map(DataSegment::getId).collect(Collectors.toSet());
EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).once();
EasyMock.expect(server.getDataSource("datasource1")).andReturn(dataSource1).once();
EasyMock.expect(segmentsMetadataManager.markSegmentsAsUnused(segmentIds)).andReturn(1).once();
EasyMock.replay(segmentsMetadataManager, inventoryView, server);
final DataSourcesResource.MarkDataSourceSegmentsPayload payload = new DataSourcesResource.MarkDataSourceSegmentsPayload(null, segmentIds.stream().map(SegmentId::toString).collect(Collectors.toSet()));
DataSourcesResource dataSourcesResource = new DataSourcesResource(inventoryView, segmentsMetadataManager, null, null, null, null);
Response response = dataSourcesResource.markSegmentsAsUnused("datasource1", payload);
Assert.assertEquals(200, response.getStatus());
Assert.assertEquals(ImmutableMap.of("numChangedSegments", 1), response.getEntity());
EasyMock.verify(segmentsMetadataManager, inventoryView, server);
}
use of org.apache.druid.client.DruidDataSource in project druid by druid-io.
the class DataSourcesResourceTest method testMarkAsUsedNonOvershadowedSegmentsInterval.
@Test
public void testMarkAsUsedNonOvershadowedSegmentsInterval() {
DruidDataSource dataSource = new DruidDataSource("datasource1", new HashMap<>());
Interval interval = Intervals.of("2010-01-22/P1D");
int numUpdatedSegments = segmentsMetadataManager.markAsUsedNonOvershadowedSegmentsInInterval(EasyMock.eq("datasource1"), EasyMock.eq(interval));
EasyMock.expect(numUpdatedSegments).andReturn(3).once();
EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).once();
EasyMock.expect(server.getDataSource("datasource1")).andReturn(dataSource).once();
EasyMock.replay(segmentsMetadataManager, inventoryView, server);
DataSourcesResource dataSourcesResource = new DataSourcesResource(inventoryView, segmentsMetadataManager, null, null, null, null);
Response response = dataSourcesResource.markAsUsedNonOvershadowedSegments("datasource1", new DataSourcesResource.MarkDataSourceSegmentsPayload(interval, null));
Assert.assertEquals(200, response.getStatus());
EasyMock.verify(segmentsMetadataManager, inventoryView, server);
}
use of org.apache.druid.client.DruidDataSource in project druid by druid-io.
the class DataSourcesResourceTest method testMarkSegmentsAsUnusedException.
@Test
public void testMarkSegmentsAsUnusedException() {
final DruidDataSource dataSource1 = new DruidDataSource("datasource1", new HashMap<>());
final Set<SegmentId> segmentIds = dataSegmentList.stream().filter(segment -> segment.getDataSource().equals(dataSource1.getName())).map(DataSegment::getId).collect(Collectors.toSet());
EasyMock.expect(inventoryView.getInventory()).andReturn(ImmutableList.of(server)).once();
EasyMock.expect(server.getDataSource("datasource1")).andReturn(dataSource1).once();
EasyMock.expect(segmentsMetadataManager.markSegmentsAsUnused(segmentIds)).andThrow(new RuntimeException("Exception occurred")).once();
EasyMock.replay(segmentsMetadataManager, inventoryView, server);
final DataSourcesResource.MarkDataSourceSegmentsPayload payload = new DataSourcesResource.MarkDataSourceSegmentsPayload(null, segmentIds.stream().map(SegmentId::toString).collect(Collectors.toSet()));
DataSourcesResource dataSourcesResource = new DataSourcesResource(inventoryView, segmentsMetadataManager, null, null, null, null);
Response response = dataSourcesResource.markSegmentsAsUnused("datasource1", payload);
Assert.assertEquals(500, response.getStatus());
Assert.assertNotNull(response.getEntity());
EasyMock.verify(segmentsMetadataManager, inventoryView, server);
}
Aggregations