@SuppressWarnings("ConstantConditions") @Test public void itShouldSendRequestToFirstAvailableSubSender() { RpcClientConnectionPoolStub pool = new RpcClientConnectionPoolStub(); RpcSenderStub connection1 = new RpcSenderStub(); RpcSenderStub connection2 = new RpcSenderStub(); RpcSenderStub connection3 = new RpcSenderStub(); RpcStrategy firstAvailableStrategy = firstAvailable(servers(ADDRESS_1, ADDRESS_2, ADDRESS_3)); RpcSender sender; int callsToSender1 = 10; int callsToSender2 = 25; int callsToSender3 = 32; pool.put(ADDRESS_1, connection1); pool.put(ADDRESS_2, connection2); pool.put(ADDRESS_3, connection3); sender = firstAvailableStrategy.createSender(pool); for (int i = 0; i < callsToSender1; i++) { sender.sendRequest(new Object(), 50, assertNoCalls()); } pool.remove(ADDRESS_1); sender = firstAvailableStrategy.createSender(pool); for (int i = 0; i < callsToSender2; i++) { sender.sendRequest(new Object(), 50, assertNoCalls()); } pool.remove(ADDRESS_2); sender = firstAvailableStrategy.createSender(pool); for (int i = 0; i < callsToSender3; i++) { sender.sendRequest(new Object(), 50, assertNoCalls()); } assertEquals(callsToSender1, connection1.getRequests()); assertEquals(callsToSender2, connection2.getRequests()); assertEquals(callsToSender3, connection3.getRequests()); }
@Nullable @Override public RpcSender createSender(RpcClientConnectionPool pool) { List<RpcSender> senders = list.listOfSenders(pool); if (senders.isEmpty()) return null; return senders.get(0); }
RpcStrategyFirstAvailable implements RpcStrategy { @Nullable @Override public RpcSender createSender(RpcClientConnectionPool pool) { List<RpcSender> senders = list.listOfSenders(pool); if (senders.isEmpty()) return null; return senders.get(0); } }
RpcStrategyFirstAvailable implements RpcStrategy { @Nullable @Override public RpcSender createSender(RpcClientConnectionPool pool) { List<RpcSender> senders = list.listOfSenders(pool); if (senders.isEmpty()) return null; return senders.get(0); } private  RpcStrategyFirstAvailable(RpcStrategyList list); }
RpcStrategyFirstAvailable implements RpcStrategy { @Nullable @Override public RpcSender createSender(RpcClientConnectionPool pool) { List<RpcSender> senders = list.listOfSenders(pool); if (senders.isEmpty()) return null; return senders.get(0); } private  RpcStrategyFirstAvailable(RpcStrategyList list); static RpcStrategyFirstAvailable create(RpcStrategyList list); @Override Set<InetSocketAddress> getAddresses(); @Nullable @Override RpcSender createSender(RpcClientConnectionPool pool); }
RpcStrategyFirstAvailable implements RpcStrategy { @Nullable @Override public RpcSender createSender(RpcClientConnectionPool pool) { List<RpcSender> senders = list.listOfSenders(pool); if (senders.isEmpty()) return null; return senders.get(0); } private  RpcStrategyFirstAvailable(RpcStrategyList list); static RpcStrategyFirstAvailable create(RpcStrategyList list); @Override Set<InetSocketAddress> getAddresses(); @Nullable @Override RpcSender createSender(RpcClientConnectionPool pool);  }