FailoverService { public List<Integer> getLocalFailoverItems() { if (JobRegistry.getInstance().isShutdown(jobName)) { return Collections.emptyList(); } return getFailoverItems(JobRegistry.getInstance().getJobInstance(jobName).getJobInstanceId()); } 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 assertGetLocalFailoverItemsIfShutdown() { assertThat(failoverService.getLocalFailoverItems(), is(Collections.<Integer>emptyList())); verify(jobNodeStorage, times(0)).getJobNodeChildrenKeys("sharding"); }
@Test public void assertGetLocalFailoverItems() { 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.getLocalFailoverItems(), is(Collections.singletonList(0))); 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"); }