### Question:
ZkHost extends AbstractHost { @Override public void setState(HostState stateValue) throws IOException { try { if (stateValue == HostState.OFFLINE) { zk.deleteIfExists(state.getPath()); } else { zk.setOrCreate(state.getPath(), stateValue.toString(), CreateMode.EPHEMERAL); } } catch (Exception e) { throw new IOException(e); } } ZkHost(final ZooKeeperPlus zk,
                final Coordinator coordinator,
                final String path,
                final DataLocationChangeListener dataLocationChangeListener,
                final boolean create,
                final HostMetadata initialMetadata,
                final HostAssignmentsMetadata initialAssignments); static ZkHost create(ZooKeeperPlus zk,
                              Coordinator coordinator,
                              String root,
                              PartitionServerAddress partitionServerAddress,
                              DataLocationChangeListener dataLocationChangeListener,
                              List<String> flags); @Override PartitionServerAddress getAddress(); @Override void setAddress(final PartitionServerAddress address); @Override HostState getState(); @Override void setState(HostState stateValue); @Override Long getUpSince(); @Override List<String> getFlags(); @Override void setFlags(final List<String> flags); @Override void setStateChangeListener(final WatchedNodeListener<HostState> listener); @Override void cancelStateChangeListener(final WatchedNodeListener<HostState> listener); @Override HostCommand getCurrentCommand(); @Override void enqueueCommand(HostCommand command); @Override List<HostCommand> getCommandQueue(); @Override HostCommand nextCommand(); @Override void setCommandQueueChangeListener(HostCommandQueueChangeListener listener); @Override void setCurrentCommandChangeListener(WatchedNodeListener<HostCommand> listener); @Override void clearCommandQueue(); @Override Set<HostDomain> getAssignedDomains(); @Override HostDomain addDomain(Domain domain); @Override void removeDomain(Domain domain); @Override void setEphemeralStatistic(final String key, final String value); @Override String getStatistic(String key); @Override void setRuntimeStatisticsSummary(RuntimeStatisticsSummary summary); @Override RuntimeStatisticsSummary getRuntimeStatisticsSummary(); @Override void deleteStatistic(final String key); @Override void setEnvironmentFlags(Map<String, String> flags); @Override Map<String, String> getEnvironmentFlags(); void delete(); void close(); @Override int hashCode(); @Override boolean equals(Object obj);  }### Answer:
@Test public void testSetState() throws Exception { ZkHost host = ZkHost.create(getZk(), coordinator, getRoot(), ADDRESS, null, Collections.emptyList()); assertEquals(HostState.OFFLINE, host.getState()); assertFalse(Hosts.isOnline(host)); host.setState(HostState.IDLE); waitUntilHost(HostState.IDLE, host); assertEquals(HostState.IDLE, host.getState()); assertTrue(Hosts.isOnline(host)); host.setState(HostState.OFFLINE); waitUntilHost(HostState.OFFLINE, host); assertEquals(HostState.OFFLINE, host.getState()); assertFalse(Hosts.isOnline(host)); host.close(); }