### Question:
PartitionServer implements HostCommandQueueChangeListener, WatchedNodeListener<HostCommand> { public void run() throws IOException, InterruptedException { connectToRing(); addShutdownHook(); setStateSynchronized(HostState.IDLE); addServerOfflineWatcher(); while (host.getState() != HostState.IDLE) { LOG.info("Waiting for Host state " + HostState.IDLE + " to propagate."); Thread.sleep(100); } processCommandOnStartup(); while (!stopping) { try { HostCommand command = commandQueue.poll(MAIN_THREAD_STEP_SLEEP_MS, TimeUnit.MILLISECONDS); if (command != null) { try { processCommand(command, host.getState()); } catch (IOException e) { LOG.error("Failed to process command: " + command, e); break; } } } catch (InterruptedException e) { LOG.info("Interrupted in main loop. Exiting.", e); break; } } LOG.info("Partition server main thread is stopping."); stopServingData(); stopUpdating(); setStateSynchronized(HostState.OFFLINE); removeShutdownHook(); coordinator.close(); } PartitionServer(PartitionServerConfigurator configurator, String hostName); void run(); synchronized void stopSynchronized(); @Override synchronized void onCommandQueueChange(Host host); @Override void onWatchedNodeChange(final HostCommand command); void processCommandOnStartup(); static void main(String[] args);  }### Answer:
@Test public void testWaitUntilRingAssignment() throws IOException, InterruptedException { final Ring mockRing = new MockRing(null, null, 0); final Map<PartitionServerAddress, Ring> hostToRing = Maps.newHashMap(); final RingGroup mockRingGroup = new MockRingGroup(null, "myRingGroup", Sets.newHashSet()) { @Override public Ring getRingForHost(PartitionServerAddress hostAddress) { return hostToRing.get(hostAddress); } }; final MockCoordinator mockCoord = new MockCoordinator() { @Override public RingGroup getRingGroup(String ringGroupName) { return mockRingGroup; } }; MockPartitionServerConfigurator configurator = new MockPartitionServerConfigurator(12345, mockCoord, "myRingGroup", null); final PartitionServer partitionServer = new MockPartitionServer(configurator, "localhost"); AtomicBoolean serverDead = new AtomicBoolean(false); new Thread(() -> { try { partitionServer.run(); serverDead.set(true); } catch (Exception e) { throw new RuntimeException(e); } }).start(); WaitUntil.orDie(() -> { try { return mockRingGroup.getLiveServers().size() == 1; } catch (IOException e) { throw new RuntimeException(e); } }); assertFalse(serverDead.get()); PartitionServerAddress address = new PartitionServerAddress("localhost", 12345); mockRing.addHost(address, Lists.newArrayList()); hostToRing.put(address, mockRing); WaitUntil.orDie(() -> { try { return mockRing.getHostByAddress(address).getState() == HostState.IDLE; } catch (IOException e) { throw new RuntimeException(e); } }); }