use of com.twitter.common.zookeeper.ZooKeeperClient in project commons by twitter.
the class ZooKeeperTestServer method createClient.
/**
* Returns a new authenticated zookeeper client connected to the in-process zookeeper server with
* a custom {@code sessionTimeout} and a custom {@code chrootPath}.
*/
public final ZooKeeperClient createClient(Amount<Integer, Time> sessionTimeout, Credentials credentials, Optional<String> chrootPath) {
final ZooKeeperClient client = new ZooKeeperClient(sessionTimeout, credentials, chrootPath, Arrays.asList(InetSocketAddress.createUnresolved("127.0.0.1", port)));
shutdownRegistry.addAction(new ExceptionalCommand<InterruptedException>() {
@Override
public void execute() {
client.close();
}
});
return client;
}
use of com.twitter.common.zookeeper.ZooKeeperClient in project commons by twitter.
the class ServerSetImplTest method testUnwatchOnException.
@Test
public void testUnwatchOnException() throws Exception {
IMocksControl control = createControl();
ZooKeeperClient zkClient = control.createMock(ZooKeeperClient.class);
Watcher onExpirationWatcher = control.createMock(Watcher.class);
expect(zkClient.registerExpirationHandler(anyObject(Command.class))).andReturn(onExpirationWatcher);
expect(zkClient.get()).andThrow(new InterruptedException());
expect(zkClient.unregister(onExpirationWatcher)).andReturn(true);
control.replay();
Group group = new Group(zkClient, ZooDefs.Ids.OPEN_ACL_UNSAFE, "/blabla");
ServerSetImpl serverset = new ServerSetImpl(zkClient, group);
try {
serverset.watch(new DynamicHostSet.HostChangeMonitor<ServiceInstance>() {
@Override
public void onChange(ImmutableSet<ServiceInstance> hostSet) {
}
});
fail("Expected MonitorException");
} catch (DynamicHostSet.MonitorException e) {
// expected
}
control.verify();
}
use of com.twitter.common.zookeeper.ZooKeeperClient in project commons by twitter.
the class AngryBirdZooKeeperTest method testEndpointExpiration.
@Test(expected = KeeperException.class)
public void testEndpointExpiration() throws Exception {
// Create some sequential nodes.
ZooKeeperClient zkClient1 = createZKClient("1@1234:81".getBytes());
ZooKeeperClient zkClient2 = createZKClient("2@1234:82".getBytes());
ZooKeeperClient zkClient3 = createZKClient("3@1235:81".getBytes());
// Expire the leader's session.
zkServer.expireEndpoint("1234", 81);
// Make sure non-matching sessions are not expired.
zkClient2.get().exists(zkPaths.get(zkClient2), null);
zkClient3.get().exists(zkPaths.get(zkClient3), null);
// Check that the matching session has expired.
zkClient1.get().exists(zkPaths.get(zkClient1), null);
fail("Matching session has not expired!");
}
use of com.twitter.common.zookeeper.ZooKeeperClient in project commons by twitter.
the class AngryBirdZooKeeperTest method testFollowerExpirationById.
@Test
public void testFollowerExpirationById() throws Exception {
// Create some sequential nodes.
ZooKeeperClient zkClient1 = createZKClient("1@1234:81".getBytes());
ZooKeeperClient zkClient2 = createZKClient("2@1234:82".getBytes());
ZooKeeperClient zkClient3 = createZKClient("3@1235:81".getBytes());
ZooKeeperClient zkClient4 = createZKClient("4@1235:81".getBytes());
// Expire the 3rd follower's session.
zkServer.expireFollower(ROOT_PATH, Optional.of("3"));
// Make sure the expected sessions non expired.
zkClient1.get().exists(zkPaths.get(zkClient1), null);
zkClient2.get().exists(zkPaths.get(zkClient2), null);
zkClient4.get().exists(zkPaths.get(zkClient4), null);
boolean failed = false;
// Check that only one of the followers's sessions has expired.
try {
zkClient3.get().exists(zkPaths.get(zkClient3), null);
} catch (KeeperException e) {
failed = true;
}
assertTrue(failed);
}
use of com.twitter.common.zookeeper.ZooKeeperClient in project distributedlog by twitter.
the class DLZkServerSet method of.
public static DLZkServerSet of(URI uri, int zkSessionTimeoutMs) {
// Create zookeeper and server set
String zkPath = uri.getPath() + "/" + ZNODE_WRITE_PROXY;
Iterable<InetSocketAddress> zkAddresses = getZkAddresses(uri);
ZooKeeperClient zkClient = new ZooKeeperClient(Amount.of(zkSessionTimeoutMs, Time.MILLISECONDS), zkAddresses);
ServerSet serverSet = ServerSets.create(zkClient, ZooDefs.Ids.OPEN_ACL_UNSAFE, zkPath);
return new DLZkServerSet(zkClient, serverSet);
}
Aggregations