@Before
 public void setUp() {
   ProcessCountStatistics.reset(jobName);
   jobConfig.setShardingItemParameters("0=A,1=B,2=C");
   jobConfig.setDisabled(disabled);
   jobConfig.setMonitorPort(monitorPort);
   jobConfig.setOverwrite(true);
   REG_CENTER.init();
 }
 public MonitorService(
     final CoordinatorRegistryCenter coordinatorRegistryCenter,
     final JobConfiguration jobConfiguration) {
   jobName = jobConfiguration.getJobName();
   this.coordinatorRegistryCenter = coordinatorRegistryCenter;
   configService = new ConfigurationService(coordinatorRegistryCenter, jobConfiguration);
 }
 /**
  * 获取当前作业服务器运行时分片上下文.
  *
  * @return 当前作业服务器运行时分片上下文
  */
 public JobExecutionMultipleShardingContext getJobExecutionShardingContext() {
   JobExecutionMultipleShardingContext result = new JobExecutionMultipleShardingContext();
   result.setJobName(jobConfiguration.getJobName());
   result.setShardingTotalCount(configService.getShardingTotalCount());
   List<Integer> shardingItems = shardingService.getLocalHostShardingItems();
   if (configService.isFailover()) {
     List<Integer> failoverItems = failoverService.getLocalHostFailoverItems();
     if (!failoverItems.isEmpty()) {
       result.setShardingItems(failoverItems);
     } else {
       shardingItems.removeAll(failoverService.getLocalHostTakeOffItems());
       result.setShardingItems(shardingItems);
     }
   } else {
     result.setShardingItems(shardingItems);
   }
   boolean isMonitorExecution = configService.isMonitorExecution();
   if (isMonitorExecution) {
     removeRunningItems(shardingItems);
   }
   result.setJobParameter(configService.getJobParameter());
   result.setMonitorExecution(isMonitorExecution);
   result.setFetchDataCount(configService.getFetchDataCount());
   if (result.getShardingItems().isEmpty()) {
     return result;
   }
   Map<Integer, String> shardingItemParameters = configService.getShardingItemParameters();
   for (int each : result.getShardingItems()) {
     if (shardingItemParameters.containsKey(each)) {
       result.getShardingItemParameters().put(each, shardingItemParameters.get(each));
     }
   }
   result.setOffsets(offsetService.getOffsets(result.getShardingItems()));
   return result;
 }
 @Before
 public void setUp() throws NoSuchFieldException {
   MockitoAnnotations.initMocks(this);
   ReflectionUtils.setFieldValue(leaderElectionService, "jobNodeStorage", jobNodeStorage);
   ReflectionUtils.setFieldValue(leaderElectionService, "localHostService", localHostService);
   when(localHostService.getIp()).thenReturn("mockedIP");
   when(localHostService.getHostName()).thenReturn("mockedHostName");
   when(jobNodeStorage.getJobConfiguration()).thenReturn(jobConfig);
   jobConfig.setOverwrite(true);
 }
 /**
  * 注册作业启动信息.
  *
  * @param jobExecutionShardingContext 作业运行时分片上下文
  */
 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());
       Date nextFireTime =
           JobRegistry.getInstance().getJob(jobConfiguration.getJobName()).getNextFireTime();
       if (null != nextFireTime) {
         jobNodeStorage.replaceJobNode(
             ExecutionNode.getNextFireTimeNode(each), nextFireTime.getTime());
       }
     }
   }
 }