.newBuilder(String.format("kiji://%s/kiji_instance/table_name", getZKAddress()))
.build();
final BlockingQueue<Multimap<String, String>> queue = Queues.newSynchronousQueue();
final UsersTracker tracker = monitor.newTableUsersTracker(
tableURI,
new UsersUpdateHandler() {
@Override
public void update(Multimap<String, String> users) {
LOG.info("Users map updated to: {}", users);
try {
queue.put(users);
} catch (InterruptedException ie) {
throw new RuntimeInterruptedException(ie);
}
}
});
tracker.open();
final ZooKeeperMonitor.TableUserRegistration userRegistration1 =
monitor.newTableUserRegistration("user-id-1", tableURI);
final ZooKeeperMonitor.TableUserRegistration userRegistration2 =
monitor.newTableUserRegistration("user-id-2", tableURI);
try {
Assert.assertTrue(queue.poll(1, TimeUnit.SECONDS).isEmpty());
userRegistration1.updateRegisteredLayout("layout-id-1");
Assert.assertEquals(
ImmutableSetMultimap.of("user-id-1", "layout-id-1"),
queue.poll(1, TimeUnit.SECONDS));
userRegistration1.updateRegisteredLayout("layout-id-2");
Assert.assertEquals(
ImmutableSetMultimap.<String, String>of(), // unregistration event
queue.poll(1, TimeUnit.SECONDS));
Assert.assertEquals(
ImmutableSetMultimap.of("user-id-1", "layout-id-2"), // re-registration event
queue.poll(1, TimeUnit.SECONDS));
userRegistration2.updateRegisteredLayout("layout-id-1");
Assert.assertEquals(
ImmutableSetMultimap.of(
"user-id-1", "layout-id-2",
"user-id-2", "layout-id-1"),
queue.poll(1, TimeUnit.SECONDS));
userRegistration1.close();
Assert.assertEquals(
ImmutableSetMultimap.of("user-id-2", "layout-id-1"),
queue.poll(1, TimeUnit.SECONDS));
} finally {
tracker.close();
userRegistration2.close();
}
} finally {
monitor.close();
}