ServerService { public List<String> getAvailableServers() { List<String> servers = getAllServers(); List<String> result = new ArrayList<String>(servers.size()); for (String each : servers) { if (isAvailableServer(each)) { result.add(each); } } return result; } 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 assertGetAvailableServers() { when(jobNodeStorage.getJobNodeChildrenKeys("servers")).thenReturn(Arrays.asList("host0", "host2", "host1", "host3")); when(jobNodeStorage.isJobNodeExisted("servers/host0/status")).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("servers/host0/disabled")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("servers/host1/status")).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("servers/host1/disabled")).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("servers/host2/status")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("servers/host3/status")).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("servers/host3/disabled")).thenReturn(false); assertThat(serverService.getAvailableServers(), is(Arrays.asList("host0", "host3"))); verify(jobNodeStorage).getJobNodeChildrenKeys("servers"); verify(jobNodeStorage).isJobNodeExisted("servers/host0/status"); verify(jobNodeStorage).isJobNodeExisted("servers/host0/disabled"); verify(jobNodeStorage).isJobNodeExisted("servers/host1/status"); verify(jobNodeStorage).isJobNodeExisted("servers/host1/disabled"); verify(jobNodeStorage).isJobNodeExisted("servers/host2/status"); verify(jobNodeStorage).isJobNodeExisted("servers/host3/status"); verify(jobNodeStorage).isJobNodeExisted("servers/host3/disabled"); }