コード例 #1
0
ファイル: TestZkRing.java プロジェクト: shahzadmajeed/hank
 public void testDelete() throws Exception {
   ZkRing ring =
       ZkRing.create(
           getZk(), coordinator, ZkPath.append(getRoot(), "ring-group-one"), 1, null, 10);
   ring.delete();
   try {
     new ZkRing(getZk(), ZkPath.append(getRoot(), "ring-group-one/ring-1"), null, coordinator);
     fail("should have had an exception!");
   } catch (KeeperException.NoNodeException e) {
     // expected
   }
 }
コード例 #2
0
ファイル: TestZkRing.java プロジェクト: shahzadmajeed/hank
 public void testSetUpdatingToVersion() throws Exception {
   Ring ring = ZkRing.create(getZk(), coordinator, getRoot(), 1, null, 1);
   ring.markUpdateComplete();
   assertNull(ring.getUpdatingToVersionNumber());
   ring.setUpdatingToVersion(7);
   assertEquals(Integer.valueOf(7), ring.getUpdatingToVersionNumber());
 }
コード例 #3
0
ファイル: TestZkRing.java プロジェクト: shahzadmajeed/hank
  public void testLoad() throws Exception {
    ZkRing ring = ZkRing.create(getZk(), coordinator, ring_group_root, 1, null, 1);
    ring.close();

    ring = new ZkRing(getZk(), ZkPath.append(ring_group_root, "ring-1"), null, coordinator);

    assertEquals("ring number", 1, ring.getRingNumber());
    assertNull("version number", ring.getCurrentVersionNumber());
    assertEquals("updating to version", Integer.valueOf(1), ring.getUpdatingToVersionNumber());
    assertEquals("number of hosts", 0, ring.getHosts().size());
    assertEquals("initial state", RingState.CLOSED, ring.getState());
    ring.close();
  }
コード例 #4
0
ファイル: TestZkRing.java プロジェクト: shahzadmajeed/hank
 public void testGetRingState() throws Exception {
   Ring ring = ZkRing.create(getZk(), coordinator, getRoot(), 1, null, 1);
   assertEquals(RingState.CLOSED, ring.getState());
   ring.setState(RingState.OPEN);
   assertEquals(RingState.OPEN, ring.getState());
   ring = new ZkRing(getZk(), ZkPath.append(getRoot(), "ring-1"), null, coordinator);
   assertEquals(RingState.OPEN, ring.getState());
 }
コード例 #5
0
ファイル: TestZkRing.java プロジェクト: shahzadmajeed/hank
  public void testListenersPreservedWhenHostAdded() throws Exception {
    ZkRing ring =
        ZkRing.create(
            getZk(), coordinator, ZkPath.append(getRoot(), "ring-group-one"), 1, null, 10);
    Host h1 = ring.addHost(new PartitionServerAddress("localhost", 1));
    MockHostCommandQueueChangeListener l1 = new MockHostCommandQueueChangeListener();
    h1.setCommandQueueChangeListener(l1);
    MockHostStateChangeListener l2 = new MockHostStateChangeListener();
    h1.setStateChangeListener(l2);

    ring.addHost(new PartitionServerAddress("localhost", 2));

    h1.setState(HostState.UPDATING);
    synchronized (l2) {
      l2.wait(WAIT_TIME);
    }
    assertEquals(h1, l2.calledWith);

    h1.enqueueCommand(HostCommand.EXECUTE_UPDATE);
    l1.waitForNotification();
    assertEquals(h1, l1.calledWith);
  }
コード例 #6
0
ファイル: TestZkRing.java プロジェクト: shahzadmajeed/hank
 public void testRingStateListener() throws Exception {
   Ring ring = ZkRing.create(getZk(), coordinator, getRoot(), 1, null, 1);
   MockListener mockListener = new MockListener();
   ring.setStateChangeListener(mockListener);
   synchronized (mockListener) {
     mockListener.wait(1000);
   }
   assertNull(mockListener.calledWith);
   ring.setState(RingState.CLOSED);
   synchronized (mockListener) {
     mockListener.wait(1000);
   }
   assertEquals(ring, mockListener.calledWith);
 }
コード例 #7
0
ファイル: TestZkRing.java プロジェクト: shahzadmajeed/hank
  public void testUpdatingSemantics() throws Exception {
    ZkRing ring = ZkRing.create(getZk(), coordinator, ring_group_root, 1, null, 1);

    assertTrue("should be updating", Rings.isUpdatePending(ring));
    assertNull("current version", ring.getCurrentVersionNumber());
    assertEquals(
        "updating_to_version number", Integer.valueOf(1), ring.getUpdatingToVersionNumber());

    ring.markUpdateComplete();

    assertFalse("updating", Rings.isUpdatePending(ring));
    assertEquals("current version", Integer.valueOf(1), ring.getCurrentVersionNumber());
    assertNull("updating to version", ring.getUpdatingToVersionNumber());

    ring.setUpdatingToVersion(7);
    assertTrue("should be updating", Rings.isUpdatePending(ring));
    assertEquals("current version", Integer.valueOf(1), ring.getCurrentVersionNumber());
    assertEquals(
        "updating_to_version number", Integer.valueOf(7), ring.getUpdatingToVersionNumber());

    ring.close();
  }
コード例 #8
0
ファイル: TestZkRing.java プロジェクト: shahzadmajeed/hank
  public void testHosts() throws Exception {
    ZkRing ring = ZkRing.create(getZk(), coordinator, ring_group_root, 1, null, 1);
    assertEquals(0, ring.getHosts().size());

    Host host = ring.addHost(LOCALHOST);
    assertEquals(LOCALHOST, host.getAddress());
    for (int i = 0; i < 20; i++) {
      if (!ring.getHosts().isEmpty()) {
        break;
      }
      Thread.sleep(100);
    }
    assertEquals(Collections.singleton(host), ring.getHosts());

    assertEquals(LOCALHOST, ring.getHostByAddress(LOCALHOST).getAddress());
    ring.close();

    // assure that hosts reload well, too
    ring = new ZkRing(getZk(), ring_root, null, coordinator);
    assertEquals(1, ring.getHosts().size());

    assertEquals(Collections.singleton(host), ring.getHosts());

    assertEquals(LOCALHOST, ring.getHostByAddress(LOCALHOST).getAddress());

    assertTrue(ring.removeHost(LOCALHOST));
    assertNull(ring.getHostByAddress(LOCALHOST));
    assertFalse(ring.removeHost(LOCALHOST));

    ring.close();
  }