use of com.twitter.common.zookeeper.Group 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();
}
Aggregations