Permalink
Browse files

updated tests due to changed behavior of MPConsistentHashRing iterator

RB=1253858
G=si-core-reviewers
R=cxu
A=cxu
  • Loading branch information...
alexjinghn committed Mar 16, 2018
1 parent 2b223bc commit db5c65d54ca3511b86f041763e36a8a0ed427a9b
View
@@ -3,6 +3,9 @@
(RB=1253124)
modified MPConsistentHashRing iterator
(RB=1253858)
updated tests due to changing behavior of MPConsistentHashRing iterator
20.0.8
------
(RB=1244383)
@@ -21,10 +21,12 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.Iterator;
import java.util.LinkedList;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.NoSuchElementException;
import java.util.Random;
import java.util.Set;
import net.openhft.hashing.LongHashFunction;
import org.slf4j.Logger;
@@ -240,12 +242,15 @@ public String toString()
private final List<T> _rankedList;
private final Iterator<T> _rankedListIter;
public QuasiMPConsistentHashRingIterator(int startKey, List<T> hosts) {
_rankedList = new ArrayList<T>();
_rankedList = new LinkedList<>();
_rankedList.addAll(hosts);
Collections.shuffle(_rankedList);// DOES not guarantee the ranking order of hosts after the first one.
_rankedList.add(0, get(startKey));
Collections.shuffle(_rankedList,
new Random(startKey));// DOES not guarantee the ranking order of hosts after the first one.
T mostWantedHost = get(startKey);
_rankedList.remove(mostWantedHost);
_rankedList.add(0, mostWantedHost);
_rankedListIter = _rankedList.listIterator();
}
@@ -62,8 +62,8 @@ public void testOtherItems() {
iterations++;
}
//test iteration should equal to 1 + number of hosts so no duplicates
Assert.assertTrue(iterations == 101);
//test iteration should equal to number of hosts so no duplicates
Assert.assertTrue(iterations == 100);
for (URI uri : pointsMap.keySet()) {
Assert.assertTrue(iterResults.contains(uri));
@@ -127,7 +127,7 @@ public void testHashRingIterator()
pointsMap.put(URI.create("www.microsoft.com"), 15);
MPConsistentHashRing<URI> hashRing = new MPConsistentHashRing<>(pointsMap);
int key = new Random().nextInt();
Iterator<URI> iter = hashRing.getIterator(key);
Iterator<URI> iter = hashRing.getOrderedIterator(key);
while (iter.hasNext()) {
URI nextUri = iter.next();
@@ -136,7 +136,7 @@ public void testHashRingIterator()
pointsMap.remove(nextUri);
hashRing = new MPConsistentHashRing<>(pointsMap);
}
Assert.assertTrue(pointsMap.isEmpty());
}

0 comments on commit db5c65d

Please sign in to comment.