Search in sources :

Example 31 with TestingCluster

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

the class TestPathChildrenCacheInCluster method testServerLoss.

@Test
public void testServerLoss() throws Exception {
    Timing timing = new Timing();
    CuratorFramework client = null;
    PathChildrenCache cache = null;
    TestingCluster cluster = new TestingCluster(3);
    try {
        cluster.start();
        client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(1));
        client.start();
        client.create().creatingParentsIfNeeded().forPath("/test");
        cache = new PathChildrenCache(client, "/test", false);
        cache.start();
        final CountDownLatch resetLatch = new CountDownLatch(1);
        final CountDownLatch reconnectLatch = new CountDownLatch(1);
        final AtomicReference<CountDownLatch> latch = new AtomicReference<CountDownLatch>(new CountDownLatch(3));
        cache.getListenable().addListener(new PathChildrenCacheListener() {

            @Override
            public void childEvent(CuratorFramework client, PathChildrenCacheEvent event) throws Exception {
                if (event.getType() == PathChildrenCacheEvent.Type.CONNECTION_SUSPENDED) {
                    resetLatch.countDown();
                } else if (event.getType() == PathChildrenCacheEvent.Type.CONNECTION_RECONNECTED) {
                    reconnectLatch.countDown();
                } else if (event.getType() == PathChildrenCacheEvent.Type.CHILD_ADDED) {
                    latch.get().countDown();
                }
            }
        });
        client.create().forPath("/test/one");
        client.create().forPath("/test/two");
        client.create().forPath("/test/three");
        Assert.assertTrue(latch.get().await(10, TimeUnit.SECONDS));
        InstanceSpec connectionInstance = cluster.findConnectionInstance(client.getZookeeperClient().getZooKeeper());
        cluster.killServer(connectionInstance);
        Assert.assertTrue(timing.awaitLatch(reconnectLatch));
        Assert.assertEquals(cache.getCurrentData().size(), 3);
    } finally {
        CloseableUtils.closeQuietly(cache);
        CloseableUtils.closeQuietly(client);
        CloseableUtils.closeQuietly(cluster);
    }
}
Also used : RetryOneTime(org.apache.curator.retry.RetryOneTime) InstanceSpec(org.apache.curator.test.InstanceSpec) AtomicReference(java.util.concurrent.atomic.AtomicReference) CountDownLatch(java.util.concurrent.CountDownLatch) CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) Timing(org.apache.curator.test.Timing) Test(org.testng.annotations.Test)

Example 32 with TestingCluster

use of org.apache.curator.test.TestingCluster in project activemq-artemis by apache.

the class ZookeeperPluggableQuorumSinglePairTest method setup.

@Before
@Override
public void setup() throws Exception {
    super.setup();
    nodes = 3;
    clusterSpecs = new InstanceSpec[nodes];
    for (int i = 0; i < nodes; i++) {
        clusterSpecs[i] = new InstanceSpec(temporaryFolder.newFolder(), BASE_SERVER_PORT + i, -1, -1, true, -1, SERVER_TICK_MS, -1);
    }
    testingServer = new TestingCluster(clusterSpecs);
    testingServer.start();
    Assert.assertEquals("127.0.0.1:6666,127.0.0.1:6667,127.0.0.1:6668", testingServer.getConnectString());
    LOGGER.infof("Cluster of %d nodes on: %s", 3, testingServer.getConnectString());
}
Also used : InstanceSpec(org.apache.curator.test.InstanceSpec) TestingCluster(org.apache.curator.test.TestingCluster) Before(org.junit.Before)

Example 33 with TestingCluster

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

the class AtlasZookeeperURLManagerTest method setUp.

@Before
public void setUp() throws Exception {
    cluster = new TestingCluster(1);
    cluster.start();
    try (CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build()) {
        zooKeeperClient.start();
        assertTrue(zooKeeperClient.blockUntilConnected(10, TimeUnit.SECONDS));
        zooKeeperClient.create().forPath("/apache_atlas");
        zooKeeperClient.create().forPath("/apache_atlas/active_server_info");
        zooKeeperClient.setData().forPath("/apache_atlas/active_server_info", atlasNode1.getBytes(StandardCharsets.UTF_8));
    }
    setAtlasActiveHostURLInZookeeper(atlasNode1);
    manager = new AtlasZookeeperURLManager();
    HaServiceConfig config = new DefaultHaServiceConfig("ATLAS-API");
    config.setEnabled(true);
    config.setZookeeperEnsemble(cluster.getConnectString());
    config.setZookeeperNamespace("apache_atlas");
    manager.setConfig(config);
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) HaServiceConfig(org.apache.knox.gateway.ha.provider.HaServiceConfig) Before(org.junit.Before)

Example 34 with TestingCluster

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

the class HBaseZookeeperURLManagerTest method setUp.

@Before
public void setUp() throws Exception {
    cluster = new TestingCluster(1);
    cluster.start();
}
Also used : TestingCluster(org.apache.curator.test.TestingCluster) Before(org.junit.Before)

Example 35 with TestingCluster

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

the class KafkaZookeeperURLManagerTest method setUp.

@Before
public void setUp() throws Exception {
    cluster = new TestingCluster(1);
    cluster.start();
    try (CuratorFramework zooKeeperClient = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()).retryPolicy(new ExponentialBackoffRetry(1000, 3)).build()) {
        zooKeeperClient.start();
        assertTrue(zooKeeperClient.blockUntilConnected(10, TimeUnit.SECONDS));
        zooKeeperClient.create().forPath("/brokers");
        zooKeeperClient.create().forPath("/brokers/ids");
    }
}
Also used : CuratorFramework(org.apache.curator.framework.CuratorFramework) TestingCluster(org.apache.curator.test.TestingCluster) ExponentialBackoffRetry(org.apache.curator.retry.ExponentialBackoffRetry) 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