use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project dubbo by alibaba.
the class ZookeeperDynamicConfigurationTest method setUp.
@BeforeEach
public void setUp() throws Exception {
zkServer = new TestingServer(zkServerPort, true);
client = CuratorFrameworkFactory.newClient("127.0.0.1:" + zkServerPort, 60 * 1000, 60 * 1000, new ExponentialBackoffRetry(1000, 3));
client.start();
try {
setData("/dubbo/config/dubbo/dubbo.properties", "The content from dubbo.properties");
setData("/dubbo/config/appname", "The content from higher level node");
setData("/dubbo/config/dubbo/never.change.DemoService.configurators", "Never change value from configurators");
} catch (Exception e) {
e.printStackTrace();
}
configUrl = URL.valueOf("zookeeper://127.0.0.1:" + zkServerPort);
configuration = ExtensionLoader.getExtensionLoader(DynamicConfigurationFactory.class).getExtension(configUrl.getProtocol()).getDynamicConfiguration(configUrl);
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry 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.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project xian by happyyangyuan.
the class TestWithCluster method testSessionSurvives.
@Test
public void testSessionSurvives() throws Exception {
Timing timing = new Timing();
CuratorFramework client = null;
TestingCluster cluster = new TestingCluster(3);
cluster.start();
try {
client = CuratorFrameworkFactory.newClient(cluster.getConnectString(), timing.session(), timing.connection(), new ExponentialBackoffRetry(100, 3));
client.start();
client.create().withMode(CreateMode.EPHEMERAL).forPath("/temp", "value".getBytes());
Assert.assertNotNull(client.checkExists().forPath("/temp"));
for (InstanceSpec spec : cluster.getInstances()) {
cluster.killServer(spec);
timing.forWaiting().sleepABit();
cluster.restartServer(spec);
timing.sleepABit();
}
timing.sleepABit();
Assert.assertNotNull(client.checkExists().forPath("/temp"));
} finally {
CloseableUtils.closeQuietly(client);
CloseableUtils.closeQuietly(cluster);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project xian by happyyangyuan.
the class TestFailedDeleteManager method testLostSession.
@Test
public void testLostSession() throws Exception {
Timing timing = new Timing();
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new ExponentialBackoffRetry(100, 3));
try {
client.start();
client.create().forPath("/test-me");
final CountDownLatch latch = new CountDownLatch(1);
final Semaphore semaphore = new Semaphore(0);
ConnectionStateListener listener = new ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if ((newState == ConnectionState.LOST) || (newState == ConnectionState.SUSPENDED)) {
semaphore.release();
} else if (newState == ConnectionState.RECONNECTED) {
latch.countDown();
}
}
};
client.getConnectionStateListenable().addListener(listener);
server.stop();
Assert.assertTrue(timing.acquireSemaphore(semaphore));
try {
client.delete().guaranteed().forPath("/test-me");
Assert.fail();
} catch (KeeperException.ConnectionLossException e) {
// expected
}
Assert.assertTrue(timing.acquireSemaphore(semaphore));
timing.sleepABit();
server.restart();
Assert.assertTrue(timing.awaitLatch(latch));
timing.sleepABit();
Assert.assertNull(client.checkExists().forPath("/test-me"));
} finally {
CloseableUtils.closeQuietly(client);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project xian by happyyangyuan.
the class TestLeaderAcls method testAclErrorWithLeader.
@Test(description = "Validation test for CURATOR-365")
public void testAclErrorWithLeader() throws Exception {
ACLProvider provider = new ACLProvider() {
@Override
public List<ACL> getDefaultAcl() {
return ZooDefs.Ids.OPEN_ACL_UNSAFE;
}
@Override
public List<ACL> getAclForPath(String path) {
if (path.equals("/base")) {
try {
String testDigest = DigestAuthenticationProvider.generateDigest("test:test");
return Collections.singletonList(new ACL(ZooDefs.Perms.ALL, new Id("digest", testDigest)));
} catch (NoSuchAlgorithmException e) {
e.printStackTrace();
}
}
return getDefaultAcl();
}
};
RetryPolicy retryPolicy = new ExponentialBackoffRetry(timing.milliseconds(), 3);
CuratorFrameworkFactory.Builder builder = CuratorFrameworkFactory.builder().connectString(server.getConnectString()).retryPolicy(retryPolicy).aclProvider(provider).authorization("digest", "test:test".getBytes());
CuratorFramework client = builder.build();
LeaderLatch latch = null;
try {
client.start();
latch = new LeaderLatch(client, "/base");
latch.start();
Assert.assertTrue(latch.await(timing.forWaiting().seconds(), TimeUnit.SECONDS));
latch.close();
latch = null;
CuratorFramework noAuthClient = CuratorFrameworkFactory.newClient(server.getConnectString(), retryPolicy);
try {
noAuthClient.start();
final CountDownLatch noAuthLatch = new CountDownLatch(1);
UnhandledErrorListener listener = new UnhandledErrorListener() {
@Override
public void unhandledError(String message, Throwable e) {
if (e instanceof KeeperException.NoAuthException) {
noAuthLatch.countDown();
}
}
};
noAuthClient.getUnhandledErrorListenable().addListener(listener);
// use a path below "base" as noAuthClient is not authorized to create nodes in "/base"
// but also making sure that the code goes through the backgroundCreateParentsThenNode() codepath
latch = new LeaderLatch(noAuthClient, "/base/second");
latch.start();
Assert.assertTrue(timing.awaitLatch(noAuthLatch));
} finally {
CloseableUtils.closeQuietly(noAuthClient);
}
} finally {
CloseableUtils.closeQuietly(latch);
CloseableUtils.closeQuietly(client);
}
}
Aggregations