JobStatisticsAPIImpl implements JobStatisticsAPI { @Override public Collection<ServerInfo> getServers(final String jobName) { JobNodePath jobNodePath = new JobNodePath(jobName); List<String> serverIps = registryCenter.getChildrenKeys(jobNodePath.getServerNodePath()); Collection<ServerInfo> result = new ArrayList<>(serverIps.size()); for (String each : serverIps) { result.add(getJobServer(jobName, each)); } return result; }  @Override Collection<JobBriefInfo> getAllJobsBriefInfo(); @Override Collection<ServerInfo> getServers(final String jobName); @Override Collection<ExecutionInfo> getExecutionInfo(final String jobName);  }
@Test public void assertGetServers() { when(registryCenter.getChildrenKeys("/testJob/servers")).thenReturn(Arrays.asList("ip1", "ip2")); when(registryCenter.get("/testJob/servers/ip1/hostName")).thenReturn("host1"); when(registryCenter.get("/testJob/servers/ip2/hostName")).thenReturn("host2"); when(registryCenter.get("/testJob/servers/ip1/processSuccessCount")).thenReturn("101"); when(registryCenter.get("/testJob/servers/ip2/processSuccessCount")).thenReturn("102"); when(registryCenter.get("/testJob/servers/ip1/processFailureCount")).thenReturn("11"); when(registryCenter.get("/testJob/servers/ip2/processFailureCount")).thenReturn("12"); when(registryCenter.get("/testJob/servers/ip1/sharding")).thenReturn("0,1"); when(registryCenter.get("/testJob/servers/ip2/sharding")).thenReturn("2,3"); when(registryCenter.get("/testJob/servers/ip1/status")).thenReturn("RUNNING"); when(registryCenter.get("/testJob/servers/ip2/status")).thenReturn("READY"); int i = 0; for (ServerInfo each : jobStatisticsAPI.getServers("testJob")) { i++; assertThat(each.getJobName(), is("testJob")); assertThat(each.getIp(), is("ip" + i)); assertThat(each.getHostName(), is("host" + i)); switch (i) { case 1: assertThat(each.getProcessSuccessCount(), is(101)); assertThat(each.getProcessFailureCount(), is(11)); assertThat(each.getStatus(), is(ServerInfo.ServerStatus.RUNNING)); break; case 2: assertThat(each.getProcessSuccessCount(), is(102)); assertThat(each.getProcessFailureCount(), is(12)); assertThat(each.getStatus(), is(ServerInfo.ServerStatus.READY)); break; default: fail(); } } }