@Test(timeout = 60000) public void testRoundRobin() throws Exception { List<Instance<SocketAddress>> hosts = lbRule.setupDefault(); AbstractLoadBalancer<String, String> loadBalancer = lbRule.getLoadBalancer(); ConnectionFactory<String, String> cfMock = lbRule.newConnectionFactoryMock(); ConnectionProvider<String, String> cp = loadBalancer.toConnectionProvider(cfMock); ConnectionObservable<String, String> co = cp.nextConnection(); lbRule.connect(co); Mockito.verify(cfMock).newConnection(hosts.get(0).getValue()); Mockito.verifyNoMoreInteractions(cfMock); cp = loadBalancer.toConnectionProvider(cfMock); co = cp.nextConnection(); lbRule.connect(co); Mockito.verify(cfMock).newConnection(hosts.get(1).getValue()); Mockito.verifyNoMoreInteractions(cfMock); }
public ConnectionProvider<W, R> toConnectionProvider() { return ConnectionProvider.create(new Func1<ConnectionFactory<W, R>, ConnectionProvider<W, R>>() { @Override public ConnectionProvider<W, R> call(final ConnectionFactory<W, R> connectionFactory) { return toConnectionProvider(connectionFactory); } }); }
AbstractLoadBalancer { public ConnectionProvider<W, R> toConnectionProvider() { return ConnectionProvider.create(new Func1<ConnectionFactory<W, R>, ConnectionProvider<W, R>>() { @Override public ConnectionProvider<W, R> call(final ConnectionFactory<W, R> connectionFactory) { return toConnectionProvider(connectionFactory); } }); } }
AbstractLoadBalancer { public ConnectionProvider<W, R> toConnectionProvider() { return ConnectionProvider.create(new Func1<ConnectionFactory<W, R>, ConnectionProvider<W, R>>() { @Override public ConnectionProvider<W, R> call(final ConnectionFactory<W, R> connectionFactory) { return toConnectionProvider(connectionFactory); } }); } protected  AbstractLoadBalancer(Observable<Instance<SocketAddress>> hosts,
                                   Func1<FailureListener, ? extends TcpClientEventListener> eventListenerFactory,
                                   LoadBalancerStrategy<HostConnectionProvider<W, R>> loadBalancer); }
AbstractLoadBalancer { public ConnectionProvider<W, R> toConnectionProvider() { return ConnectionProvider.create(new Func1<ConnectionFactory<W, R>, ConnectionProvider<W, R>>() { @Override public ConnectionProvider<W, R> call(final ConnectionFactory<W, R> connectionFactory) { return toConnectionProvider(connectionFactory); } }); } protected  AbstractLoadBalancer(Observable<Instance<SocketAddress>> hosts,
                                   Func1<FailureListener, ? extends TcpClientEventListener> eventListenerFactory,
                                   LoadBalancerStrategy<HostConnectionProvider<W, R>> loadBalancer); ConnectionProvider<W, R> toConnectionProvider(); }
AbstractLoadBalancer { public ConnectionProvider<W, R> toConnectionProvider() { return ConnectionProvider.create(new Func1<ConnectionFactory<W, R>, ConnectionProvider<W, R>>() { @Override public ConnectionProvider<W, R> call(final ConnectionFactory<W, R> connectionFactory) { return toConnectionProvider(connectionFactory); } }); } protected  AbstractLoadBalancer(Observable<Instance<SocketAddress>> hosts,
                                   Func1<FailureListener, ? extends TcpClientEventListener> eventListenerFactory,
                                   LoadBalancerStrategy<HostConnectionProvider<W, R>> loadBalancer); ConnectionProvider<W, R> toConnectionProvider();  }