ConsistentHash { public ConsistentHash(int numberOfReplicas, Collection<T> nodes) { this(new MD5HashFunction(), numberOfReplicas, nodes); } ConsistentHash(int numberOfReplicas, Collection<T> nodes);  ConsistentHash(HashFunction hashFunction, int numberOfReplicas,
      Collection<T> nodes); void addBin(T bin); void removeBin(T bin); T getBinFor(Object key); List<T> getNBinsFor(Object key, int n); List<T> getNUniqueBinsFor(Object key, int n); final static int MAX_DUPES; }
@Test public void testConsistentHash() { int replicas = 100; ConsistentHash<String> hash = new ConsistentHash<String>(replicas, machines); List<String> orig = new ArrayList<String>(20); StringBuilder sb = new StringBuilder(); sb.append("Before: "); for (int i = 0; i < 20; i++) { String s = "this is a the key " + i; String bin = hash.getBinFor(s); sb.append(bin + ", "); orig.add(bin); } LOG.info(sb.toString()); int diffs = 0; sb = new StringBuilder(); sb.append("after adding a machine: "); hash.addBin("machine F"); for (int i = 0; i < 20; i++) { String s = "this is a the key " + i; String bin = hash.getBinFor(s); sb.append(bin + ", "); if (!orig.get(i).equals(bin)) { diffs++; } } LOG.info(sb.toString()); LOG.info("Adding one caused " + diffs + " out of 20 to change"); LOG.info("after adding a machine: "); hash.removeBin("machine F"); sb = new StringBuilder(); for (int i = 0; i < 20; i++) { String s = "this is a the key " + i; String bin = hash.getBinFor(s); sb.append(bin + ", "); assertEquals(orig.get(i), bin); } LOG.info(sb.toString()); }