FailoverService { public List<Integer> getLocalHostTakeOffItems() { List<Integer> shardingItems = shardingService.getLocalHostShardingItems(); 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 coordinatorRegistryCenter, final JobConfiguration jobConfiguration); void setCrashedFailoverFlag(final int item); void failoverIfNecessary(); void updateFailoverComplete(final List<Integer> items); List<Integer> getLocalHostFailoverItems(); List<Integer> getLocalHostTakeOffItems(); void removeFailoverInfo();  }
@Test public void assertGetLocalHostTakeOffItems() { when(shardingService.getLocalHostShardingItems()).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); assertThat(failoverService.getLocalHostTakeOffItems(), is(Arrays.asList(0, 1))); verify(shardingService).getLocalHostShardingItems(); verify(jobNodeStorage).isJobNodeExisted("execution/0/failover"); verify(jobNodeStorage).isJobNodeExisted("execution/1/failover"); verify(jobNodeStorage).isJobNodeExisted("execution/2/failover"); }