Called when the client wishes to know on which node the next invocation must be performed.
8586878889909192939495
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());
101102103104105106107108109110111
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));
106107108109110111112113114115116
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);
110111112113114115116117118119120
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++)
116117118119120121122123124125126
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);
120121122123124125126127128129130
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));
127128129130131132133134135136137
assertFalse(firstTarget.equals(thirdTarget)); assertFalse(secondTarget.equals(thirdTarget)); assertTrue(targets.contains(target)); for (int i = 0; i < 5; i++) assertEquals(target, lbp.chooseTarget(fci)); fci.removeDeadTarget(target); assertNull(lbp.chooseTarget(fci)); }
131132133134135136137138139140141
for (int i = 0; i < 5; i++) assertEquals(target, lbp.chooseTarget(fci)); fci.removeDeadTarget(target); assertNull(lbp.chooseTarget(fci)); } public void testNoAvailableTargets() { testCount++;
9899100101102103104105106107108
{ target = (InvokerLocator) ((AopLoadBalancePolicy) lb).chooseTarget(family.get(), invocation); } else { target = (InvokerLocator) lb.chooseTarget(family.get()); } } Throwable lastException = null; boolean failoverAuthorized = true;
215216217218219220221222223224225
if (!definitivlyRemoveNodeOnFailure) { family.get().resetView(); } target = (InvokerLocator) lb.chooseTarget(family.get()); if (target == null) { if (lastException != null) { throw new RuntimeException("cluster invocation failed, last exception was: ", lastException);