@Test public void testPickFirstBalancerFactory() throws Exception { try (Client client = Client.builder() .endpoints(TestConstants.endpoints) .loadBalancerFactory(PickFirstBalancerFactory.getInstance()) .build(); KV kv = client.getKVClient()) { PutResponse response; long lastMemberId = 0; for (int i = 0; i < TestConstants.endpoints.length * 2; i++) { response = kv.put(TestUtil.randomByteSequence(), TestUtil.randomByteSequence()).get(); if (i == 0) { lastMemberId = response.getHeader().getMemberId(); } assertThat(response.getHeader().getMemberId()).isEqualTo(lastMemberId); } } }
@Override public LoadBalancer newLoadBalancer(LoadBalancer.Helper helper) { return new GrpclbLoadBalancer( helper, PickFirstBalancerFactory.getInstance(), RoundRobinLoadBalancerFactory.getInstance(), // TODO(zhangkun83): balancer sends load reporting RPCs from it, which also involves // channelExecutor thus may also run other tasks queued in the channelExecutor. If such // load should not be on the shared scheduled executor, we should use a combination of the // scheduled executor and the default app executor. SharedResourcePool.forResource(GrpcUtil.TIMER_SERVICE), TIME_PROVIDER); }