FailoverService { public List<Integer> getLocalHostFailoverItems() { List<String> items = jobNodeStorage.getJobNodeChildrenKeys(ExecutionNode.ROOT); List<Integer> result = new ArrayList<Integer>(items.size()); String ip = localHostService.getIp(); for (String each : items) { int item = Integer.parseInt(each); String node = FailoverNode.getExecutionFailoverNode(item); if (jobNodeStorage.isJobNodeExisted(node) && ip.equals(jobNodeStorage.getJobNodeDataDirectly(node))) { result.add(item); } } Collections.sort(result); 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 assertGetLocalHostFailoverItems() { when(jobNodeStorage.getJobNodeChildrenKeys("execution")).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); when(jobNodeStorage.getJobNodeDataDirectly("execution/0/failover")).thenReturn("mockedIP"); when(jobNodeStorage.getJobNodeDataDirectly("execution/1/failover")).thenReturn("otherIP"); assertThat(failoverService.getLocalHostFailoverItems(), is(Collections.singletonList(0))); verify(jobNodeStorage).getJobNodeChildrenKeys("execution"); verify(localHostService).getIp(); verify(jobNodeStorage).isJobNodeExisted("execution/0/failover"); verify(jobNodeStorage).isJobNodeExisted("execution/1/failover"); verify(jobNodeStorage).getJobNodeDataDirectly("execution/0/failover"); verify(jobNodeStorage).getJobNodeDataDirectly("execution/1/failover"); }