Search in sources :

Example 6 with Membership

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();
}
Also used : Command(com.twitter.common.base.Command) Membership(com.twitter.common.zookeeper.Group.Membership) CountDownLatch(java.util.concurrent.CountDownLatch) EasyMockTest(com.twitter.common.testing.easymock.EasyMockTest) Test(org.junit.Test) BaseZooKeeperTest(com.twitter.common.zookeeper.testing.BaseZooKeeperTest)

Example 7 with Membership

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();
}
Also used : Membership(com.twitter.common.zookeeper.Group.Membership) EasyMockTest(com.twitter.common.testing.easymock.EasyMockTest) Test(org.junit.Test) BaseZooKeeperTest(com.twitter.common.zookeeper.testing.BaseZooKeeperTest)

Example 8 with Membership

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();
}
Also used : Command(com.twitter.common.base.Command) Membership(com.twitter.common.zookeeper.Group.Membership) CountDownLatch(java.util.concurrent.CountDownLatch) EasyMockTest(com.twitter.common.testing.easymock.EasyMockTest) Test(org.junit.Test) BaseZooKeeperTest(com.twitter.common.zookeeper.testing.BaseZooKeeperTest)

Example 9 with Membership

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);
}
Also used : Membership(com.twitter.common.zookeeper.Group.Membership) EasyMockTest(com.twitter.common.testing.easymock.EasyMockTest) Test(org.junit.Test) BaseZooKeeperTest(com.twitter.common.zookeeper.testing.BaseZooKeeperTest)

Aggregations

Membership (com.twitter.common.zookeeper.Group.Membership)9 EasyMockTest (com.twitter.common.testing.easymock.EasyMockTest)7 BaseZooKeeperTest (com.twitter.common.zookeeper.testing.BaseZooKeeperTest)7 Test (org.junit.Test)7 Command (com.twitter.common.base.Command)3 Supplier (com.twitter.common.base.Supplier)2 CountDownLatch (java.util.concurrent.CountDownLatch)2 Supplier (com.google.common.base.Supplier)1 ExceptionalCommand (com.twitter.common.base.ExceptionalCommand)1 GroupChangeListener (com.twitter.common.zookeeper.Group.GroupChangeListener)1 JoinException (com.twitter.common.zookeeper.Group.JoinException)1 Status (com.twitter.thrift.Status)1 AtomicBoolean (java.util.concurrent.atomic.AtomicBoolean)1