@Test public void assertGetShardingContextWhenIsFailoverEnableAndFailover() { ShardingContexts shardingContexts = new ShardingContexts("fake_task_id", "test_job", 10, "", Collections.emptyMap()); when(configService.load(true)).thenReturn(JobConfiguration.newBuilder("test_job", 3).cron("0/1 * * * * ?").failover(true).monitorExecution(true).build()); when(failoverService.getLocalFailoverItems()).thenReturn(Collections.singletonList(1)); when(executionContextService.getJobShardingContext(Collections.singletonList(1))).thenReturn(shardingContexts); assertThat(liteJobFacade.getShardingContexts(), is(shardingContexts)); verify(shardingService, times(0)).shardingIfNecessary(); }
@Override public ShardingContexts getShardingContexts() { boolean isFailover = configService.load(true).isFailover(); if (isFailover) { List<Integer> failoverShardingItems = failoverService.getLocalFailoverItems(); if (!failoverShardingItems.isEmpty()) { return executionContextService.getJobShardingContext(failoverShardingItems); } } shardingService.shardingIfNecessary(); List<Integer> shardingItems = shardingService.getLocalShardingItems(); if (isFailover) { shardingItems.removeAll(failoverService.getLocalTakeOffItems()); } shardingItems.removeAll(executionService.getDisabledItems(shardingItems)); return executionContextService.getJobShardingContext(shardingItems); }
LiteJobFacade implements JobFacade { @Override public ShardingContexts getShardingContexts() { boolean isFailover = configService.load(true).isFailover(); if (isFailover) { List<Integer> failoverShardingItems = failoverService.getLocalFailoverItems(); if (!failoverShardingItems.isEmpty()) { return executionContextService.getJobShardingContext(failoverShardingItems); } } shardingService.shardingIfNecessary(); List<Integer> shardingItems = shardingService.getLocalShardingItems(); if (isFailover) { shardingItems.removeAll(failoverService.getLocalTakeOffItems()); } shardingItems.removeAll(executionService.getDisabledItems(shardingItems)); return executionContextService.getJobShardingContext(shardingItems); } }
LiteJobFacade implements JobFacade { @Override public ShardingContexts getShardingContexts() { boolean isFailover = configService.load(true).isFailover(); if (isFailover) { List<Integer> failoverShardingItems = failoverService.getLocalFailoverItems(); if (!failoverShardingItems.isEmpty()) { return executionContextService.getJobShardingContext(failoverShardingItems); } } shardingService.shardingIfNecessary(); List<Integer> shardingItems = shardingService.getLocalShardingItems(); if (isFailover) { shardingItems.removeAll(failoverService.getLocalTakeOffItems()); } shardingItems.removeAll(executionService.getDisabledItems(shardingItems)); return executionContextService.getJobShardingContext(shardingItems); } LiteJobFacade(final CoordinatorRegistryCenter regCenter, final String jobName, final Collection<ElasticJobListener> elasticJobListeners, final TracingConfiguration tracingConfig); }
LiteJobFacade implements JobFacade { @Override public ShardingContexts getShardingContexts() { boolean isFailover = configService.load(true).isFailover(); if (isFailover) { List<Integer> failoverShardingItems = failoverService.getLocalFailoverItems(); if (!failoverShardingItems.isEmpty()) { return executionContextService.getJobShardingContext(failoverShardingItems); } } shardingService.shardingIfNecessary(); List<Integer> shardingItems = shardingService.getLocalShardingItems(); if (isFailover) { shardingItems.removeAll(failoverService.getLocalTakeOffItems()); } shardingItems.removeAll(executionService.getDisabledItems(shardingItems)); return executionContextService.getJobShardingContext(shardingItems); } LiteJobFacade(final CoordinatorRegistryCenter regCenter, final String jobName, final Collection<ElasticJobListener> elasticJobListeners, final TracingConfiguration tracingConfig); @Override JobConfiguration loadJobConfiguration(final boolean fromCache); @Override void checkJobExecutionEnvironment(); @Override void failoverIfNecessary(); @Override void registerJobBegin(final ShardingContexts shardingContexts); @Override void registerJobCompleted(final ShardingContexts shardingContexts); @Override ShardingContexts getShardingContexts(); @Override boolean misfireIfRunning(final Collection<Integer> shardingItems); @Override void clearMisfire(final Collection<Integer> shardingItems); @Override boolean isExecuteMisfired(final Collection<Integer> shardingItems); @Override boolean isNeedSharding(); @Override void beforeJobExecuted(final ShardingContexts shardingContexts); @Override void afterJobExecuted(final ShardingContexts shardingContexts); @Override void postJobExecutionEvent(final JobExecutionEvent jobExecutionEvent); @Override void postJobStatusTraceEvent(final String taskId, final State state, final String message); }
LiteJobFacade implements JobFacade { @Override public ShardingContexts getShardingContexts() { boolean isFailover = configService.load(true).isFailover(); if (isFailover) { List<Integer> failoverShardingItems = failoverService.getLocalFailoverItems(); if (!failoverShardingItems.isEmpty()) { return executionContextService.getJobShardingContext(failoverShardingItems); } } shardingService.shardingIfNecessary(); List<Integer> shardingItems = shardingService.getLocalShardingItems(); if (isFailover) { shardingItems.removeAll(failoverService.getLocalTakeOffItems()); } shardingItems.removeAll(executionService.getDisabledItems(shardingItems)); return executionContextService.getJobShardingContext(shardingItems); } LiteJobFacade(final CoordinatorRegistryCenter regCenter, final String jobName, final Collection<ElasticJobListener> elasticJobListeners, final TracingConfiguration tracingConfig); @Override JobConfiguration loadJobConfiguration(final boolean fromCache); @Override void checkJobExecutionEnvironment(); @Override void failoverIfNecessary(); @Override void registerJobBegin(final ShardingContexts shardingContexts); @Override void registerJobCompleted(final ShardingContexts shardingContexts); @Override ShardingContexts getShardingContexts(); @Override boolean misfireIfRunning(final Collection<Integer> shardingItems); @Override void clearMisfire(final Collection<Integer> shardingItems); @Override boolean isExecuteMisfired(final Collection<Integer> shardingItems); @Override boolean isNeedSharding(); @Override void beforeJobExecuted(final ShardingContexts shardingContexts); @Override void afterJobExecuted(final ShardingContexts shardingContexts); @Override void postJobExecutionEvent(final JobExecutionEvent jobExecutionEvent); @Override void postJobStatusTraceEvent(final String taskId, final State state, final String message);  }