### Question:
PartitionServer implements HostCommandQueueChangeListener, WatchedNodeListener<HostCommand> { public synchronized void stopSynchronized() { stop(); } 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 testColdStartAndShutDown() throws Exception { final SleepingUpdateManager updateManager = new SleepingUpdateManager(); final PartitionServer partitionServer = new MockPartitionServer(fixtures.CONFIGURATOR1, "localhost") { @Override protected IUpdateManager getUpdateManager() { return updateManager; } }; Thread thread = createPartitionServerThread(partitionServer); thread.start(); waitUntilHost(HostState.IDLE, fixtures.host); assertEquals(HostState.IDLE, fixtures.host.getState()); fixtures.host.enqueueCommand(HostCommand.SERVE_DATA); waitUntilHost(HostState.SERVING, fixtures.host); assertEquals(HostState.SERVING, fixtures.host.getState()); fixtures.host.enqueueCommand(HostCommand.GO_TO_IDLE); waitUntilHost(HostState.IDLE, fixtures.host); assertEquals(HostState.IDLE, fixtures.host.getState()); fixtures.host.enqueueCommand(HostCommand.EXECUTE_UPDATE); waitUntilHost(HostState.UPDATING, fixtures.host); assertEquals(HostState.UPDATING, fixtures.host.getState()); WaitUntil.orDie(() -> { try { return updateManager.updateCalled && fixtures.host.getCurrentCommand() == null && HostState.IDLE.equals(fixtures.host.getState()); } catch (IOException e) { throw new RuntimeException(e); } }); assertTrue("Update called", updateManager.updateCalled); assertNull("Current command cleared", fixtures.host.getCurrentCommand()); assertEquals(HostState.IDLE, fixtures.host.getState()); partitionServer.stopSynchronized(); thread.join(); assertEquals(HostState.OFFLINE, fixtures.host.getState()); }
@Test public void testNonEmptyCommandQueue() throws Exception { final SleepingUpdateManager updateManager = new SleepingUpdateManager(); final PartitionServer partitionServer = new MockPartitionServer(fixtures.CONFIGURATOR1, "localhost") { @Override protected IUpdateManager getUpdateManager() { return updateManager; } }; fixtures.host.enqueueCommand(HostCommand.SERVE_DATA); fixtures.host.enqueueCommand(HostCommand.GO_TO_IDLE); fixtures.host.enqueueCommand(HostCommand.EXECUTE_UPDATE); fixtures.host.enqueueCommand(HostCommand.SERVE_DATA); Thread thread = createPartitionServerThread(partitionServer); thread.start(); waitUntilHost(HostState.SERVING, fixtures.host); assertTrue("Update was called", updateManager.updateCalled); assertEquals(HostState.SERVING, fixtures.host.getState()); assertNull("Current command cleared", fixtures.host.getCurrentCommand()); partitionServer.stopSynchronized(); thread.join(); assertEquals(HostState.OFFLINE, fixtures.host.getState()); }