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();
}
use of com.twitter.common.zookeeper.Group.Membership in project commons by twitter.
the class GroupTest method testSessionExpirationTriggersOnLoseMembership.
@Test
public void testSessionExpirationTriggersOnLoseMembership() 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());
expireSession(zkClient);
// 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 testJoinCustomNamingScheme.
@Test
public void testJoinCustomNamingScheme() throws Exception {
Group group = new Group(zkClient, ZooKeeperUtils.EVERYONE_READ_CREATOR_ALL, "/a/group", new CustomScheme());
listener = new RecordingListener();
group.watch(listener);
assertEmptyMembershipObserved();
Membership membership = group.join();
String memberId = membership.getMemberId();
assertEquals("Wrong member ID.", CustomScheme.NODE_NAME, memberId);
assertMembershipObserved(memberId);
expireSession(zkClient);
}
Aggregations