ServerStatisticsAPIImpl implements ServerStatisticsAPI { @Override public Collection<ServerInfo> getJobs(final String serverIp) { List<String> jobs = registryCenter.getChildrenKeys("/"); Collection<ServerInfo> result = new ArrayList<ServerInfo>(jobs.size()); for (String each : jobs) { JobNodePath jobNodePath = new JobNodePath(each); if (registryCenter.isExisted(jobNodePath.getServerNodePath(serverIp))) { result.add(getJob(serverIp, each)); } } return result; }  @Override Collection<ServerBriefInfo> getAllServersBriefInfo(); @Override Collection<ServerInfo> getJobs(final String serverIp);  }
@Test public void assertGetJobs() { when(registryCenter.getChildrenKeys("/")).thenReturn(Arrays.asList("testJob1", "testJob2", "testJob3")); when(registryCenter.isExisted("/testJob1/servers/localhost")).thenReturn(true); when(registryCenter.isExisted("/testJob2/servers/localhost")).thenReturn(true); when(registryCenter.isExisted("/testJob3/servers/localhost")).thenReturn(false); when(registryCenter.get("/testJob1/servers/localhost/hostName")).thenReturn("localhost"); when(registryCenter.get("/testJob2/servers/localhost/hostName")).thenReturn("localhost"); when(registryCenter.get("/testJob1/servers/localhost/processSuccessCount")).thenReturn("100"); when(registryCenter.get("/testJob2/servers/localhost/processSuccessCount")).thenReturn(null); when(registryCenter.get("/testJob1/servers/localhost/processFailureCount")).thenReturn("10"); when(registryCenter.get("/testJob2/servers/localhost/processFailureCount")).thenReturn(null); when(registryCenter.get("/testJob1/servers/localhost/sharding")).thenReturn("0,1"); when(registryCenter.get("/testJob2/servers/localhost/sharding")).thenReturn("2"); when(registryCenter.get("/testJob1/servers/localhost/status")).thenReturn("RUNNING"); when(registryCenter.get("/testJob2/servers/localhost/status")).thenReturn("RUNNING"); when(registryCenter.isExisted("/testJob1/servers/localhost/disabled")).thenReturn(false); when(registryCenter.isExisted("/testJob2/servers/localhost/disabled")).thenReturn(false); when(registryCenter.isExisted("/testJob1/servers/localhost/paused")).thenReturn(false); when(registryCenter.isExisted("/testJob2/servers/localhost/paused")).thenReturn(false); when(registryCenter.isExisted("/testJob1/servers/localhost/shutdown")).thenReturn(false); when(registryCenter.isExisted("/testJob2/servers/localhost/shutdown")).thenReturn(false); int i = 0; for (ServerInfo each : serverStatisticsAPI.getJobs("localhost")) { i++; assertThat(each.getJobName(), is("testJob" + i)); assertThat(each.getIp(), is("localhost")); assertThat(each.getHostName(), is("localhost")); assertThat(each.getStatus(), is(ServerInfo.ServerStatus.RUNNING)); switch (i) { case 1: assertThat(each.getProcessSuccessCount(), is(100)); assertThat(each.getProcessFailureCount(), is(10)); assertThat(each.getSharding(), is("0,1")); break; case 2: assertThat(each.getProcessSuccessCount(), is(0)); assertThat(each.getProcessFailureCount(), is(0)); assertThat(each.getSharding(), is("2")); break; default: fail(); } } }