OdevitySortByNameJobShardingStrategy implements JobShardingStrategy { @Override public Map<String, List<Integer>> sharding(final List<String> serversList, final JobShardingStrategyOption option) { long jobNameHash = option.getJobName().hashCode(); if (0 == jobNameHash % 2) { Collections.reverse(serversList); } return averageAllocationJobShardingStrategy.sharding(serversList, option); }  @Override Map<String, List<Integer>> sharding(final List<String> serversList, final JobShardingStrategyOption option);  }
@Test public void assertShardingByAsc() { Map<String, List<Integer>> expected = new LinkedHashMap<>(3); expected.put("host0", Collections.singletonList(0)); expected.put("host1", Collections.singletonList(1)); expected.put("host2", Collections.<Integer>emptyList()); assertThat( odevitySortByNameJobShardingStrategy.sharding(Arrays.asList("host0", "host1", "host2"), new JobShardingStrategyOption("1", 2, Collections.<Integer, String>emptyMap())), is(expected)); }
@Test public void assertShardingByDesc() { Map<String, List<Integer>> expected = new LinkedHashMap<>(3); expected.put("host2", Collections.singletonList(0)); expected.put("host1", Collections.singletonList(1)); expected.put("host0", Collections.<Integer>emptyList()); assertThat( odevitySortByNameJobShardingStrategy.sharding(Arrays.asList("host0", "host1", "host2"), new JobShardingStrategyOption("0", 2, Collections.<Integer, String>emptyMap())), is(expected)); }
@Test public void assertShardingByAsc() { Map<String, List<Integer>> expected = new LinkedHashMap<String, List<Integer>>(3); expected.put("host0", Collections.singletonList(0)); expected.put("host1", Collections.singletonList(1)); expected.put("host2", Collections.<Integer>emptyList()); assertThat( odevitySortByNameJobShardingStrategy.sharding(Arrays.asList("host0", "host1", "host2"), new JobShardingStrategyOption("1", 2, Collections.<Integer, String>emptyMap())), is(expected)); }
@Test public void assertShardingByDesc() { Map<String, List<Integer>> expected = new LinkedHashMap<String, List<Integer>>(3); expected.put("host2", Collections.singletonList(0)); expected.put("host1", Collections.singletonList(1)); expected.put("host0", Collections.<Integer>emptyList()); assertThat( odevitySortByNameJobShardingStrategy.sharding(Arrays.asList("host0", "host1", "host2"), new JobShardingStrategyOption("0", 2, Collections.<Integer, String>emptyMap())), is(expected)); }