ServerService { public boolean hasAvailableServers() { List<String> servers = jobNodeStorage.getJobNodeChildrenKeys(ServerNode.ROOT); for (String each : servers) { if (isAvailableServer(each)) { return true; } } return false; } ServerService(final CoordinatorRegistryCenter regCenter, final String jobName); void persistOnline(final boolean enabled); boolean hasAvailableServers(); boolean isAvailableServer(final String ip); boolean isEnableServer(final String ip);  }
@Test public void assertHasAvailableServers() { when(jobNodeStorage.getJobNodeChildrenKeys("servers")).thenReturn(Arrays.asList("127.0.0.1", "127.0.0.2", "127.0.0.3")); when(jobNodeStorage.getJobNodeData("servers/127.0.0.1")).thenReturn(ServerStatus.DISABLED.name()); when(jobNodeStorage.getJobNodeData("servers/127.0.0.2")).thenReturn(ServerStatus.ENABLED.name()); when(jobNodeStorage.getJobNodeData("servers/127.0.0.3")).thenReturn(ServerStatus.ENABLED.name()); when(jobNodeStorage.getJobNodeChildrenKeys("instances")).thenReturn(Collections.singletonList("127.0.0.3@-@0")); assertTrue(serverService.hasAvailableServers()); }
@Test public void assertHasNotAvailableServers() { when(jobNodeStorage.getJobNodeChildrenKeys("servers")).thenReturn(Arrays.asList("127.0.0.1", "127.0.0.2")); when(jobNodeStorage.getJobNodeData("servers/127.0.0.1")).thenReturn(ServerStatus.DISABLED.name()); when(jobNodeStorage.getJobNodeData("servers/127.0.0.2")).thenReturn(ServerStatus.DISABLED.name()); assertFalse(serverService.hasAvailableServers()); }