@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());
  // ideally there should only be about 4 that have changed.
  LOG.info("Adding one caused " + diffs + " out of 20 to change");
  // we should have the original setup back again.
  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());
}