Called when the client wishes to know on which node the next invocation must be performed.
111112113114115116117118119120121
testCount++; List<String> targets = Arrays.asList(TARGETS); FamilyClusterInfo fci = ClusteringTargetsRepository.initTarget(FAMILY_BASE + testCount, targets); LoadBalancePolicy lbp = getLoadBalancePolicy(); String target = (String) lbp.chooseTarget(fci); assertTrue(targets.contains(target)); targets = Arrays.asList(new String[]{"W", "X", "Y", "Z"}); fci.updateClusterInfo(targets, 1);
117118119120121122123124125126
assertTrue(targets.contains(target)); targets = Arrays.asList(new String[]{"W", "X", "Y", "Z"}); fci.updateClusterInfo(targets, 1); target = (String) lbp.chooseTarget(fci); assertTrue(targets.contains(target)); } }
6768697071727374757677
Set<Object> selected = new HashSet<Object>(); for (int i = 0; i < 10000; i++) { LoadBalancePolicy lbp = getLoadBalancePolicy(); selected.add(lbp.chooseTarget(fci)); if (selected.size() == TARGETS.length) break; } assertEquals(TARGETS.length, selected.size());
5657585960616263646566
testCount++; List<String> targets = Arrays.asList(TARGETS); FamilyClusterInfo fci = ClusteringTargetsRepository.initTarget(FAMILY_BASE + testCount, targets); LoadBalancePolicy lbp = getLoadBalancePolicy(); Object target = lbp.chooseTarget(fci); assertTrue(targets.contains(target)); for (int i = 0; i < 10; i++) assertEquals(target, lbp.chooseTarget(fci));
6162636465666768697071
Object target = lbp.chooseTarget(fci); assertTrue(targets.contains(target)); for (int i = 0; i < 10; i++) assertEquals(target, lbp.chooseTarget(fci)); } public void testStickinessAfterFailover() {
7374757677787980818283
List<String> targets = Arrays.asList(TARGETS); FamilyClusterInfo fci = ClusteringTargetsRepository.initTarget(FAMILY_BASE + testCount, targets); LoadBalancePolicy lbp = getLoadBalancePolicy(); Object firstTarget; Object target = firstTarget = lbp.chooseTarget(fci); assertTrue(targets.contains(target)); for (int i = 0; i < 5; i++) assertEquals(target, lbp.chooseTarget(fci));
7879808182838485868788
Object target = firstTarget = lbp.chooseTarget(fci); assertTrue(targets.contains(target)); for (int i = 0; i < 5; i++) assertEquals(target, lbp.chooseTarget(fci)); fci.removeDeadTarget(target); Object secondTarget; target = secondTarget = lbp.chooseTarget(fci);
8283848586878889909192
for (int i = 0; i < 5; i++) assertEquals(target, lbp.chooseTarget(fci)); fci.removeDeadTarget(target); Object secondTarget; target = secondTarget = lbp.chooseTarget(fci); assertFalse(firstTarget.equals(secondTarget)); assertTrue(targets.contains(target)); for (int i = 0; i < 5; i++)
8889909192939495969798
assertFalse(firstTarget.equals(secondTarget)); assertTrue(targets.contains(target)); for (int i = 0; i < 5; i++) assertEquals(target, lbp.chooseTarget(fci)); fci.removeDeadTarget(target); Object thirdTarget; target = thirdTarget = lbp.chooseTarget(fci);
9293949596979899100101102
for (int i = 0; i < 5; i++) assertEquals(target, lbp.chooseTarget(fci)); fci.removeDeadTarget(target); Object thirdTarget; target = thirdTarget = lbp.chooseTarget(fci); assertFalse(firstTarget.equals(thirdTarget)); assertFalse(secondTarget.equals(thirdTarget)); assertTrue(targets.contains(target));