ShardingService { public List<Integer> getLocalHostShardingItems() { String ip = localHostService.getIp(); if (!jobNodeStorage.isJobNodeExisted(ShardingNode.getShardingNode(ip))) { return Collections.emptyList(); } return ItemUtils.toItemList(jobNodeStorage.getJobNodeDataDirectly(ShardingNode.getShardingNode(ip))); } ShardingService(final CoordinatorRegistryCenter coordinatorRegistryCenter, final JobConfiguration jobConfiguration); void setReshardingFlag(); boolean isNeedSharding(); void shardingIfNecessary(); List<Integer> getLocalHostShardingItems();  }
@Test public void assertGetLocalHostShardingItemsWhenNodeExisted() { when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/sharding")).thenReturn(true); when(jobNodeStorage.getJobNodeDataDirectly("servers/mockedIP/sharding")).thenReturn("0,1,2"); assertThat(shardingService.getLocalHostShardingItems(), is(Arrays.asList(0, 1, 2))); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/sharding"); verify(jobNodeStorage).getJobNodeDataDirectly("servers/mockedIP/sharding"); }
@Test public void assertGetLocalHostShardingWhenNodeNotExisted() { when(jobNodeStorage.isJobNodeExisted("servers/mockedIP/sharding")).thenReturn(false); assertThat(shardingService.getLocalHostShardingItems(), is(Collections.EMPTY_LIST)); verify(jobNodeStorage).isJobNodeExisted("servers/mockedIP/sharding"); }