ExecutionService { public boolean misfireIfNecessary(final List<Integer> items) { if (hasRunningItems(items)) { setMisfire(items); return true; } return false; } ExecutionService(final CoordinatorRegistryCenter coordinatorRegistryCenter, final JobConfiguration jobConfiguration); void registerJobBegin(final JobExecutionMultipleShardingContext jobExecutionShardingContext); void cleanPreviousExecutionInfo(); void registerJobCompleted(final JobExecutionMultipleShardingContext jobExecutionShardingContext); void setNeedFixExecutionInfoFlag(); void clearRunningInfo(final List<Integer> items); boolean misfireIfNecessary(final List<Integer> items); void setMisfire(final List<Integer> items); List<Integer> getMisfiredJobItems(final List<Integer> items); void clearMisfire(final List<Integer> items); void removeExecutionInfo(); boolean isCompleted(final int item); boolean hasRunningItems(final List<Integer> items); boolean hasRunningItems();  }
@Test public void assertMisfireIfNotNecessaryWhenNotMonitorExecution() { when(configService.isMonitorExecution()).thenReturn(false); assertFalse(executionService.misfireIfNecessary(Arrays.asList(0, 1, 2))); verify(configService).isMonitorExecution(); }
@Test public void assertMisfireIfNotNecessary() { when(configService.isMonitorExecution()).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("execution/0/running")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("execution/1/running")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("execution/2/running")).thenReturn(false); assertFalse(executionService.misfireIfNecessary(Arrays.asList(0, 1, 2))); verify(configService).isMonitorExecution(); verify(jobNodeStorage).isJobNodeExisted("execution/0/running"); verify(jobNodeStorage).isJobNodeExisted("execution/1/running"); verify(jobNodeStorage).isJobNodeExisted("execution/2/running"); }
@Test public void assertMisfireIfNecessary() { when(configService.isMonitorExecution()).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("execution/0/running")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("execution/1/running")).thenReturn(true); assertTrue(executionService.misfireIfNecessary(Arrays.asList(0, 1, 2))); verify(configService, times(2)).isMonitorExecution(); verify(jobNodeStorage).isJobNodeExisted("execution/0/running"); verify(jobNodeStorage).isJobNodeExisted("execution/1/running"); verify(jobNodeStorage).createJobNodeIfNeeded("execution/0/misfire"); verify(jobNodeStorage).createJobNodeIfNeeded("execution/1/misfire"); verify(jobNodeStorage).createJobNodeIfNeeded("execution/2/misfire"); }