@Test public void basicTest() { final InstanceManager<Integer> instances = InstanceManager.create(); final LoadBalancer<Client> lb = LoadBalancer .fromSource(instances.map(Client.connector())) .withQuarantiner(Client.incarnationFactory(), Delays.fixed(1, TimeUnit.SECONDS), scheduler) .build(RoundRobinLoadBalancer.<Client>create()); instances.add(1); Client c = lb.next(); Assert.assertNotNull("Load balancer should have an active intance", c); Assert.assertEquals(1, c.getId()); c.onFailed(); try { c = lb.next(); Assert.fail("Load balancer should be empty"); } catch (NoSuchElementException e) { } scheduler.advanceTimeBy(2, TimeUnit.SECONDS); c = lb.next(); Assert.assertNotNull("Load balancer should have an active intance", c); Assert.assertEquals(2, c.getId()); c.onFailed(); try { c = lb.next(); Assert.fail("Load balancer should be empty"); } catch (NoSuchElementException e) { } scheduler.advanceTimeBy(2, TimeUnit.SECONDS); c = lb.next(); Assert.assertNotNull("Load balancer should have an active intance", c); Assert.assertEquals(3, c.counter.get()); instances.remove(1); try { c = lb.next(); Assert.fail(); } catch (NoSuchElementException e) { } System.out.println(c); }
public static <T> InstanceQuarantiner<T> create( IncarnationFactory<T> factory, DelayStrategy backoffStrategy, Scheduler scheduler) { return new InstanceQuarantiner<T>(factory, backoffStrategy, scheduler); }
InstanceQuarantiner implements Func1<Instance<T>, Observable<Instance<T>>> { public static <T> InstanceQuarantiner<T> create( IncarnationFactory<T> factory, DelayStrategy backoffStrategy, Scheduler scheduler) { return new InstanceQuarantiner<T>(factory, backoffStrategy, scheduler); } }
InstanceQuarantiner implements Func1<Instance<T>, Observable<Instance<T>>> { public static <T> InstanceQuarantiner<T> create( IncarnationFactory<T> factory, DelayStrategy backoffStrategy, Scheduler scheduler) { return new InstanceQuarantiner<T>(factory, backoffStrategy, scheduler); } InstanceQuarantiner(IncarnationFactory<T> factory, DelayStrategy backoffStrategy, Scheduler scheduler); }
InstanceQuarantiner implements Func1<Instance<T>, Observable<Instance<T>>> { public static <T> InstanceQuarantiner<T> create( IncarnationFactory<T> factory, DelayStrategy backoffStrategy, Scheduler scheduler) { return new InstanceQuarantiner<T>(factory, backoffStrategy, scheduler); } InstanceQuarantiner(IncarnationFactory<T> factory, DelayStrategy backoffStrategy, Scheduler scheduler); static InstanceQuarantiner<T> create(
            IncarnationFactory<T> factory,
            DelayStrategy         backoffStrategy, 
            Scheduler             scheduler); @Override Observable<Instance<T>> call(final Instance<T> primaryInstance); }
InstanceQuarantiner implements Func1<Instance<T>, Observable<Instance<T>>> { public static <T> InstanceQuarantiner<T> create( IncarnationFactory<T> factory, DelayStrategy backoffStrategy, Scheduler scheduler) { return new InstanceQuarantiner<T>(factory, backoffStrategy, scheduler); } InstanceQuarantiner(IncarnationFactory<T> factory, DelayStrategy backoffStrategy, Scheduler scheduler); static InstanceQuarantiner<T> create(
            IncarnationFactory<T> factory,
            DelayStrategy         backoffStrategy, 
            Scheduler             scheduler); @Override Observable<Instance<T>> call(final Instance<T> primaryInstance);  }