コード例 #1
0
 /**
  * 获取当前作业服务器运行时分片上下文.
  *
  * @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;
 }
コード例 #2
0
 @Test
 public void assertGetLocalHostFailoverItems() {
   when(jobNodeStorage.getJobNodeChildrenKeys("execution"))
       .thenReturn(Arrays.asList("0", "1", "2"));
   when(jobNodeStorage.isJobNodeExisted("execution/0/failover")).thenReturn(true);
   when(jobNodeStorage.isJobNodeExisted("execution/1/failover")).thenReturn(true);
   when(jobNodeStorage.isJobNodeExisted("execution/2/failover")).thenReturn(false);
   when(jobNodeStorage.getJobNodeDataDirectly("execution/0/failover")).thenReturn("mockedIP");
   when(jobNodeStorage.getJobNodeDataDirectly("execution/1/failover")).thenReturn("otherIP");
   assertThat(failoverService.getLocalHostFailoverItems(), is(Collections.singletonList(0)));
   verify(jobNodeStorage).getJobNodeChildrenKeys("execution");
   verify(localHostService).getIp();
   verify(jobNodeStorage).isJobNodeExisted("execution/0/failover");
   verify(jobNodeStorage).isJobNodeExisted("execution/1/failover");
   verify(jobNodeStorage).getJobNodeDataDirectly("execution/0/failover");
   verify(jobNodeStorage).getJobNodeDataDirectly("execution/1/failover");
 }