mirror of
https://github.com/jenkinsci/jenkins.git
synced 2026-11-16 13:32:24 +00:00
Clean up some generics in ConsistentHash and add tests for non-defaults.
This commit is contained in:
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.
|
||||
*/
|
||||
|
||||
Reference in new issue
Block a user