Search in sources :

Example 11 with ZkPathsConfig

use of io.druid.server.initialization.ZkPathsConfig in project druid by druid-io.

the class ListenerDiscovererTest method testFullService.

@Test(timeout = 60_000L)
public void testFullService() throws Exception {
    final String listenerKey = "listenerKey";
    final String listenerTier = "listenerTier";
    final String listenerTierChild = "tierChild";
    final String tierZkPath = ZKPaths.makePath(listenerTier, listenerTierChild);
    setupServerAndCurator();
    final ExecutorService executorService = Execs.singleThreaded("listenerDiscovererTest--%s");
    closerRule.closeLater(new Closeable() {

        @Override
        public void close() throws IOException {
            executorService.shutdownNow();
        }
    });
    closerRule.closeLater(server);
    closerRule.closeLater(curator);
    curator.start();
    curator.blockUntilConnected(10, TimeUnit.SECONDS);
    Assert.assertEquals("/druid", curator.create().forPath("/druid"));
    final Announcer announcer = new Announcer(curator, executorService);
    closerRule.closeLater(new Closeable() {

        @Override
        public void close() throws IOException {
            announcer.stop();
        }
    });
    final ListeningAnnouncerConfig config = new ListeningAnnouncerConfig(new ZkPathsConfig());
    final ListenerDiscoverer listenerDiscoverer = new ListenerDiscoverer(curator, config);
    listenerDiscoverer.start();
    closerRule.closeLater(new Closeable() {

        @Override
        public void close() throws IOException {
            listenerDiscoverer.stop();
        }
    });
    Assert.assertTrue(listenerDiscoverer.getNodes(listenerKey).isEmpty());
    final HostAndPort node = HostAndPort.fromParts("someHost", 8888);
    final ListenerResourceAnnouncer listenerResourceAnnouncer = new ListenerResourceAnnouncer(announcer, config, listenerKey, node) {
    };
    listenerResourceAnnouncer.start();
    closerRule.closeLater(new Closeable() {

        @Override
        public void close() throws IOException {
            listenerResourceAnnouncer.stop();
        }
    });
    final ListenerResourceAnnouncer tieredListenerResourceAnnouncer = new ListenerResourceAnnouncer(announcer, config, tierZkPath, node) {
    };
    tieredListenerResourceAnnouncer.start();
    closerRule.closeLater(new Closeable() {

        @Override
        public void close() throws IOException {
            tieredListenerResourceAnnouncer.stop();
        }
    });
    announcer.start();
    Assert.assertNotNull(curator.checkExists().forPath(config.getAnnouncementPath(listenerKey)));
    // Have to wait for background syncing
    while (listenerDiscoverer.getNodes(listenerKey).isEmpty()) {
        // Will timeout at test's timeout setting
        Thread.sleep(1);
    }
    Assert.assertEquals(ImmutableSet.of(HostAndPort.fromString(node.toString())), listenerDiscoverer.getNodes(listenerKey));
    // 2nd call of two concurrent getNewNodes should return no entry collection
    listenerDiscoverer.getNewNodes(listenerKey);
    Assert.assertEquals(0, listenerDiscoverer.getNewNodes(listenerKey).size());
    Assert.assertEquals(ImmutableSet.of(listenerKey, listenerTier), ImmutableSet.copyOf(listenerDiscoverer.discoverChildren(null)));
    Assert.assertEquals(ImmutableSet.of(listenerTierChild), ImmutableSet.copyOf(listenerDiscoverer.discoverChildren(listenerTier)));
}
Also used : HostAndPort(com.google.common.net.HostAndPort) Announcer(io.druid.curator.announcement.Announcer) ZkPathsConfig(io.druid.server.initialization.ZkPathsConfig) Closeable(java.io.Closeable) ExecutorService(java.util.concurrent.ExecutorService) IOException(java.io.IOException) Test(org.junit.Test)

Example 12 with ZkPathsConfig

use of io.druid.server.initialization.ZkPathsConfig 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 13 with ZkPathsConfig

use of io.druid.server.initialization.ZkPathsConfig in project druid by druid-io.

the class ZkPathsConfigTest method testOverrideBaseOnlyConfig.

@Test
public void testOverrideBaseOnlyConfig() throws IllegalAccessException, NoSuchMethodException, InvocationTargetException, IOException {
    JsonConfigurator configurator = injector.getBinding(JsonConfigurator.class).getProvider().get();
    JsonConfigProvider<ZkPathsConfig> zkPathsConfig = JsonConfigProvider.of(configPrefix, ZkPathsConfig.class);
    testProperties.clear();
    String base = UUID.randomUUID().toString();
    testProperties.put(String.format("%s.base", configPrefix), base);
    zkPathsConfig.inject(testProperties, configurator);
    propertyValues.clear();
    propertyValues.put(String.format("%s.base", configPrefix), base);
    propertyValues.put(String.format("%s.propertiesPath", configPrefix), ZKPaths.makePath(base, "properties"));
    propertyValues.put(String.format("%s.announcementsPath", configPrefix), ZKPaths.makePath(base, "announcements"));
    propertyValues.put(String.format("%s.servedSegmentsPath", configPrefix), ZKPaths.makePath(base, "servedSegments"));
    propertyValues.put(String.format("%s.liveSegmentsPath", configPrefix), ZKPaths.makePath(base, "segments"));
    propertyValues.put(String.format("%s.coordinatorPath", configPrefix), ZKPaths.makePath(base, "coordinator"));
    propertyValues.put(String.format("%s.loadQueuePath", configPrefix), ZKPaths.makePath(base, "loadQueue"));
    propertyValues.put(String.format("%s.connectorPath", configPrefix), ZKPaths.makePath(base, "connector"));
    ZkPathsConfig zkPathsConfigObj = zkPathsConfig.get().get();
    validateEntries(zkPathsConfigObj);
    Assert.assertEquals(propertyValues.size(), assertions);
    ObjectMapper jsonMapper = injector.getProvider(Key.get(ObjectMapper.class, Json.class)).get();
    String jsonVersion = jsonMapper.writeValueAsString(zkPathsConfigObj);
    ZkPathsConfig zkPathsConfigObjDeSer = jsonMapper.readValue(jsonVersion, ZkPathsConfig.class);
    Assert.assertEquals(zkPathsConfigObj, zkPathsConfigObjDeSer);
}
Also used : ZkPathsConfig(io.druid.server.initialization.ZkPathsConfig) JsonConfigurator(io.druid.guice.JsonConfigurator) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) Test(org.junit.Test)

Aggregations

ZkPathsConfig (io.druid.server.initialization.ZkPathsConfig)13 Before (org.junit.Before)7 IndexerZkConfig (io.druid.server.initialization.IndexerZkConfig)5 Test (org.junit.Test)5 PotentiallyGzippedCompressionProvider (io.druid.curator.PotentiallyGzippedCompressionProvider)4 Announcer (io.druid.curator.announcement.Announcer)4 DataSegment (io.druid.timeline.DataSegment)4 DruidServer (io.druid.client.DruidServer)3 DefaultObjectMapper (io.druid.jackson.DefaultObjectMapper)3 BatchDataSegmentAnnouncerConfig (io.druid.server.initialization.BatchDataSegmentAnnouncerConfig)3 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)3 TestingCluster (org.apache.curator.test.TestingCluster)3 NoopServiceAnnouncer (io.druid.curator.discovery.NoopServiceAnnouncer)2 RemoteTaskRunnerConfig (io.druid.indexing.overlord.config.RemoteTaskRunnerConfig)2 ScheduledExecutorFactory (io.druid.java.util.common.concurrent.ScheduledExecutorFactory)2 BatchDataSegmentAnnouncer (io.druid.server.coordination.BatchDataSegmentAnnouncer)2 DruidServerMetadata (io.druid.server.coordination.DruidServerMetadata)2 NoopServiceEmitter (io.druid.server.metrics.NoopServiceEmitter)2 IOException (java.io.IOException)2 CountDownLatch (java.util.concurrent.CountDownLatch)2