@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; } }; // Enqueue commands 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()); }
@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( new Condition() { @Override public boolean test() { 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 testFailToStartWhenHostIsAlreadyOnline() throws IOException, InterruptedException { final PartitionServer partitionServer = new MockPartitionServer(fixtures.CONFIGURATOR1, "localhost"); Thread thread = createPartitionServerThread(partitionServer); thread.start(); Thread.sleep(500); try { new MockPartitionServer(fixtures.CONFIGURATOR1, "localhost"); fail("Should fail to start when host is already online."); } catch (Exception e) { } partitionServer.stopSynchronized(); thread.join(); }
public static Map<String, FilesystemStatisticsAggregator> computeFilesystemStatistics(Host host) throws IOException { return PartitionServer.getFilesystemStatistics(host); }