### Question:
ZkRingGroup extends AbstractRingGroup implements RingGroup { @Override public boolean claimRingGroupConductor(RingGroupConductorMode mode) throws IOException { try { if (zk.exists(ringGroupConductorOnlinePath, false) == null) { zk.create(ringGroupConductorOnlinePath, BytesUtils.stringToBytes(mode.toString()), CreateMode.EPHEMERAL); return true; } return false; } catch (Exception e) { throw new IOException(e); } } ZkRingGroup(ZooKeeperPlus zk, String ringGroupPath, DomainGroup domainGroup, final Coordinator coordinator); static ZkRingGroup create(ZooKeeperPlus zk, String path, ZkDomainGroup domainGroup, Coordinator coordinator); @Override DomainGroup getDomainGroup(); @Override Ring getRing(int ringNumber); @Override Ring getRingForHost(PartitionServerAddress hostAddress); @Override Set<Ring> getRings(); @Override boolean claimRingGroupConductor(RingGroupConductorMode mode); @Override void releaseRingGroupConductor(); @Override RingGroupConductorMode getRingGroupConductorMode(); @Override void setRingGroupConductorMode(RingGroupConductorMode mode); @Override Ring addRing(int ringNum); @Override boolean removeRing(int ringNum); @Override void addRingGroupConductorModeListener(WatchedNodeListener<RingGroupConductorMode> listener); @Override void removeRingGroupConductorModeListener(WatchedNodeListener<RingGroupConductorMode> listener); @Override List<ClientMetadata> getClients(); @Override List<ConnectedServerMetadata> getLiveServers(); @Override void registerClient(ClientMetadata client); @Override void registerServer(ConnectedServerMetadata metadata); @Override boolean isRingGroupConductorOnline(); boolean delete(); @Override void addDataLocationChangeListener(RingGroupDataLocationChangeListener listener); @Override void removeDataLocationChangeListener(RingGroupDataLocationChangeListener listener); static final String RING_GROUP_CONDUCTOR_ONLINE_PATH; }### Answer:
@Test public void testClaimRingGroupConductor() throws Exception { ZkDomainGroup dg = ZkDomainGroup.create(getZk(), null, dg_root, "blah"); dg.setDomainVersions(Collections.emptyMap()); final RingGroup rg = ZkRingGroup.create(getZk(), ring_group, dg, coordinator); create(ZkPath.append(ring_group, ZkRingGroup.RING_GROUP_CONDUCTOR_ONLINE_PATH)); assertFalse(rg.claimRingGroupConductor(RingGroupConductorMode.ACTIVE)); getZk().delete(ZkPath.append(ring_group, ZkRingGroup.RING_GROUP_CONDUCTOR_ONLINE_PATH), -1); assertTrue(rg.claimRingGroupConductor(RingGroupConductorMode.ACTIVE)); assertFalse(rg.claimRingGroupConductor(RingGroupConductorMode.ACTIVE)); rg.releaseRingGroupConductor(); assertTrue(rg.claimRingGroupConductor(RingGroupConductorMode.ACTIVE)); WaitUntil.orDie(() -> { try { return RingGroupConductorMode.ACTIVE.equals(rg.getRingGroupConductorMode()); } catch (IOException e) { throw new RuntimeException(e); } }); assertEquals(RingGroupConductorMode.ACTIVE, rg.getRingGroupConductorMode()); }