ExecutionService { public boolean hasRunningItems(final List<Integer> items) { if (!configService.isMonitorExecution()) { return false; } for (int each : items) { if (jobNodeStorage.isJobNodeExisted(ExecutionNode.getRunningNode(each))) { 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 assertNotHaveRunningItemsWhenJNotMonitorExecution() { when(configService.isMonitorExecution()).thenReturn(false); assertFalse(executionService.hasRunningItems(Arrays.asList(0, 1, 2))); verify(configService).isMonitorExecution(); verify(jobNodeStorage, times(0)).isJobNodeExisted("execution/0/running"); verify(jobNodeStorage, times(0)).isJobNodeExisted("execution/1/running"); verify(jobNodeStorage, times(0)).isJobNodeExisted("execution/2/running"); }
@Test public void assertHasRunningItems() { when(configService.isMonitorExecution()).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("execution/0/running")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("execution/1/running")).thenReturn(true); assertTrue(executionService.hasRunningItems(Arrays.asList(0, 1, 2))); verify(configService).isMonitorExecution(); verify(jobNodeStorage).isJobNodeExisted("execution/0/running"); verify(jobNodeStorage).isJobNodeExisted("execution/1/running"); }
@Test public void assertNotHaveRunningItems() { 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.hasRunningItems(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 assertNotHaveRunningItemsWhenJNotMonitorExecutionForAll() { when(configService.isMonitorExecution()).thenReturn(false); when(jobNodeStorage.getJobNodeChildrenKeys("execution")).thenReturn(Arrays.asList("0", "1", "2")); assertFalse(executionService.hasRunningItems()); verify(configService).isMonitorExecution(); verify(jobNodeStorage).getJobNodeChildrenKeys("execution"); }
@Test public void assertHasRunningItemsForAll() { when(configService.isMonitorExecution()).thenReturn(true); when(jobNodeStorage.getJobNodeChildrenKeys("execution")).thenReturn(Arrays.asList("0", "1", "2")); when(jobNodeStorage.isJobNodeExisted("execution/0/running")).thenReturn(false); when(jobNodeStorage.isJobNodeExisted("execution/1/running")).thenReturn(true); assertTrue(executionService.hasRunningItems()); verify(configService).isMonitorExecution(); verify(jobNodeStorage).getJobNodeChildrenKeys("execution"); verify(jobNodeStorage).isJobNodeExisted("execution/0/running"); verify(jobNodeStorage).isJobNodeExisted("execution/1/running"); }
@Test public void assertNotHaveRunningItemsForAll() { when(configService.isMonitorExecution()).thenReturn(true); when(jobNodeStorage.getJobNodeChildrenKeys("execution")).thenReturn(Arrays.asList("0", "1", "2")); 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.hasRunningItems()); verify(configService).isMonitorExecution(); verify(jobNodeStorage).getJobNodeChildrenKeys("execution"); verify(jobNodeStorage).isJobNodeExisted("execution/0/running"); verify(jobNodeStorage).isJobNodeExisted("execution/1/running"); verify(jobNodeStorage).isJobNodeExisted("execution/2/running"); }