@Test public void itShouldSendRequestUsingRoundRobinAlgorithm() { RpcClientConnectionPoolStub pool = new RpcClientConnectionPoolStub(); RpcSenderStub connection1 = new RpcSenderStub(); RpcSenderStub connection2 = new RpcSenderStub(); RpcSenderStub connection3 = new RpcSenderStub(); RpcStrategy server1 = server(ADDRESS_1); RpcStrategy server2 = server(ADDRESS_2); RpcStrategy server3 = server(ADDRESS_3); RpcStrategy roundRobin = roundRobin(server1, server2, server3); RpcSender senderRoundRobin; int timeout = 50; Object data = new RpcMessageDataStub(); int callsAmount = 5; pool.put(ADDRESS_1, connection1); pool.put(ADDRESS_2, connection2); pool.put(ADDRESS_3, connection3); senderRoundRobin = roundRobin.createSender(pool); for (int i = 0; i < callsAmount; i++) { senderRoundRobin.sendRequest(data, timeout, assertNoCalls()); } assertEquals(2, connection1.getRequests()); assertEquals(2, connection2.getRequests()); assertEquals(1, connection3.getRequests()); }
@Nullable @Override public RpcSender createSender(RpcClientConnectionPool pool) { List<RpcSender> subSenders = list.listOfSenders(pool); if (subSenders.size() < minActiveSubStrategies) return null; if (subSenders.size() == 0) return null; if (subSenders.size() == 1) return subSenders.get(0); return new Sender(subSenders); }
RpcStrategyRoundRobin implements RpcStrategy { @Nullable @Override public RpcSender createSender(RpcClientConnectionPool pool) { List<RpcSender> subSenders = list.listOfSenders(pool); if (subSenders.size() < minActiveSubStrategies) return null; if (subSenders.size() == 0) return null; if (subSenders.size() == 1) return subSenders.get(0); return new Sender(subSenders); } }
RpcStrategyRoundRobin implements RpcStrategy { @Nullable @Override public RpcSender createSender(RpcClientConnectionPool pool) { List<RpcSender> subSenders = list.listOfSenders(pool); if (subSenders.size() < minActiveSubStrategies) return null; if (subSenders.size() == 0) return null; if (subSenders.size() == 1) return subSenders.get(0); return new Sender(subSenders); } private  RpcStrategyRoundRobin(RpcStrategyList list, int minActiveSubStrategies); }
RpcStrategyRoundRobin implements RpcStrategy { @Nullable @Override public RpcSender createSender(RpcClientConnectionPool pool) { List<RpcSender> subSenders = list.listOfSenders(pool); if (subSenders.size() < minActiveSubStrategies) return null; if (subSenders.size() == 0) return null; if (subSenders.size() == 1) return subSenders.get(0); return new Sender(subSenders); } private  RpcStrategyRoundRobin(RpcStrategyList list, int minActiveSubStrategies); static RpcStrategyRoundRobin create(RpcStrategyList list); RpcStrategyRoundRobin withMinActiveSubStrategies(int minActiveSubStrategies); @Override Set<InetSocketAddress> getAddresses(); @Nullable @Override RpcSender createSender(RpcClientConnectionPool pool); }
RpcStrategyRoundRobin implements RpcStrategy { @Nullable @Override public RpcSender createSender(RpcClientConnectionPool pool) { List<RpcSender> subSenders = list.listOfSenders(pool); if (subSenders.size() < minActiveSubStrategies) return null; if (subSenders.size() == 0) return null; if (subSenders.size() == 1) return subSenders.get(0); return new Sender(subSenders); } private  RpcStrategyRoundRobin(RpcStrategyList list, int minActiveSubStrategies); static RpcStrategyRoundRobin create(RpcStrategyList list); RpcStrategyRoundRobin withMinActiveSubStrategies(int minActiveSubStrategies); @Override Set<InetSocketAddress> getAddresses(); @Nullable @Override RpcSender createSender(RpcClientConnectionPool pool);  }