use of com.twitter.common.zookeeper.Group.Membership in project commons by twitter.
the class GroupTest method testJoinsAndWatchesSurviveExpiredSession.
@Test
public void testJoinsAndWatchesSurviveExpiredSession() throws Exception {
onLoseMembership.execute();
replay(onLoseMembership);
assertEmptyMembershipObserved();
Membership membership = joinGroup.join(onLoseMembership);
String originalMemberId = membership.getMemberId();
assertMembershipObserved(originalMemberId);
expireSession(zkClient);
// We should have lost our group membership and then re-gained it with a new ephemeral node.
// We may or may-not see the intermediate state change but we must see the final state
Iterable<String> members = listener.take();
if (Iterables.isEmpty(members)) {
members = listener.take();
}
assertEquals(1, Iterables.size(members));
assertNotEqual(originalMemberId, Iterables.getOnlyElement(members));
assertNotEqual(originalMemberId, membership.getMemberId());
listener.assertEmpty();
verify(onLoseMembership);
// Turn off expectations during ZK server shutdown.
reset(onLoseMembership);
}
use of com.twitter.common.zookeeper.Group.Membership in project commons by twitter.
the class GroupTest method testJoinsAndWatchesSurviveDisconnect.
@Test
public void testJoinsAndWatchesSurviveDisconnect() throws Exception {
replay(onLoseMembership);
assertEmptyMembershipObserved();
Membership membership = joinGroup.join();
String originalMemberId = membership.getMemberId();
assertMembershipObserved(originalMemberId);
shutdownNetwork();
restartNetwork();
// The member should still be present under existing ephemeral node since session did not
// expire.
watchGroup.watch(listener);
assertMembershipObserved(originalMemberId);
membership.cancel();
assertEmptyMembershipObserved();
// and again for 2nd listener
assertEmptyMembershipObserved();
listener.assertEmpty();
verify(onLoseMembership);
// Turn off expectations during ZK server shutdown.
reset(onLoseMembership);
}
use of com.twitter.common.zookeeper.Group.Membership in project commons by twitter.
the class GroupTest method testUpdateMembershipData.
@Test
public void testUpdateMembershipData() throws Exception {
Supplier<byte[]> dataSupplier = new EasyMockTest.Clazz<Supplier<byte[]>>() {
}.createMock();
byte[] initial = "start".getBytes();
expect(dataSupplier.get()).andReturn(initial);
byte[] second = "update".getBytes();
expect(dataSupplier.get()).andReturn(second);
replay(dataSupplier);
Membership membership = joinGroup.join(dataSupplier, onLoseMembership);
assertArrayEquals("Initial setting is incorrect.", initial, zkClient.get().getData(membership.getMemberPath(), false, null));
assertArrayEquals("Updating supplier should not change membership data", initial, zkClient.get().getData(membership.getMemberPath(), false, null));
membership.updateMemberData();
assertArrayEquals("Updating membership should change data", second, zkClient.get().getData(membership.getMemberPath(), false, null));
verify(dataSupplier);
}
use of com.twitter.common.zookeeper.Group.Membership in project commons by twitter.
the class GroupTest method testNodeDeleteTriggersOnLoseMembership.
@Test
public void testNodeDeleteTriggersOnLoseMembership() throws Exception {
final CountDownLatch lostMembership = new CountDownLatch(1);
Command onLoseMembership = new Command() {
@Override
public void execute() throws RuntimeException {
lostMembership.countDown();
}
};
assertEmptyMembershipObserved();
Membership membership = joinGroup.join(onLoseMembership);
assertMembershipObserved(membership.getMemberId());
membership.cancel();
// Will hang this test if onLoseMembership event is not propagated.
lostMembership.await();
}
use of com.twitter.common.zookeeper.Group.Membership in project commons by twitter.
the class GroupTest method testStopWatching.
@Test
public void testStopWatching() throws Exception {
replay(onLoseMembership);
assertEmptyMembershipObserved();
Membership member1 = joinGroup.join();
String memberId1 = member1.getMemberId();
assertMembershipObserved(memberId1);
Membership member2 = joinGroup.join();
String memberId2 = member2.getMemberId();
assertMembershipObserved(memberId1, memberId2);
stopWatching.execute();
member1.cancel();
Membership member3 = joinGroup.join();
member2.cancel();
member3.cancel();
listener.assertEmpty();
}
Aggregations