JobRunningStatisticJob extends AbstractStatisticJob { @Override public void execute(final JobExecutionContext context) { Map<String, Set<TaskContext>> allRunningTasks = runningService.getAllRunningTasks(); statisticJob(getJobRunningCount(allRunningTasks)); statisticTask(getTaskRunningCount(allRunningTasks)); } JobRunningStatisticJob(final CoordinatorRegistryCenter registryCenter, final StatisticRdbRepository rdbRepository); @Override JobDetail buildJobDetail(); @Override Trigger buildTrigger(); @Override Map<String, Object> getDataMap(); @Override void execute(final JobExecutionContext context);  }
@Test public void assertExecuteWhenRepositoryIsEmpty() { Optional<JobRunningStatistics> latestJobRunningStatistics = Optional.empty(); Optional<TaskRunningStatistics> latestTaskRunningStatistics = Optional.empty(); when(repository.findLatestJobRunningStatistics()).thenReturn(latestJobRunningStatistics); when(repository.findLatestTaskRunningStatistics()).thenReturn(latestTaskRunningStatistics); when(repository.add(ArgumentMatchers.any(JobRunningStatistics.class))).thenReturn(true); when(repository.add(ArgumentMatchers.any(TaskRunningStatistics.class))).thenReturn(true); when(runningService.getAllRunningTasks()).thenReturn(Collections.emptyMap()); jobRunningStatisticJob.execute(null); verify(repository).findLatestJobRunningStatistics(); verify(repository).add(ArgumentMatchers.any(JobRunningStatistics.class)); verify(repository).add(ArgumentMatchers.any(TaskRunningStatistics.class)); verify(runningService).getAllRunningTasks(); }
@Test public void assertExecute() { Optional<JobRunningStatistics> latestJobRunningStatistics = Optional.of(new JobRunningStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.MINUTE, -3))); Optional<TaskRunningStatistics> latestTaskRunningStatistics = Optional.of(new TaskRunningStatistics(0, StatisticTimeUtils.getStatisticTime(StatisticInterval.MINUTE, -3))); when(repository.findLatestJobRunningStatistics()).thenReturn(latestJobRunningStatistics); when(repository.findLatestTaskRunningStatistics()).thenReturn(latestTaskRunningStatistics); when(repository.add(ArgumentMatchers.any(JobRunningStatistics.class))).thenReturn(true); when(repository.add(ArgumentMatchers.any(TaskRunningStatistics.class))).thenReturn(true); Map<String, Set<TaskContext>> jobMap = new HashMap<>(1); Set<TaskContext> jobSet = new HashSet<>(1); jobSet.add(TaskContext.from(TaskNode.builder().jobName("test_job").build().getTaskNodeValue())); jobMap.put("test_job", jobSet); when(runningService.getAllRunningTasks()).thenReturn(jobMap); jobRunningStatisticJob.execute(null); verify(repository).findLatestJobRunningStatistics(); verify(repository).findLatestTaskRunningStatistics(); verify(repository, times(3)).add(ArgumentMatchers.any(JobRunningStatistics.class)); verify(repository, times(3)).add(ArgumentMatchers.any(TaskRunningStatistics.class)); verify(runningService).getAllRunningTasks(); }