Clean up some generics in ConsistentHash and add tests for non-defaults.

This commit is contained in:
David Hoover committed 2015-04-19 14:48:04 -07:00
1 parent aea48a9d7b
commit 57255ccb10
2 files changed
+37 -3

No files matched your search

@@ -140,6 +140,40 @@ public class ConsistentHashTest {
assertEquals(5, hash.countAllPoints());
}
@Test
public void defaultReplicationIsOneHundred() {
ConsistentHash<String> hash = new ConsistentHash<String>();
assertEquals(0, hash.countAllPoints());
hash.add("foo");
assertEquals(100, hash.countAllPoints());
}
@Test
public void setCustomDefaultReplication() {
ConsistentHash<String> hash = new ConsistentHash<String>((ConsistentHash.Hash<String>) ConsistentHash.DEFAULT_HASH, 7);
assertEquals(0, hash.countAllPoints());
hash.add("foo");
assertEquals(7, hash.countAllPoints());
}
@Test
public void usesCustomHash() {
final RuntimeException exception = new RuntimeException();
ConsistentHash.Hash<String> hashFunction = new ConsistentHash.Hash<String>() {
public String hash(String str) {
throw exception;
}
};
try {
ConsistentHash<String> hash = new ConsistentHash<String>(hashFunction);
hash.add("foo");
fail("Didn't use custom hash function");
} catch (RuntimeException e) {
assertSame(exception, e);
}
}
/**
* This test doesn't fail but it's written to measure the performance of the consistent hash function with large data set.
*/