FailoverService { public Collection<JobContext> getAllEligibleJobContexts() { if (!regCenter.isExisted(FailoverNode.ROOT)) { return Collections.emptyList(); } List<String> jobNames = regCenter.getChildrenKeys(FailoverNode.ROOT); Collection<JobContext> result = new ArrayList<>(jobNames.size()); Set<HashCode> assignedTasks = new HashSet<>(jobNames.size() * 10, 1); for (String each : jobNames) { List<String> taskIdList = regCenter.getChildrenKeys(FailoverNode.getFailoverJobNodePath(each)); if (taskIdList.isEmpty()) { regCenter.remove(FailoverNode.getFailoverJobNodePath(each)); continue; } Optional<CloudJobConfigurationPOJO> cloudJobConfig = configService.load(each); if (!cloudJobConfig.isPresent()) { regCenter.remove(FailoverNode.getFailoverJobNodePath(each)); continue; } List<Integer> assignedShardingItems = getAssignedShardingItems(each, taskIdList, assignedTasks); if (!assignedShardingItems.isEmpty()) { result.add(new JobContext(cloudJobConfig.get().toCloudJobConfiguration(), assignedShardingItems, ExecutionType.FAILOVER)); } } return result; } FailoverService(final CoordinatorRegistryCenter regCenter); void add(final TaskContext taskContext); Collection<JobContext> getAllEligibleJobContexts(); void remove(final Collection<MetaInfo> metaInfoList); Optional<String> getTaskId(final MetaInfo metaInfo); Map<String, Collection<FailoverTaskInfo>> getAllFailoverTasks();  }
@Test public void assertGetAllEligibleJobContextsWithoutRootNode() { when(regCenter.isExisted("/state/failover")).thenReturn(false); assertTrue(failoverService.getAllEligibleJobContexts().isEmpty()); verify(regCenter).isExisted("/state/failover"); }