Search in sources :

Example 56 with TestingCluster

use of org.apache.curator.test.TestingCluster in project curator by apache.

the class TestReconfiguration method testAddWithoutEnsembleTracker.

@Test
public void testAddWithoutEnsembleTracker() throws Exception {
    final String initialClusterCS = cluster.getConnectString();
    try (CuratorFramework client = newClient(cluster.getConnectString(), false)) {
        assertEquals(((CuratorFrameworkImpl) client).getEnsembleTracker(), null);
        client.start();
        QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble());
        assertConfig(oldConfig, cluster.getInstances());
        CountDownLatch latch = setChangeWaiter(client);
        try (TestingCluster newCluster = new TestingCluster(TestingCluster.makeSpecs(1, false))) {
            newCluster.start();
            client.reconfig().joining(toReconfigSpec(newCluster.getInstances())).fromConfig(oldConfig.getVersion()).forEnsemble();
            assertTrue(timing.awaitLatch(latch));
            byte[] newConfigData = client.getConfig().forEnsemble();
            QuorumVerifier newConfig = toQuorumVerifier(newConfigData);
            List<InstanceSpec> newInstances = Lists.newArrayList(cluster.getInstances());
            newInstances.addAll(newCluster.getInstances());
            assertConfig(newConfig, newInstances);
            assertEquals(ensembleProvider.getConnectionString(), initialClusterCS);
            assertNotEquals(EnsembleTracker.configToConnectionString(newConfig), ensembleProvider.getConnectionString());
            assertEquals(client.getZookeeperClient().getCurrentConnectionString(), initialClusterCS);
            final CountDownLatch reconnectLatch = new CountDownLatch(1);
            client.getConnectionStateListenable().addListener((cfClient, newState) -> {
                if (newState == ConnectionState.RECONNECTED)
                    reconnectLatch.countDown();
            });
            client.getZookeeperClient().getZooKeeper().getTestable().injectSessionExpiration();
            assertTrue(reconnectLatch.await(2, TimeUnit.SECONDS));
            assertEquals(client.getZookeeperClient().getCurrentConnectionString(), initialClusterCS);
            assertEquals(ensembleProvider.getConnectionString(), initialClusterCS);
            newConfigData = client.getConfig().forEnsemble();
            assertNotEquals(EnsembleTracker.configToConnectionString(newConfig), ensembleProvider.getConnectionString());
        }
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) InstanceSpec(org.apache.curator.test.InstanceSpec) CountDownLatch(java.util.concurrent.CountDownLatch) QuorumVerifier(org.apache.zookeeper.server.quorum.flexible.QuorumVerifier) Test(org.junit.jupiter.api.Test)

Example 57 with TestingCluster

use of org.apache.curator.test.TestingCluster in project curator by apache.

the class TestReconfiguration method testAddAndRemove.

@Test
public void testAddAndRemove() throws Exception {
    try (CuratorFramework client = newClient()) {
        client.start();
        QuorumVerifier oldConfig = toQuorumVerifier(client.getConfig().forEnsemble());
        assertConfig(oldConfig, cluster.getInstances());
        CountDownLatch latch = setChangeWaiter(client);
        try (TestingCluster newCluster = new TestingCluster(TestingCluster.makeSpecs(1, false))) {
            newCluster.start();
            Collection<InstanceSpec> oldInstances = cluster.getInstances();
            InstanceSpec us = cluster.findConnectionInstance(client.getZookeeperClient().getZooKeeper());
            InstanceSpec removeSpec = oldInstances.iterator().next();
            if (us.equals(removeSpec)) {
                Iterator<InstanceSpec> iterator = oldInstances.iterator();
                iterator.next();
                removeSpec = iterator.next();
            }
            Collection<InstanceSpec> instances = newCluster.getInstances();
            client.reconfig().leaving(Integer.toString(removeSpec.getServerId())).joining(toReconfigSpec(instances)).fromConfig(oldConfig.getVersion()).forEnsemble();
            assertTrue(timing.awaitLatch(latch));
            byte[] newConfigData = client.getConfig().forEnsemble();
            QuorumVerifier newConfig = toQuorumVerifier(newConfigData);
            ArrayList<InstanceSpec> newInstances = Lists.newArrayList(oldInstances);
            newInstances.addAll(instances);
            newInstances.remove(removeSpec);
            assertConfig(newConfig, newInstances);
            assertEquals(EnsembleTracker.configToConnectionString(newConfig), ensembleProvider.getConnectionString());
        }
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) InstanceSpec(org.apache.curator.test.InstanceSpec) CountDownLatch(java.util.concurrent.CountDownLatch) QuorumVerifier(org.apache.zookeeper.server.quorum.flexible.QuorumVerifier) Test(org.junit.jupiter.api.Test)

Example 58 with TestingCluster

use of org.apache.curator.test.TestingCluster in project exhibitor by soabase.

the class TestZookeeperConfigProvider method setup.

@BeforeMethod
public void setup() throws Exception {
    timing = new Timing();
    cluster = new TestingCluster(3);
    cluster.start();
    client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
    client.start();
}
Also used : TestingCluster(org.apache.curator.test.TestingCluster) RetryOneTime(org.apache.curator.retry.RetryOneTime) Timing(org.apache.curator.test.Timing) BeforeMethod(org.testng.annotations.BeforeMethod)

Example 59 with TestingCluster

use of org.apache.curator.test.TestingCluster in project druid by druid-io.

the class RemoteTaskRunnerTestUtils method setUp.

void setUp() throws Exception {
    testingCluster = new TestingCluster(1);
    testingCluster.start();
    cf = CuratorFrameworkFactory.builder().connectString(testingCluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1, 10)).compressionProvider(new PotentiallyGzippedCompressionProvider(false)).build();
    cf.start();
    cf.blockUntilConnected();
    cf.create().creatingParentsIfNeeded().forPath(basePath);
    cf.create().creatingParentsIfNeeded().forPath(tasksPath);
}
Also used : TestingCluster(org.apache.curator.test.TestingCluster) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) PotentiallyGzippedCompressionProvider(io.druid.curator.PotentiallyGzippedCompressionProvider)

Example 60 with TestingCluster

use of org.apache.curator.test.TestingCluster in project druid by druid-io.

the class BatchDataSegmentAnnouncerTest method setUp.

@Before
public void setUp() throws Exception {
    testingCluster = new TestingCluster(1);
    testingCluster.start();
    cf = CuratorFrameworkFactory.builder().connectString(testingCluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1, 10)).compressionProvider(new PotentiallyGzippedCompressionProvider(false)).build();
    cf.start();
    cf.blockUntilConnected();
    cf.create().creatingParentsIfNeeded().forPath(testBasePath);
    jsonMapper = new DefaultObjectMapper();
    announcer = new Announcer(cf, MoreExecutors.sameThreadExecutor());
    announcer.start();
    segmentReader = new SegmentReader(cf, jsonMapper);
    skipDimensionsAndMetrics = false;
    skipLoadSpec = false;
    segmentAnnouncer = new BatchDataSegmentAnnouncer(new DruidServerMetadata("id", "host", Long.MAX_VALUE, "type", "tier", 0), new BatchDataSegmentAnnouncerConfig() {

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

        @Override
        public long getMaxBytesPerNode() {
            return maxBytesPerNode.get();
        }

        @Override
        public boolean isSkipDimensionsAndMetrics() {
            return skipDimensionsAndMetrics;
        }

        @Override
        public boolean isSkipLoadSpec() {
            return skipLoadSpec;
        }
    }, new ZkPathsConfig() {

        @Override
        public String getBase() {
            return testBasePath;
        }
    }, announcer, jsonMapper);
    segmentAnnouncer.start();
    testSegments = Sets.newHashSet();
    for (int i = 0; i < 100; i++) {
        testSegments.add(makeSegment(i));
    }
}
Also used : TestingCluster(org.apache.curator.test.TestingCluster) BatchDataSegmentAnnouncer(io.druid.server.coordination.BatchDataSegmentAnnouncer) Announcer(io.druid.curator.announcement.Announcer) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) ZkPathsConfig(io.druid.server.initialization.ZkPathsConfig) BatchDataSegmentAnnouncerConfig(io.druid.server.initialization.BatchDataSegmentAnnouncerConfig) DefaultObjectMapper(io.druid.jackson.DefaultObjectMapper) DruidServerMetadata(io.druid.server.coordination.DruidServerMetadata) PotentiallyGzippedCompressionProvider(io.druid.curator.PotentiallyGzippedCompressionProvider) BatchDataSegmentAnnouncer(io.druid.server.coordination.BatchDataSegmentAnnouncer) Before(org.junit.Before)

Aggregations

TestingCluster (org.apache.curator.test.TestingCluster)97 CuratorFramework (org.apache.curator.framework.CuratorFramework)48 InstanceSpec (org.apache.curator.test.InstanceSpec)41 ExponentialBackoffRetry (org.apache.curator.retry.ExponentialBackoffRetry)39 Before (org.junit.Before)30 Timing (org.apache.curator.test.Timing)21 Test (org.junit.jupiter.api.Test)21 CountDownLatch (java.util.concurrent.CountDownLatch)20 ConnectionState (org.apache.curator.framework.state.ConnectionState)16 RetryOneTime (org.apache.curator.retry.RetryOneTime)15 ConnectionStateListener (org.apache.curator.framework.state.ConnectionStateListener)12 HashMap (java.util.HashMap)10 PotentiallyGzippedCompressionProvider (org.apache.druid.curator.PotentiallyGzippedCompressionProvider)10 BeforeClass (org.junit.BeforeClass)10 Test (org.junit.Test)10 Test (org.testng.annotations.Test)10 ArrayList (java.util.ArrayList)9 TestBroker (org.apache.druid.indexing.kafka.test.TestBroker)8 ZkPathsConfig (org.apache.druid.server.initialization.ZkPathsConfig)8 GatewayConfig (org.apache.knox.gateway.config.GatewayConfig)8