FailoverService { public List<Integer> getFailoverItems(final String jobInstanceId) { List<String> items = jobNodeStorage.getJobNodeChildrenKeys(ShardingNode.ROOT); List<Integer> result = new ArrayList<>(items.size()); for (String each : items) { int item = Integer.parseInt(each); String node = FailoverNode.getExecutionFailoverNode(item); if (jobNodeStorage.isJobNodeExisted(node) && jobInstanceId.equals(jobNodeStorage.getJobNodeDataDirectly(node))) { result.add(item); } } Collections.sort(result); return result; } FailoverService(final CoordinatorRegistryCenter regCenter, final String jobName); void setCrashedFailoverFlag(final int item); void failoverIfNecessary(); void updateFailoverComplete(final Collection<Integer> items); List<Integer> getFailoverItems(final String jobInstanceId); List<Integer> getLocalFailoverItems(); List<Integer> getLocalTakeOffItems(); void removeFailoverInfo();  }
@Test public void assertGetFailoverItems() { JobRegistry.getInstance().registerRegistryCenter("test_job", regCenter); JobRegistry.getInstance().registerJob("test_job", jobScheduleController); when(jobNodeStorage.getJobNodeChildrenKeys("sharding")).thenReturn(Arrays.asList("0", "1", "2")); when(jobNodeStorage.isJobNodeExisted("sharding/0/failover")).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("sharding/1/failover")).thenReturn(true); when(jobNodeStorage.isJobNodeExisted("sharding/2/failover")).thenReturn(false); when(jobNodeStorage.getJobNodeDataDirectly("sharding/0/failover")).thenReturn("127.0.0.1@-@0"); when(jobNodeStorage.getJobNodeDataDirectly("sharding/1/failover")).thenReturn("127.0.0.1@-@1"); assertThat(failoverService.getFailoverItems("127.0.0.1@-@1"), is(Collections.singletonList(1))); verify(jobNodeStorage).getJobNodeChildrenKeys("sharding"); verify(jobNodeStorage).isJobNodeExisted("sharding/0/failover"); verify(jobNodeStorage).isJobNodeExisted("sharding/1/failover"); verify(jobNodeStorage).getJobNodeDataDirectly("sharding/0/failover"); verify(jobNodeStorage).getJobNodeDataDirectly("sharding/1/failover"); JobRegistry.getInstance().shutdown("test_job"); }