FailoverService { public List<Integer> getLocalTakeOffItems() { List<Integer> shardingItems = shardingService.getLocalShardingItems(); List<Integer> result = new ArrayList<>(shardingItems.size()); for (int each : shardingItems) { if (jobNodeStorage.isJobNodeExisted(FailoverNode.getExecutionFailoverNode(each))) { result.add(each); } } 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 assertGetLocalTakeOffItems() { when(shardingService.getLocalShardingItems()).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); assertThat(failoverService.getLocalTakeOffItems(), is(Arrays.asList(0, 1))); verify(shardingService).getLocalShardingItems(); verify(jobNodeStorage).isJobNodeExisted("sharding/0/failover"); verify(jobNodeStorage).isJobNodeExisted("sharding/1/failover"); verify(jobNodeStorage).isJobNodeExisted("sharding/2/failover"); }