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");
}
}
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 xian by happyyangyuan.
the class TestReadOnly method testReadOnly.
@Test
public void testReadOnly() throws Exception {
Timing timing = new Timing();
CuratorFramework client = null;
TestingCluster cluster = new TestingCluster(2);
try {
cluster.start();
client = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()).canBeReadOnly(true).connectionTimeoutMs(timing.connection()).sessionTimeoutMs(timing.session()).retryPolicy(new ExponentialBackoffRetry(100, 3)).build();
client.start();
client.create().forPath("/test");
final CountDownLatch readOnlyLatch = new CountDownLatch(1);
final CountDownLatch reconnectedLatch = new CountDownLatch(1);
ConnectionStateListener listener = new ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if (newState == ConnectionState.READ_ONLY) {
readOnlyLatch.countDown();
} else if (newState == ConnectionState.RECONNECTED) {
reconnectedLatch.countDown();
}
}
};
client.getConnectionStateListenable().addListener(listener);
InstanceSpec ourInstance = cluster.findConnectionInstance(client.getZookeeperClient().getZooKeeper());
Iterator<InstanceSpec> iterator = cluster.getInstances().iterator();
InstanceSpec killInstance = iterator.next();
if (killInstance.equals(ourInstance)) {
// kill the instance we're not connected to
killInstance = iterator.next();
}
cluster.killServer(killInstance);
Assert.assertEquals(reconnectedLatch.getCount(), 1);
Assert.assertTrue(timing.awaitLatch(readOnlyLatch));
Assert.assertEquals(reconnectedLatch.getCount(), 1);
cluster.restartServer(killInstance);
Assert.assertTrue(timing.awaitLatch(reconnectedLatch));
} finally {
CloseableUtils.closeQuietly(client);
CloseableUtils.closeQuietly(cluster);
}
}
use of org.apache.curator.test.TestingCluster in project xian by happyyangyuan.
the class TestReadOnly method testConnectionStateNewClient.
@Test
public void testConnectionStateNewClient() throws Exception {
Timing timing = new Timing();
TestingCluster cluster = new TestingCluster(3);
CuratorFramework client = null;
try {
cluster.start();
client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), timing.session(), timing.connection(), new RetryOneTime(100));
client.start();
client.checkExists().forPath("/");
client.close();
client = null;
Iterator<InstanceSpec> iterator = cluster.getInstances().iterator();
for (int i = 0; i < 2; ++i) {
cluster.killServer(iterator.next());
}
client = CuratorFrameworkFactory.builder().connectString(cluster.getConnectString()).sessionTimeoutMs(timing.session()).connectionTimeoutMs(timing.connection()).retryPolicy(new RetryNTimes(3, timing.milliseconds())).canBeReadOnly(true).build();
final BlockingQueue<ConnectionState> states = Queues.newLinkedBlockingQueue();
client.getConnectionStateListenable().addListener(new ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
states.add(newState);
}
});
client.start();
client.checkExists().forPath("/");
ConnectionState state = states.poll(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS);
Assert.assertEquals(state, ConnectionState.READ_ONLY);
} finally {
CloseableUtils.closeQuietly(client);
CloseableUtils.closeQuietly(cluster);
}
}
Aggregations