KeyAllocationStrategy { public byte[] getKey(int messageNum) { return keys.get(messageNum % uniqueKeys); } KeyAllocationStrategy(KeyAllocationStrategyDefinition strategyDefinition); @Override String toString(); byte[] getKey(int messageNum);  }
@Test public void testFairAllocation() { KeyAllocationStrategy s0 = getStrategy(KeyAllocationType.fair, 2); assertThat(s0.getKey(0), equalTo(s0.getKey(0))); assertThat(s0.getKey(0), equalTo(s0.getKey(2))); assertThat(s0.getKey(0), not(equalTo(s0.getKey(1)))); KeyAllocationStrategy s1 = getStrategy(KeyAllocationType.fair, 2); assertThat(s0.getKey(0), equalTo(s1.getKey(0))); assertThat(s0.getKey(1), equalTo(s1.getKey(1))); }
@Test public void testRandomAllocation() { KeyAllocationStrategy s0 = getStrategy(KeyAllocationType.random, 2); assertThat(s0.getKey(0), equalTo(s0.getKey(0))); assertThat(s0.getKey(0), equalTo(s0.getKey(2))); assertThat(s0.getKey(0), not(equalTo(s0.getKey(1)))); KeyAllocationStrategy s1 = getStrategy(KeyAllocationType.random, 2); assertThat(s0.getKey(0), not(equalTo(s1.getKey(0)))); assertThat(s0.getKey(1), not(equalTo(s1.getKey(1)))); }