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 } }
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()); }
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(); }
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()); }
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); }
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); }
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(); }
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(); }