@Test public void testMany() { BehaviorSubject<List<Integer>> source = BehaviorSubject.create(); LoadBalancer<Integer> lb = LoadBalancer.fromSnapshotSource(source).build(ChoiceOfTwoLoadBalancer.create(COMPARATOR)); source.onNext(Lists.newArrayList(0,1,2,3,4,5,6,7,8,9)); AtomicIntegerArray counts = new AtomicIntegerArray(10); for (int i = 0; i < 100000; i++) { counts.incrementAndGet(lb.next()); } Double[] pct = new Double[counts.length()]; for (int i = 0; i < counts.length(); i++) { pct[i] = counts.get(i)/100000.0; } for (int i = 1; i < counts.length(); i++) { Assert.assertTrue(counts.get(i) > counts.get(i-1)); } }
public static <T> ChoiceOfTwoLoadBalancer<T> create(final Comparator<T> func) { return new ChoiceOfTwoLoadBalancer<T>(func); }
ChoiceOfTwoLoadBalancer implements LoadBalancerStrategy<T> { public static <T> ChoiceOfTwoLoadBalancer<T> create(final Comparator<T> func) { return new ChoiceOfTwoLoadBalancer<T>(func); } }
ChoiceOfTwoLoadBalancer implements LoadBalancerStrategy<T> { public static <T> ChoiceOfTwoLoadBalancer<T> create(final Comparator<T> func) { return new ChoiceOfTwoLoadBalancer<T>(func); } ChoiceOfTwoLoadBalancer(final Comparator<T> func2); }
ChoiceOfTwoLoadBalancer implements LoadBalancerStrategy<T> { public static <T> ChoiceOfTwoLoadBalancer<T> create(final Comparator<T> func) { return new ChoiceOfTwoLoadBalancer<T>(func); } ChoiceOfTwoLoadBalancer(final Comparator<T> func2); static ChoiceOfTwoLoadBalancer<T> create(final Comparator<T> func); @Override T choose(List<T> candidates); }
ChoiceOfTwoLoadBalancer implements LoadBalancerStrategy<T> { public static <T> ChoiceOfTwoLoadBalancer<T> create(final Comparator<T> func) { return new ChoiceOfTwoLoadBalancer<T>(func); } ChoiceOfTwoLoadBalancer(final Comparator<T> func2); static ChoiceOfTwoLoadBalancer<T> create(final Comparator<T> func); @Override T choose(List<T> candidates);  }