use of com.twitter.common.net.pool.DynamicHostSet.HostChangeMonitor in project commons by twitter.
the class DynamicHostSetUtilTest method testSnapshot.
@Test
public void testSnapshot() throws MonitorException {
DynamicHostSet<String> hostSet = createMock(new Clazz<DynamicHostSet<String>>() {
});
final Capture<HostChangeMonitor<String>> monitorCapture = createCapture();
final Command unwatchCommand = createMock(Command.class);
expect(hostSet.watch(capture(monitorCapture))).andAnswer(new IAnswer<Command>() {
@Override
public Command answer() throws Throwable {
// Simulate the 1st blocking onChange callback.
HostChangeMonitor<String> monitor = monitorCapture.getValue();
monitor.onChange(ImmutableSet.of("jack", "jill"));
return unwatchCommand;
}
});
// Confirm we clean up our watch.
unwatchCommand.execute();
expectLastCall();
control.replay();
ImmutableSet<String> snapshot = DynamicHostSetUtil.getSnapshot(hostSet);
assertEquals(ImmutableSet.of("jack", "jill"), snapshot);
}
Aggregations