use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project xian by happyyangyuan.
the class TestInterProcessMutexBase method testReentrant.
@Test
public void testReentrant() throws Exception {
CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), new ExponentialBackoffRetry(100, 3));
client.start();
try {
InterProcessLock mutex = makeLock(client);
foo(mutex);
Assert.assertFalse(mutex.isAcquiredInThisProcess());
} finally {
client.close();
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project xian by happyyangyuan.
the class TestInterProcessMutexBase method testWaitingProcessKilledServer.
@Test
public void testWaitingProcessKilledServer() throws Exception {
final Timing timing = new Timing();
final CuratorFramework client = CuratorFrameworkFactory.newClient(server.getConnectString(), timing.session(), timing.connection(), new ExponentialBackoffRetry(100, 3));
try {
client.start();
final CountDownLatch latch = new CountDownLatch(1);
ConnectionStateListener listener = new ConnectionStateListener() {
@Override
public void stateChanged(CuratorFramework client, ConnectionState newState) {
if (newState == ConnectionState.LOST) {
latch.countDown();
}
}
};
client.getConnectionStateListenable().addListener(listener);
final AtomicBoolean isFirst = new AtomicBoolean(true);
ExecutorCompletionService<Object> service = new ExecutorCompletionService<Object>(Executors.newFixedThreadPool(2));
for (int i = 0; i < 2; ++i) {
service.submit(new Callable<Object>() {
@Override
public Object call() throws Exception {
InterProcessLock lock = makeLock(client);
lock.acquire();
try {
if (isFirst.compareAndSet(true, false)) {
timing.sleepABit();
server.stop();
Assert.assertTrue(timing.awaitLatch(latch));
server.restart();
}
} finally {
try {
lock.release();
} catch (Exception e) {
// ignore
}
}
return null;
}
});
}
for (int i = 0; i < 2; ++i) {
service.take().get(timing.forWaiting().milliseconds(), TimeUnit.MILLISECONDS);
}
} finally {
CloseableUtils.closeQuietly(client);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project xian by happyyangyuan.
the class TestLockACLs method createClient.
private CuratorFramework createClient(ACLProvider provider) throws Exception {
RetryPolicy retryPolicy = new ExponentialBackoffRetry(1000, 3);
CuratorFramework client = CuratorFrameworkFactory.builder().namespace("ns").connectString(server.getConnectString()).retryPolicy(retryPolicy).aclProvider(provider).build();
client.start();
return client;
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project xian by happyyangyuan.
the class TestRetryLoop method testExponentialBackoffRetryLimit.
@Test
public void testExponentialBackoffRetryLimit() {
RetrySleeper sleeper = new RetrySleeper() {
@Override
public void sleepFor(long time, TimeUnit unit) throws InterruptedException {
Assert.assertTrue(unit.toMillis(time) <= 100);
}
};
ExponentialBackoffRetry retry = new ExponentialBackoffRetry(1, Integer.MAX_VALUE, 100);
for (int i = 0; i >= 0; ++i) {
retry.allowRetry(i, 0, sleeper);
}
}
use of org.apache.flink.shaded.curator5.org.apache.curator.retry.ExponentialBackoffRetry in project xian by happyyangyuan.
the class TestExhibitorEnsembleProvider method testSimple.
@Test
public void testSimple() throws Exception {
Exhibitors exhibitors = new Exhibitors(Lists.newArrayList("foo", "bar"), 1000, dummyConnectionStringProvider);
ExhibitorRestClient mockRestClient = new ExhibitorRestClient() {
@Override
public String getRaw(String hostname, int port, String uriPath, String mimeType) throws Exception {
return "count=1&port=" + server.getPort() + "&server0=localhost";
}
};
ExhibitorEnsembleProvider provider = new ExhibitorEnsembleProvider(exhibitors, mockRestClient, "/foo", 10, new RetryOneTime(1));
provider.pollForInitialEnsemble();
Timing timing = new Timing();
CuratorZookeeperClient client = new CuratorZookeeperClient(provider, timing.session(), timing.connection(), null, new ExponentialBackoffRetry(timing.milliseconds(), 3));
client.start();
try {
client.blockUntilConnectedOrTimedOut();
client.getZooKeeper().exists("/", false);
} catch (Exception e) {
Assert.fail("provider.getConnectionString(): " + provider.getConnectionString() + " server.getPort(): " + server.getPort(), e);
} finally {
client.close();
}
}
Aggregations