ExecutionService { public void registerJobBegin(final JobExecutionMultipleShardingContext jobExecutionShardingContext) { if (!jobExecutionShardingContext.getShardingItems().isEmpty() && configService.isMonitorExecution()) { serverService.updateServerStatus(ServerStatus.RUNNING); for (int each : jobExecutionShardingContext.getShardingItems()) { jobNodeStorage.fillEphemeralJobNode(ExecutionNode.getRunningNode(each), ""); jobNodeStorage.replaceJobNode(ExecutionNode.getLastBeginTimeNode(each), System.currentTimeMillis()); JobScheduleController jobScheduleController = JobRegistry.getInstance().getJobScheduleController(jobConfiguration.getJobName()); if (null == jobScheduleController) { continue; } Date nextFireTime = jobScheduleController.getNextFireTime(); if (null != nextFireTime) { jobNodeStorage.replaceJobNode(ExecutionNode.getNextFireTimeNode(each), nextFireTime.getTime()); } } } } 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 assertRegisterJobBeginWhenNotAssignAnyItem() { executionService.registerJobBegin(new JobExecutionMultipleShardingContext()); verify(configService, times(0)).isMonitorExecution(); }
@Test public void assertRegisterJobBeginWhenNotMonitorExecution() { when(configService.isMonitorExecution()).thenReturn(false); JobExecutionMultipleShardingContext jobExecutionShardingContext = new JobExecutionMultipleShardingContext(); jobExecutionShardingContext.setShardingItems(Arrays.asList(0, 1, 2)); executionService.registerJobBegin(jobExecutionShardingContext); verify(configService).isMonitorExecution(); }
@Test public void assertRegisterJobBeginWithoutNextFireTime() { when(configService.isMonitorExecution()).thenReturn(true); when(jobScheduleController.getNextFireTime()).thenReturn(null); JobRegistry.getInstance().addJobScheduleController("testJob", jobScheduleController); JobExecutionMultipleShardingContext jobExecutionShardingContext = new JobExecutionMultipleShardingContext(); jobExecutionShardingContext.setShardingItems(Arrays.asList(0, 1, 2)); executionService.registerJobBegin(jobExecutionShardingContext); verify(configService).isMonitorExecution(); verify(serverService).updateServerStatus(ServerStatus.RUNNING); verify(jobNodeStorage).fillEphemeralJobNode("execution/0/running", ""); verify(jobNodeStorage).fillEphemeralJobNode("execution/1/running", ""); verify(jobNodeStorage).fillEphemeralJobNode("execution/2/running", ""); verify(jobNodeStorage).replaceJobNode(eq("execution/0/lastBeginTime"), anyLong()); verify(jobNodeStorage).replaceJobNode(eq("execution/1/lastBeginTime"), anyLong()); verify(jobNodeStorage).replaceJobNode(eq("execution/2/lastBeginTime"), anyLong()); }
@Test public void assertRegisterJobBeginWithNextFireTime() { when(configService.isMonitorExecution()).thenReturn(true); when(jobScheduleController.getNextFireTime()).thenReturn(new Date(0L)); JobRegistry.getInstance().addJobScheduleController("testJob", jobScheduleController); JobExecutionMultipleShardingContext jobExecutionShardingContext = new JobExecutionMultipleShardingContext(); jobExecutionShardingContext.setShardingItems(Arrays.asList(0, 1, 2)); executionService.registerJobBegin(jobExecutionShardingContext); verify(configService).isMonitorExecution(); verify(serverService).updateServerStatus(ServerStatus.RUNNING); verify(jobNodeStorage).fillEphemeralJobNode("execution/0/running", ""); verify(jobNodeStorage).fillEphemeralJobNode("execution/1/running", ""); verify(jobNodeStorage).fillEphemeralJobNode("execution/2/running", ""); verify(jobNodeStorage).replaceJobNode(eq("execution/0/lastBeginTime"), anyLong()); verify(jobNodeStorage).replaceJobNode(eq("execution/1/lastBeginTime"), anyLong()); verify(jobNodeStorage).replaceJobNode(eq("execution/2/lastBeginTime"), anyLong()); verify(jobNodeStorage).replaceJobNode("execution/0/nextFireTime", 0L); verify(jobNodeStorage).replaceJobNode("execution/1/nextFireTime", 0L); verify(jobNodeStorage).replaceJobNode("execution/2/nextFireTime", 0L); }