Skip to content

Commit

Permalink
ISPN-2074 - The consistent hash in the java Hotrod client is buggy
Browse files Browse the repository at this point in the history
  • Loading branch information
mmarkus authored and galderz committed May 29, 2012
1 parent 5437f34 commit 8ade99c
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 2 deletions.
Expand Up @@ -102,7 +102,7 @@ public SocketAddress getServer(byte[] key) {

private int getHashIndex(int normalisedHashForKey) {
int result = Arrays.binarySearch(hashes, normalisedHashForKey);
if (result > 0) {//the normalisedHashForKey has an exact match in the hashes array
if (result >= 0) {//the normalisedHashForKey has an exact match in the hashes array
return result;
} else {
//see javadoc for Arrays.binarySearch, @return tag in particular
Expand Down
Expand Up @@ -72,6 +72,8 @@ private void setUp(int numOwners) {

public void simpleTest() {
setUp(1);
hash.value = 0;
assert v1.getServer(new byte[0]).equals(a1);
hash.value = 1;
assert v1.getServer(new byte[0]).equals(a2);
hash.value = 1001;
Expand All @@ -84,6 +86,9 @@ public void simpleTest() {

public void numOwners2Test() {
setUp(2);
hash.value = 0;
assert list(a1, a2).contains(v1.getServer(new byte[0]));

hash.value = 1;
assert list(a2, a3).contains(v1.getServer(new byte[0]));

Expand All @@ -99,6 +104,9 @@ public void numOwners2Test() {

public void numOwners3Test() {
setUp(3);
hash.value = 0;
assert list(a1, a2, a3).contains(v1.getServer(new byte[0]));

hash.value = 1;
assert list(a2, a3, a4).contains(v1.getServer(new byte[0]));

Expand All @@ -115,8 +123,13 @@ public void numOwners3Test() {
//now a bit more extreme...
public void numOwners4Test() {
setUp(4);
hash.value = 1;

List<InetSocketAddress> list = list(a1, a2, a3, a4);

hash.value = 0;
assert list.contains(v1.getServer(new byte[0]));

hash.value = 1;
assert list.contains(v1.getServer(new byte[0]));

hash.value = 1001;
Expand Down

0 comments on commit 8ade99c

Please sign in to comment.