Search in sources :

Example 16 with DruidDataSource

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);
}
Also used : HttpServletRequest(javax.servlet.http.HttpServletRequest) SegmentsMetadataManager(org.apache.druid.metadata.SegmentsMetadataManager) DruidServer(org.apache.druid.client.DruidServer) CoordinatorServerView(org.apache.druid.client.CoordinatorServerView) DataSegment(org.apache.druid.timeline.DataSegment) DruidDataSource(org.apache.druid.client.DruidDataSource) ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) Before(org.junit.Before)

Example 17 with DruidDataSource

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);
}
Also used : Response(javax.ws.rs.core.Response) DruidDataSource(org.apache.druid.client.DruidDataSource) ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) Test(org.junit.Test)

Example 18 with DruidDataSource

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);
}
Also used : Response(javax.ws.rs.core.Response) SegmentId(org.apache.druid.timeline.SegmentId) DruidDataSource(org.apache.druid.client.DruidDataSource) ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) Test(org.junit.Test)

Example 19 with DruidDataSource

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);
}
Also used : Response(javax.ws.rs.core.Response) DruidDataSource(org.apache.druid.client.DruidDataSource) ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) Interval(org.joda.time.Interval) Test(org.junit.Test)

Example 20 with DruidDataSource

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);
}
Also used : Response(javax.ws.rs.core.Response) SegmentId(org.apache.druid.timeline.SegmentId) DruidDataSource(org.apache.druid.client.DruidDataSource) ImmutableDruidDataSource(org.apache.druid.client.ImmutableDruidDataSource) Test(org.junit.Test)

Aggregations

DruidDataSource (org.apache.druid.client.DruidDataSource)22 ImmutableDruidDataSource (org.apache.druid.client.ImmutableDruidDataSource)21 Test (org.junit.Test)17 Response (javax.ws.rs.core.Response)14 DataSegment (org.apache.druid.timeline.DataSegment)10 DruidServer (org.apache.druid.client.DruidServer)7 Interval (org.joda.time.Interval)7 Object2LongMap (it.unimi.dsi.fastutil.objects.Object2LongMap)5 SegmentId (org.apache.druid.timeline.SegmentId)5 HashMap (java.util.HashMap)4 CountDownLatch (java.util.concurrent.CountDownLatch)4 ImmutableDruidServer (org.apache.druid.client.ImmutableDruidServer)4 Map (java.util.Map)3 TreeMap (java.util.TreeMap)3 ForeverBroadcastDistributionRule (org.apache.druid.server.coordinator.rules.ForeverBroadcastDistributionRule)3 ForeverLoadRule (org.apache.druid.server.coordinator.rules.ForeverLoadRule)3 IntervalLoadRule (org.apache.druid.server.coordinator.rules.IntervalLoadRule)3 Rule (org.apache.druid.server.coordinator.rules.Rule)3 ImmutableMap (com.google.common.collect.ImmutableMap)2 EnumMap (java.util.EnumMap)2