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);
}
}
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());
}
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);
}
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();
}
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");
}
}
Aggregations