Search in sources :

Example 46 with DruidServer

use of io.druid.client.DruidServer in project druid by druid-io.

the class BatchServerInventoryViewTest method testSameTimeZnode.

@Test
public void testSameTimeZnode() throws Exception {
    final int numThreads = INITIAL_SEGMENTS / 10;
    final ListeningExecutorService executor = MoreExecutors.listeningDecorator(Executors.newFixedThreadPool(numThreads));
    segmentAnnouncer.announceSegments(testSegments);
    waitForSync(batchServerInventoryView, testSegments);
    DruidServer server = Iterables.get(batchServerInventoryView.getInventory(), 0);
    final Set<DataSegment> segments = Sets.newHashSet(server.getSegments().values());
    Assert.assertEquals(testSegments, segments);
    final CountDownLatch latch = new CountDownLatch(numThreads);
    final List<ListenableFuture<BatchDataSegmentAnnouncer>> futures = new ArrayList<>();
    for (int i = 0; i < numThreads; ++i) {
        final int ii = i;
        futures.add(executor.submit(new Callable<BatchDataSegmentAnnouncer>() {

            @Override
            public BatchDataSegmentAnnouncer call() {
                BatchDataSegmentAnnouncer segmentAnnouncer = new BatchDataSegmentAnnouncer(new DruidServerMetadata("id", "host", Long.MAX_VALUE, "type", "tier", 0), new BatchDataSegmentAnnouncerConfig() {

                    @Override
                    public int getSegmentsPerNode() {
                        return 50;
                    }
                }, new ZkPathsConfig() {

                    @Override
                    public String getBase() {
                        return testBasePath;
                    }
                }, announcer, jsonMapper);
                segmentAnnouncer.start();
                List<DataSegment> segments = new ArrayList<DataSegment>();
                try {
                    for (int j = 0; j < INITIAL_SEGMENTS / numThreads; ++j) {
                        segments.add(makeSegment(INITIAL_SEGMENTS + ii + numThreads * j));
                    }
                    latch.countDown();
                    latch.await();
                    segmentAnnouncer.announceSegments(segments);
                    testSegments.addAll(segments);
                } catch (Exception e) {
                    throw Throwables.propagate(e);
                }
                return segmentAnnouncer;
            }
        }));
    }
    final List<BatchDataSegmentAnnouncer> announcers = Futures.<BatchDataSegmentAnnouncer>allAsList(futures).get();
    Assert.assertEquals(INITIAL_SEGMENTS * 2, testSegments.size());
    waitForSync(batchServerInventoryView, testSegments);
    Assert.assertEquals(testSegments, Sets.newHashSet(server.getSegments().values()));
    for (int i = 0; i < INITIAL_SEGMENTS; ++i) {
        final DataSegment segment = makeSegment(100 + i);
        segmentAnnouncer.unannounceSegment(segment);
        testSegments.remove(segment);
    }
    waitForSync(batchServerInventoryView, testSegments);
    Assert.assertEquals(testSegments, Sets.newHashSet(server.getSegments().values()));
}
Also used : ArrayList(java.util.ArrayList) BatchDataSegmentAnnouncerConfig(io.druid.server.initialization.BatchDataSegmentAnnouncerConfig) DruidServer(io.druid.client.DruidServer) DruidServerMetadata(io.druid.server.coordination.DruidServerMetadata) CountDownLatch(java.util.concurrent.CountDownLatch) DataSegment(io.druid.timeline.DataSegment) Callable(java.util.concurrent.Callable) ExpectedException(org.junit.rules.ExpectedException) ZkPathsConfig(io.druid.server.initialization.ZkPathsConfig) ListenableFuture(com.google.common.util.concurrent.ListenableFuture) ListeningExecutorService(com.google.common.util.concurrent.ListeningExecutorService) BatchDataSegmentAnnouncer(io.druid.server.coordination.BatchDataSegmentAnnouncer) Test(org.junit.Test)

Example 47 with DruidServer

use of io.druid.client.DruidServer in project druid by druid-io.

the class TierSelectorStrategyTest method testHighestPriorityTierSelectorStrategy.

@Test
public void testHighestPriorityTierSelectorStrategy() {
    DirectDruidClient client = EasyMock.createMock(DirectDruidClient.class);
    QueryableDruidServer lowPriority = new QueryableDruidServer(new DruidServer("test1", "localhost", 0, "historical", DruidServer.DEFAULT_TIER, 0), client);
    QueryableDruidServer highPriority = new QueryableDruidServer(new DruidServer("test1", "localhost", 0, "historical", DruidServer.DEFAULT_TIER, 1), client);
    testTierSelectorStrategy(new HighestPriorityTierSelectorStrategy(new ConnectionCountServerSelectorStrategy()), highPriority, lowPriority);
}
Also used : DirectDruidClient(io.druid.client.DirectDruidClient) DruidServer(io.druid.client.DruidServer) Test(org.junit.Test)

Aggregations

DruidServer (io.druid.client.DruidServer)47 DataSegment (io.druid.timeline.DataSegment)36 Test (org.junit.Test)30 Interval (org.joda.time.Interval)25 DateTime (org.joda.time.DateTime)20 ListeningExecutorService (com.google.common.util.concurrent.ListeningExecutorService)18 ForeverLoadRule (io.druid.server.coordinator.rules.ForeverLoadRule)15 Rule (io.druid.server.coordinator.rules.Rule)15 IntervalDropRule (io.druid.server.coordinator.rules.IntervalDropRule)14 IntervalLoadRule (io.druid.server.coordinator.rules.IntervalLoadRule)14 ServiceEventBuilder (com.metamx.emitter.service.ServiceEventBuilder)11 Map (java.util.Map)11 DruidDataSource (io.druid.client.DruidDataSource)7 ImmutableMap (com.google.common.collect.ImmutableMap)6 Response (javax.ws.rs.core.Response)6 ImmutableDruidServer (io.druid.client.ImmutableDruidServer)5 DruidServerMetadata (io.druid.server.coordination.DruidServerMetadata)5 GET (javax.ws.rs.GET)5 Produces (javax.ws.rs.Produces)5 BalancerStrategy (io.druid.server.coordinator.BalancerStrategy)4