GrpclbLoadBalancer extends LoadBalancer<T> { private void updateRetainedTransports() { HashSet<EquivalentAddressGroup> addresses = new HashSet<EquivalentAddressGroup>(); synchronized (lock) { if (lbAddresses != null) { addresses.add(lbAddresses); } if (servers != null) { for (SocketAddress addr : servers.keySet()) { addresses.add(new EquivalentAddressGroup(addr)); } } } tm.updateRetainedTransports(addresses); } GrpclbLoadBalancer(String serviceName, TransportManager<T> tm); @Override T pickTransport(Attributes affinity); @Override void handleResolvedAddresses(
      List<ResolvedServerInfo> updatedServers, Attributes config); @Override void handleNameResolutionError(Status error); @Override void shutdown(); @Override void handleTransportShutdown(EquivalentAddressGroup addressGroup, Status status);  }
@Test public void newLbAddressesResolved() throws Exception { Transport lbTransport = simulateLbAddressResolved(30001); EquivalentAddressGroup lbAddress1 = lbAddressGroup; verify(mockTransportManager).updateRetainedTransports(eq(Collections.singleton(lbAddress1))); verify(mockTransportManager).getTransport(eq(lbAddressGroup)); SendLbRequestArgs sentLbRequest = loadBalancer.sentLbRequests.poll(1000, TimeUnit.SECONDS); assertNotNull(sentLbRequest); assertSame(lbTransport, sentLbRequest.transport); lbTransport = simulateLbAddressResolved(30002); EquivalentAddressGroup lbAddress2 = lbAddressGroup; assertNotEquals(lbAddress1, lbAddress2); verify(mockTransportManager).updateRetainedTransports(eq(Collections.singleton(lbAddress2))); verify(mockTransportManager).getTransport(eq(lbAddressGroup)); sentLbRequest = loadBalancer.sentLbRequests.poll(1000, TimeUnit.SECONDS); assertNotNull(sentLbRequest); assertSame(lbTransport, sentLbRequest.transport); simulateLbAddressResolved(30002); EquivalentAddressGroup lbAddress3 = lbAddressGroup; assertEquals(lbAddress2, lbAddress3); verify(mockTransportManager).getTransport(eq(lbAddressGroup)); verify(mockTransportManager, times(2)).getTransport(any(EquivalentAddressGroup.class)); }