ServerService { public boolean isLocalhostServerReady() { String ip = localHostService.getIp(); return isAvailableServer(ip) && ServerStatus.READY.name().equals(jobNodeStorage.getJobNodeData(ServerNode.getStatusNode(ip))); } ServerService(final CoordinatorRegistryCenter coordinatorRegistryCenter, final JobConfiguration jobConfiguration); void clearPreviousServerStatus(); void persistServerOnline(); void clearJobTriggerStatus(); void clearJobPausedStatus(); boolean isJobPausedManually(); void processServerShutdown(); void updateServerStatus(final ServerStatus status); void removeServerStatus(); List<String> getAllServers(); List<String> getAvailableServers(); boolean isAvailableServer(final String ip); boolean isLocalServerDisabled(); boolean isLocalhostServerReady(); void persistProcessSuccessCount(final int processSuccessCount); void persistProcessFailureCount(final int processFailureCount);  }
@Test public void assertIsLocalhostServerReadyWhenServerCrashed() { when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/status")).thenReturn(false); assertFalse(serverService.isLocalhostServerReady()); verify(localHostService).getIp(); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/status"); }
@Test public void assertIsLocalhostServerReadyWhenServerPaused() { when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/status")).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/paused")).thenReturn(true); assertFalse(serverService.isLocalhostServerReady()); verify(localHostService).getIp(); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/paused"); }
@Test public void assertIsLocalhostServerReadyWhenServerDisabled() { when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/status")).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/paused")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/disabled")).thenReturn(true); assertFalse(serverService.isLocalhostServerReady()); verify(localHostService).getIp(); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/paused"); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/disabled"); }
@Test public void assertIsLocalhostServerReadyWhenServerShutdown() { when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/status")).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/paused")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/disabled")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/shutdown")).thenReturn(true); assertFalse(serverService.isLocalhostServerReady()); verify(localHostService).getIp(); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/paused"); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/disabled"); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/shutdown"); }
@Test public void assertIsLocalhostServerReadyWhenServerRunning() { when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/status")).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/paused")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/disabled")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/shutdown")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/status")).thenReturn(true); when(jobNodeStorage.getJobNodeData("servers/mockedIP/status")).thenReturn("RUNNING"); assertFalse(serverService.isLocalhostServerReady()); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/status"); verify(localHostService).getIp(); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/paused"); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/disabled"); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/shutdown"); verify(jobNodeStorage).getJobNodeData("servers/mockedIP/status"); }
@Test public void assertIsLocalhostServerReadyWhenServerReady() { when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/status")).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/paused")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/disabled")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/shutdown")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/status")).thenReturn(true); when(jobNodeStorage.getJobNodeData("servers/mockedIP/status")).thenReturn("READY"); assertTrue(serverService.isLocalhostServerReady()); verify(localHostService).getIp(); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/status"); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/paused"); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/disabled"); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/shutdown"); verify(jobNodeStorage).getJobNodeData("servers/mockedIP/status"); }