@Test public void rendezvousHashingTest() { RpcClientConnectionPoolStub pool = new RpcClientConnectionPoolStub(); RpcSenderStub connection1 = new RpcSenderStub(); RpcSenderStub connection2 = new RpcSenderStub(); RpcSenderStub connection3 = new RpcSenderStub(); RpcSenderStub connection4 = new RpcSenderStub(); RpcSenderStub connection5 = new RpcSenderStub(); HashFunction<Integer> hashFunction = item -> item; RpcStrategy strategy = rendezvousHashing(hashFunction) .withShard(1, firstAvailable(servers(ADDRESS_1, ADDRESS_2))) .withShard(2, firstAvailable(servers(ADDRESS_3, ADDRESS_4))) .withShard(3, server(ADDRESS_5)); int iterationsPerLoop = 1000; RpcSender sender; pool.put(ADDRESS_1, connection1); pool.put(ADDRESS_2, connection2); pool.put(ADDRESS_3, connection3); pool.put(ADDRESS_4, connection4); pool.put(ADDRESS_5, connection5); sender = strategy.createSender(pool); for (int i = 0; i < iterationsPerLoop; i++) { sender.sendRequest(i, 50, ignore()); } pool.remove(ADDRESS_3); pool.remove(ADDRESS_4); sender = strategy.createSender(pool); for (int i = 0; i < iterationsPerLoop; i++) { sender.sendRequest(i, 50, ignore()); } double acceptableError = iterationsPerLoop / 10.0; assertEquals(iterationsPerLoop / 3 + iterationsPerLoop / 2, connection1.getRequests(), acceptableError); assertEquals(0, connection2.getRequests()); assertEquals(iterationsPerLoop / 3, connection3.getRequests(), acceptableError); assertEquals(0, connection4.getRequests()); assertEquals(iterationsPerLoop / 3 + iterationsPerLoop / 2, connection5.getRequests(), acceptableError); }
public static RpcStrategyRendezvousHashing rendezvousHashing(@NotNull HashFunction<?> hashFunction) { return RpcStrategyRendezvousHashing.create(hashFunction); }
RpcStrategies { public static RpcStrategyRendezvousHashing rendezvousHashing(@NotNull HashFunction<?> hashFunction) { return RpcStrategyRendezvousHashing.create(hashFunction); } }
RpcStrategies { public static RpcStrategyRendezvousHashing rendezvousHashing(@NotNull HashFunction<?> hashFunction) { return RpcStrategyRendezvousHashing.create(hashFunction); }  }
RpcStrategies { public static RpcStrategyRendezvousHashing rendezvousHashing(@NotNull HashFunction<?> hashFunction) { return RpcStrategyRendezvousHashing.create(hashFunction); }  static RpcStrategySingleServer server(@NotNull InetSocketAddress address); static RpcStrategyList servers(InetSocketAddress... addresses); static RpcStrategyList servers(List<InetSocketAddress> addresses); static RpcStrategyFirstAvailable firstAvailable(RpcStrategy... senders); static RpcStrategyFirstAvailable firstAvailable(List<RpcStrategy> strategies); static RpcStrategyFirstAvailable firstAvailable(RpcStrategyList list); static RpcStrategyFirstValidResult firstValidResult(RpcStrategy... senders); static RpcStrategyFirstValidResult firstValidResult(List<RpcStrategy> senders); static RpcStrategyFirstValidResult firstValidResult(RpcStrategyList list); static RpcStrategyRoundRobin roundRobin(RpcStrategy... senders); static RpcStrategyRoundRobin roundRobin(List<RpcStrategy> senders); static RpcStrategyRoundRobin roundRobin(RpcStrategyList list); static RpcStrategySharding sharding(ShardingFunction<?> hashFunction,
			RpcStrategy... senders); static RpcStrategySharding sharding(@NotNull ShardingFunction<?> hashFunction,
			@NotNull List<RpcStrategy> senders); static RpcStrategySharding sharding(@NotNull ShardingFunction<?> hashFunction,
			@NotNull RpcStrategyList list); static RpcStrategyRendezvousHashing rendezvousHashing(@NotNull HashFunction<?> hashFunction); static RpcStrategyTypeDispatching typeDispatching(); static RpcStrategyRandomSampling randomSampling(); }
RpcStrategies { public static RpcStrategyRendezvousHashing rendezvousHashing(@NotNull HashFunction<?> hashFunction) { return RpcStrategyRendezvousHashing.create(hashFunction); }  static RpcStrategySingleServer server(@NotNull InetSocketAddress address); static RpcStrategyList servers(InetSocketAddress... addresses); static RpcStrategyList servers(List<InetSocketAddress> addresses); static RpcStrategyFirstAvailable firstAvailable(RpcStrategy... senders); static RpcStrategyFirstAvailable firstAvailable(List<RpcStrategy> strategies); static RpcStrategyFirstAvailable firstAvailable(RpcStrategyList list); static RpcStrategyFirstValidResult firstValidResult(RpcStrategy... senders); static RpcStrategyFirstValidResult firstValidResult(List<RpcStrategy> senders); static RpcStrategyFirstValidResult firstValidResult(RpcStrategyList list); static RpcStrategyRoundRobin roundRobin(RpcStrategy... senders); static RpcStrategyRoundRobin roundRobin(List<RpcStrategy> senders); static RpcStrategyRoundRobin roundRobin(RpcStrategyList list); static RpcStrategySharding sharding(ShardingFunction<?> hashFunction,
			RpcStrategy... senders); static RpcStrategySharding sharding(@NotNull ShardingFunction<?> hashFunction,
			@NotNull List<RpcStrategy> senders); static RpcStrategySharding sharding(@NotNull ShardingFunction<?> hashFunction,
			@NotNull RpcStrategyList list); static RpcStrategyRendezvousHashing rendezvousHashing(@NotNull HashFunction<?> hashFunction); static RpcStrategyTypeDispatching typeDispatching(); static RpcStrategyRandomSampling randomSampling();  }