@Test public void firstResolvedServerFailedToConnect() throws Exception { final SocketAddress goodAddress = new SocketAddress() { @Override public String toString() { return "goodAddress"; } }; final SocketAddress badAddress = new SocketAddress() { @Override public String toString() { return "badAddress"; } }; final ResolvedServerInfo goodServer = new ResolvedServerInfo(goodAddress, Attributes.EMPTY); final ResolvedServerInfo badServer = new ResolvedServerInfo(badAddress, Attributes.EMPTY); final ManagedClientTransport goodTransport = mock(ManagedClientTransport.class); final ManagedClientTransport badTransport = mock(ManagedClientTransport.class); when(goodTransport.newStream(any(MethodDescriptor.class), any(Metadata.class))) .thenReturn(mock(ClientStream.class)); when(mockTransportFactory.newClientTransport(same(goodAddress), any(String.class))) .thenReturn(goodTransport); when(mockTransportFactory.newClientTransport(same(badAddress), any(String.class))) .thenReturn(badTransport); FakeNameResolverFactory nameResolverFactory = new FakeNameResolverFactory(Arrays.asList(badServer, goodServer)); ManagedChannel channel = createChannel(nameResolverFactory, NO_INTERCEPTOR); ClientCall<String, Integer> call = channel.newCall(method, CallOptions.DEFAULT); Metadata headers = new Metadata(); call.start(mockCallListener, headers); ArgumentCaptor<ManagedClientTransport.Listener> badTransportListenerCaptor = ArgumentCaptor.forClass(ManagedClientTransport.Listener.class); verify(badTransport, timeout(1000)).start(badTransportListenerCaptor.capture()); verify(mockTransportFactory).newClientTransport(same(badAddress), any(String.class)); verify(mockTransportFactory, times(0)) .newClientTransport(same(goodAddress), any(String.class)); badTransportListenerCaptor.getValue().transportShutdown(Status.UNAVAILABLE); ArgumentCaptor<ManagedClientTransport.Listener> goodTransportListenerCaptor = ArgumentCaptor.forClass(ManagedClientTransport.Listener.class); verify(mockTransportFactory, timeout(1000)) .newClientTransport(same(goodAddress), any(String.class)); verify(goodTransport, timeout(1000)).start(goodTransportListenerCaptor.capture()); goodTransportListenerCaptor.getValue().transportReady(); verify(goodTransport, timeout(1000)).newStream(same(method), same(headers)); verify(badTransport, times(0)).newStream(any(MethodDescriptor.class), any(Metadata.class)); }
@Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) { return interceptorChannel.newCall(method, callOptions); }
ManagedChannelImpl extends ManagedChannel implements WithLogId { @Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) { return interceptorChannel.newCall(method, callOptions); } }
ManagedChannelImpl extends ManagedChannel implements WithLogId { @Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) { return interceptorChannel.newCall(method, callOptions); } ManagedChannelImpl(String target, BackoffPolicy.Provider backoffPolicyProvider,
      NameResolver.Factory nameResolverFactory, Attributes nameResolverParams,
      LoadBalancer.Factory loadBalancerFactory, ClientTransportFactory transportFactory,
      DecompressorRegistry decompressorRegistry, CompressorRegistry compressorRegistry,
      @Nullable Executor executor, @Nullable String userAgent,
      List<ClientInterceptor> interceptors); }
ManagedChannelImpl extends ManagedChannel implements WithLogId { @Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) { return interceptorChannel.newCall(method, callOptions); } ManagedChannelImpl(String target, BackoffPolicy.Provider backoffPolicyProvider,
      NameResolver.Factory nameResolverFactory, Attributes nameResolverParams,
      LoadBalancer.Factory loadBalancerFactory, ClientTransportFactory transportFactory,
      DecompressorRegistry decompressorRegistry, CompressorRegistry compressorRegistry,
      @Nullable Executor executor, @Nullable String userAgent,
      List<ClientInterceptor> interceptors); @Override ManagedChannelImpl shutdown(); @Override ManagedChannelImpl shutdownNow(); @Override boolean isShutdown(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override boolean isTerminated(); @Override ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method,
      CallOptions callOptions); @Override String authority(); @Override String getLogId(); }
ManagedChannelImpl extends ManagedChannel implements WithLogId { @Override public <ReqT, RespT> ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions) { return interceptorChannel.newCall(method, callOptions); } ManagedChannelImpl(String target, BackoffPolicy.Provider backoffPolicyProvider,
      NameResolver.Factory nameResolverFactory, Attributes nameResolverParams,
      LoadBalancer.Factory loadBalancerFactory, ClientTransportFactory transportFactory,
      DecompressorRegistry decompressorRegistry, CompressorRegistry compressorRegistry,
      @Nullable Executor executor, @Nullable String userAgent,
      List<ClientInterceptor> interceptors); @Override ManagedChannelImpl shutdown(); @Override ManagedChannelImpl shutdownNow(); @Override boolean isShutdown(); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override boolean isTerminated(); @Override ClientCall<ReqT, RespT> newCall(MethodDescriptor<ReqT, RespT> method,
      CallOptions callOptions); @Override String authority(); @Override String getLogId();  }