use of org.apache.curator.CuratorZookeeperClient in project hadoop by apache.
the class TestLeaderElectorService method testExpireCurrentZKSession.
// 1. rm1 active
// 2. kill the zk session between the rm and zk cluster.
// 3. rm1 will first relinquish leadership and re-acquire leadership
@Test
public void testExpireCurrentZKSession() throws Exception {
rm1 = startRM("rm1", HAServiceState.ACTIVE);
CuratorBasedElectorService service = (CuratorBasedElectorService) rm1.getRMContext().getLeaderElectorService();
CuratorZookeeperClient client = service.getCuratorClient().getZookeeperClient();
// this will expire current curator client session. curator will re-establish
// the session. RM will first relinquish leadership and re-acquire leadership
KillSession.kill(client.getZooKeeper(), client.getCurrentConnectionString());
waitFor(rm1, HAServiceState.ACTIVE);
}
use of org.apache.curator.CuratorZookeeperClient in project nakadi by zalando.
the class KafkaRepositoryAT method createKafkaTopicRepository.
private KafkaTopicRepository createKafkaTopicRepository() {
final CuratorZookeeperClient zookeeperClient = mock(CuratorZookeeperClient.class);
when(zookeeperClient.getCurrentConnectionString()).thenReturn(ZOOKEEPER_URL);
final CuratorFramework curatorFramework = mock(CuratorFramework.class);
when(curatorFramework.getZookeeperClient()).thenReturn(zookeeperClient);
final ZooKeeperHolder zooKeeperHolder = mock(ZooKeeperHolder.class);
when(zooKeeperHolder.get()).thenReturn(curatorFramework);
final Consumer<byte[], byte[]> consumer = mock(Consumer.class);
when(consumer.partitionsFor(any())).thenReturn(new ArrayList<>());
final KafkaFactory factory = mock(KafkaFactory.class);
when(factory.getConsumer()).thenReturn(consumer);
Mockito.doReturn(kafkaHelper.createProducer()).when(factory).takeProducer();
return new KafkaTopicRepository(zooKeeperHolder, factory, nakadiSettings, kafkaSettings, zookeeperSettings, new UUIDGenerator());
}
use of org.apache.curator.CuratorZookeeperClient in project xian by happyyangyuan.
the class TestExhibitorEnsembleProvider method testChanging.
@Test
public void testChanging() throws Exception {
TestingServer secondServer = new TestingServer();
try {
String mainConnectionString = "count=1&port=" + server.getPort() + "&server0=localhost";
String secondConnectionString = "count=1&port=" + secondServer.getPort() + "&server0=localhost";
final Semaphore semaphore = new Semaphore(0);
final AtomicReference<String> connectionString = new AtomicReference<String>(mainConnectionString);
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 {
semaphore.release();
return connectionString.get();
}
};
ExhibitorEnsembleProvider provider = new ExhibitorEnsembleProvider(exhibitors, mockRestClient, "/foo", 10, new RetryOneTime(1));
provider.pollForInitialEnsemble();
Timing timing = new Timing().multiple(4);
final CuratorZookeeperClient client = new CuratorZookeeperClient(provider, timing.session(), timing.connection(), null, new RetryOneTime(2));
client.start();
try {
RetryLoop.callWithRetry(client, new Callable<Object>() {
@Override
public Object call() throws Exception {
client.getZooKeeper().create("/test", new byte[0], ZooDefs.Ids.OPEN_ACL_UNSAFE, CreateMode.PERSISTENT);
return null;
}
});
connectionString.set(secondConnectionString);
semaphore.drainPermits();
semaphore.acquire();
// create situation where the current zookeeper gets a sys-disconnected
server.stop();
Stat stat = RetryLoop.callWithRetry(client, new Callable<Stat>() {
@Override
public Stat call() throws Exception {
return client.getZooKeeper().exists("/test", false);
}
});
// it's a different server so should be null
Assert.assertNull(stat);
} finally {
client.close();
}
} finally {
CloseableUtils.closeQuietly(secondServer);
}
}
use of org.apache.curator.CuratorZookeeperClient 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();
}
}
use of org.apache.curator.CuratorZookeeperClient in project phoenix by apache.
the class LoadBalancerEnd2EndIT method testZookeeperDown.
@Test(expected = Exception.class)
public void testZookeeperDown() throws Exception {
testingServer.stop();
CuratorZookeeperClient zookeeperClient = curatorFramework.getZookeeperClient();
// check to see if zookeeper is really down.
while (zookeeperClient.isConnected()) {
Thread.sleep(1000);
}
;
loadBalancer.getSingleServiceLocation();
}
Aggregations