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