use of org.apache.curator.retry.RetryNTimes in project tutorials by eugenp.
the class ConnectionManagementManualTest method givenRunningZookeeper_whenOpenConnectionUsingAsyncNotBlocking_thenClientIsOpened.
@Test
public void givenRunningZookeeper_whenOpenConnectionUsingAsyncNotBlocking_thenClientIsOpened() throws InterruptedException {
int sleepMsBetweenRetries = 100;
int maxRetries = 3;
RetryPolicy retryPolicy = new RetryNTimes(maxRetries, sleepMsBetweenRetries);
try (CuratorFramework client = CuratorFrameworkFactory.newClient("127.0.0.1:2181", retryPolicy)) {
client.start();
AsyncCuratorFramework async = AsyncCuratorFramework.wrap(client);
AtomicBoolean exists = new AtomicBoolean(false);
async.checkExists().forPath("/").thenAcceptAsync(s -> exists.set(s != null));
await().until(() -> assertThat(exists.get()).isTrue());
}
}
use of org.apache.curator.retry.RetryNTimes in project nakadi by zalando.
the class ZookeeperTestUtils method createCurator.
public static CuratorFramework createCurator(final String zkUrl) {
final CuratorFramework curator = CuratorFrameworkFactory.builder().connectString(zkUrl).retryPolicy(new RetryNTimes(5, 500)).sessionTimeoutMs((int) TimeUnit.SECONDS.toMillis(10)).build();
curator.start();
return curator;
}
use of org.apache.curator.retry.RetryNTimes in project drill by apache.
the class TestZkRegistry method connectToZk.
/**
* Connect to the test ZK for the simulated Drillbit side of the test. (The AM
* side of the test uses the actual AM code, which is what we're testing
* here...)
*
* @param connectString
* @return
*/
public static CuratorFramework connectToZk(String connectString) {
CuratorFramework client = CuratorFrameworkFactory.builder().namespace(ZK_ROOT + "/" + CLUSTER_ID).connectString(connectString).retryPolicy(new RetryNTimes(3, 1000)).build();
client.start();
return client;
}
use of org.apache.curator.retry.RetryNTimes in project drill by apache.
the class TestEphemeralStore method setUp.
@SuppressWarnings("unchecked")
@Before
public void setUp() throws Exception {
ZookeeperTestUtil.setZookeeperSaslTestConfigProps();
server = new TestingServer();
final RetryPolicy policy = new RetryNTimes(2, 1000);
curator = CuratorFrameworkFactory.newClient(server.getConnectString(), policy);
config = Mockito.mock(TransientStoreConfig.class);
Mockito.when(config.getName()).thenReturn(root);
Mockito.when(config.getSerializer()).thenReturn(new InstanceSerializer<String>() {
@Override
public byte[] serialize(final String instance) throws IOException {
if (instance == null) {
return null;
}
return instance.getBytes();
}
@Override
public String deserialize(final byte[] raw) throws IOException {
if (raw == null) {
return null;
}
return new String(raw);
}
});
store = new ZkEphemeralStore<>(config, curator);
server.start();
curator.start();
store.start();
}
use of org.apache.curator.retry.RetryNTimes in project yyl_example by Relucent.
the class CuratorWatcherTest method main.
public static void main(String[] args) throws Exception {
// 1.Connect to zk
CuratorFramework client = CuratorFrameworkFactory.newClient(ZK_ADDRESS, new RetryNTimes(10, 5000));
client.start();
System.out.println("zk client start successfully!");
// 2.Register watcher
PathChildrenCache watcher = new PathChildrenCache(client, ZK_PATH, true);
watcher.getListenable().addListener((client1, event) -> {
ChildData data = event.getData();
if (data == null) {
System.out.println("No data in event[" + event + "]");
} else {
System.out.println(//
"Receive event: " + "type=[" + event.getType() + "]" + //
", " + "path=[" + data.getPath() + "]" + //
", " + "data=[" + new String(data.getData()) + "]" + //
", " + "stat=[" + data.getStat() + "]");
}
});
watcher.start(StartMode.BUILD_INITIAL_CACHE);
System.out.println("Register zk watcher successfully!");
client.create().creatingParentsIfNeeded().forPath(ZK_CHILDREN_PATH, "hello".getBytes());
client.setData().forPath(ZK_CHILDREN_PATH, "world".getBytes());
client.delete().deletingChildrenIfNeeded().forPath(ZK_CHILDREN_PATH);
watcher.close();
Thread.sleep(100);
client.close();
}
Aggregations