JobStatisticsAPIImpl implements JobStatisticsAPI { @Override public Collection<ExecutionInfo> getExecutionInfo(final String jobName) { String executionRootPath = new JobNodePath(jobName).getExecutionNodePath(); if (!registryCenter.isExisted(executionRootPath)) { return Collections.emptyList(); } List<String> items = registryCenter.getChildrenKeys(executionRootPath); List<ExecutionInfo> result = new ArrayList<>(items.size()); for (String each : items) { result.add(getExecutionInfo(jobName, each)); } Collections.sort(result); return result; }  @Override Collection<JobBriefInfo> getAllJobsBriefInfo(); @Override Collection<ServerInfo> getServers(final String jobName); @Override Collection<ExecutionInfo> getExecutionInfo(final String jobName);  }
@Test public void assertGetExecutionInfoWithMonitorExecution() { when(registryCenter.isExisted("/testJob/execution")).thenReturn(true); when(registryCenter.getChildrenKeys("/testJob/execution")).thenReturn(Arrays.asList("0", "1", "2")); when(registryCenter.isExisted("/testJob/execution/0/running")).thenReturn(true); when(registryCenter.isExisted("/testJob/execution/1/running")).thenReturn(false); when(registryCenter.isExisted("/testJob/execution/1/completed")).thenReturn(true); when(registryCenter.isExisted("/testJob/execution/2/running")).thenReturn(false); when(registryCenter.isExisted("/testJob/execution/2/completed")).thenReturn(false); when(registryCenter.isExisted("/testJob/execution/0/failover")).thenReturn(false); when(registryCenter.isExisted("/testJob/execution/1/failover")).thenReturn(false); when(registryCenter.isExisted("/testJob/execution/2/failover")).thenReturn(true); when(registryCenter.get("/testJob/execution/2/failover")).thenReturn("ip0"); when(registryCenter.get("/testJob/execution/0/lastBeginTime")).thenReturn("0"); when(registryCenter.get("/testJob/execution/1/lastBeginTime")).thenReturn("0"); when(registryCenter.get("/testJob/execution/2/lastBeginTime")).thenReturn(null); when(registryCenter.get("/testJob/execution/0/nextFireTime")).thenReturn("0"); when(registryCenter.get("/testJob/execution/1/nextFireTime")).thenReturn("0"); when(registryCenter.get("/testJob/execution/2/nextFireTime")).thenReturn(null); when(registryCenter.get("/testJob/execution/0/lastCompleteTime")).thenReturn("0"); when(registryCenter.get("/testJob/execution/1/lastCompleteTime")).thenReturn("0"); when(registryCenter.get("/testJob/execution/2/lastCompleteTime")).thenReturn(null); int i = 0; for (ExecutionInfo each : jobStatisticsAPI.getExecutionInfo("testJob")) { i++; assertThat(each.getItem(), is(i - 1)); switch (i) { case 1: assertNull(each.getFailoverIp()); assertThat(each.getLastBeginTime(), is(new Date(0L))); assertThat(each.getNextFireTime(), is(new Date(0L))); assertThat(each.getLastCompleteTime(), is(new Date(0L))); assertThat(each.getStatus(), is(ExecutionInfo.ExecutionStatus.RUNNING)); break; case 2: assertNull(each.getFailoverIp()); assertThat(each.getLastBeginTime(), is(new Date(0L))); assertThat(each.getNextFireTime(), is(new Date(0L))); assertThat(each.getLastCompleteTime(), is(new Date(0L))); assertThat(each.getStatus(), is(ExecutionInfo.ExecutionStatus.COMPLETED)); break; case 3: assertThat(each.getFailoverIp(), is("ip0")); assertNull(each.getLastBeginTime()); assertNull(each.getNextFireTime()); assertNull(each.getLastCompleteTime()); assertThat(each.getStatus(), is(ExecutionInfo.ExecutionStatus.PENDING)); break; default: fail(); } } }
@Test public void assertGetExecutionInfoWithoutMonitorExecution() { when(registryCenter.isExisted("/testJob/execution")).thenReturn(false); assertTrue(jobStatisticsAPI.getExecutionInfo("testJob").isEmpty()); }