Package com.facebook.zookeeper.mock

Examples of com.facebook.zookeeper.mock.MockWatcher


  }

  @Test(groups = "fast")
  public void testEnter() throws Exception {
    // Verify no candidates
    MockWatcher mockWatcher = new MockWatcher();
    List<String> candidates = zk1.getChildren(electionRoot, mockWatcher);
    Assert.assertTrue(candidates.isEmpty());

    // Enter the candidate and run any callbacks
    zkLeaderElection1.enter();
    mockExecutor1.drain();

    // Check that candidate is created
    candidates = zk1.getChildren(electionRoot, null);
    Assert.assertEquals(candidates.size(), 1);

    // Check that candidate is elected
    Assert.assertTrue(mockLeaderElectionCallback1.isElected());
    mockLeaderElectionCallback1.resetElected();
    Assert.assertEquals(zkLeaderElection1.getLeader(), candidates.get(0));

    // Check data contents
    String data = VariablePayload.decode(
      zk1.getData(electionRoot + "/" + candidates.get(0), null, null)
    );
    Assert.assertEquals(data, testData1);

    // Check that external watch was notified of candidate creation
    Assert.assertEquals(mockWatcher.getEventQueue().size(), 1);
    WatchedEvent watchedEvent = mockWatcher.getEventQueue().remove();
    Assert.assertEquals(watchedEvent.getType(), EventType.NodeChildrenChanged);
    Assert.assertEquals(watchedEvent.getPath(), electionRoot);
  }
View Full Code Here


  public void testWithdraw() throws Exception {
    zkLeaderElection1.enter();
    mockExecutor1.drain();

    // Verify candidate
    MockWatcher mockWatcher = new MockWatcher();
    List<String> candidates = zk1.getChildren(electionRoot, mockWatcher);
    Assert.assertEquals(candidates.size(), 1);
    Assert.assertTrue(mockLeaderElectionCallback1.isElected());
    mockLeaderElectionCallback1.resetElected();

    zkLeaderElection1.withdraw();
    mockExecutor1.drain();

    candidates = zk1.getChildren(electionRoot, null);
    Assert.assertTrue(candidates.isEmpty());
    Assert.assertEquals(zkLeaderElection1.getLeader(), null);
    // Manual withdraw should not trigger a "removed" callback
    Assert.assertFalse(mockLeaderElectionCallback1.isRemoved());
    Assert.assertEquals(mockWatcher.getEventQueue().size(), 1);
    WatchedEvent watchedEvent = mockWatcher.getEventQueue().remove();
    Assert.assertEquals(watchedEvent.getType(), EventType.NodeChildrenChanged);
    Assert.assertEquals(watchedEvent.getPath(), electionRoot);
  }
View Full Code Here

TOP

Related Classes of com.facebook.zookeeper.mock.MockWatcher

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.