@Test public void getTransportFromPickResult_dropPickResult_waitForReady() { Status status = Status.UNAVAILABLE; PickResult pickResult = PickResult.withDrop(status); ClientTransport transport = GrpcUtil.getTransportFromPickResult(pickResult, true); assertNotNull(transport); ClientStream stream = transport .newStream(TestMethodDescriptors.voidMethod(), new Metadata(), CallOptions.DEFAULT); ClientStreamListener listener = mock(ClientStreamListener.class); stream.start(listener); verify(listener).closed(eq(status), eq(RpcProgress.DROPPED), any(Metadata.class)); }
@Nullable static ClientTransport getTransportFromPickResult(PickResult result, boolean isWaitForReady) { final ClientTransport transport; Subchannel subchannel = result.getSubchannel(); if (subchannel != null) { transport = ((AbstractSubchannel) subchannel).obtainActiveTransport(); } else { transport = null; } if (transport != null) { final ClientStreamTracer.Factory streamTracerFactory = result.getStreamTracerFactory(); if (streamTracerFactory == null) { return transport; } return new ClientTransport() { @Override public ClientStream newStream( MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions) { return transport.newStream( method, headers, callOptions.withStreamTracerFactory(streamTracerFactory)); } @Override public void ping(PingCallback callback, Executor executor) { transport.ping(callback, executor); } @Override public InternalLogId getLogId() { return transport.getLogId(); } @Override public ListenableFuture<SocketStats> getStats() { return transport.getStats(); } }; } if (!result.getStatus().isOk()) { if (result.isDrop()) { return new FailingClientTransport(result.getStatus(), RpcProgress.DROPPED); } if (!isWaitForReady) { return new FailingClientTransport(result.getStatus(), RpcProgress.PROCESSED); } } return null; }
GrpcUtil { @Nullable static ClientTransport getTransportFromPickResult(PickResult result, boolean isWaitForReady) { final ClientTransport transport; Subchannel subchannel = result.getSubchannel(); if (subchannel != null) { transport = ((AbstractSubchannel) subchannel).obtainActiveTransport(); } else { transport = null; } if (transport != null) { final ClientStreamTracer.Factory streamTracerFactory = result.getStreamTracerFactory(); if (streamTracerFactory == null) { return transport; } return new ClientTransport() { @Override public ClientStream newStream( MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions) { return transport.newStream( method, headers, callOptions.withStreamTracerFactory(streamTracerFactory)); } @Override public void ping(PingCallback callback, Executor executor) { transport.ping(callback, executor); } @Override public InternalLogId getLogId() { return transport.getLogId(); } @Override public ListenableFuture<SocketStats> getStats() { return transport.getStats(); } }; } if (!result.getStatus().isOk()) { if (result.isDrop()) { return new FailingClientTransport(result.getStatus(), RpcProgress.DROPPED); } if (!isWaitForReady) { return new FailingClientTransport(result.getStatus(), RpcProgress.PROCESSED); } } return null; } }
GrpcUtil { @Nullable static ClientTransport getTransportFromPickResult(PickResult result, boolean isWaitForReady) { final ClientTransport transport; Subchannel subchannel = result.getSubchannel(); if (subchannel != null) { transport = ((AbstractSubchannel) subchannel).obtainActiveTransport(); } else { transport = null; } if (transport != null) { final ClientStreamTracer.Factory streamTracerFactory = result.getStreamTracerFactory(); if (streamTracerFactory == null) { return transport; } return new ClientTransport() { @Override public ClientStream newStream( MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions) { return transport.newStream( method, headers, callOptions.withStreamTracerFactory(streamTracerFactory)); } @Override public void ping(PingCallback callback, Executor executor) { transport.ping(callback, executor); } @Override public InternalLogId getLogId() { return transport.getLogId(); } @Override public ListenableFuture<SocketStats> getStats() { return transport.getStats(); } }; } if (!result.getStatus().isOk()) { if (result.isDrop()) { return new FailingClientTransport(result.getStatus(), RpcProgress.DROPPED); } if (!isWaitForReady) { return new FailingClientTransport(result.getStatus(), RpcProgress.PROCESSED); } } return null; } private  GrpcUtil(); }
GrpcUtil { @Nullable static ClientTransport getTransportFromPickResult(PickResult result, boolean isWaitForReady) { final ClientTransport transport; Subchannel subchannel = result.getSubchannel(); if (subchannel != null) { transport = ((AbstractSubchannel) subchannel).obtainActiveTransport(); } else { transport = null; } if (transport != null) { final ClientStreamTracer.Factory streamTracerFactory = result.getStreamTracerFactory(); if (streamTracerFactory == null) { return transport; } return new ClientTransport() { @Override public ClientStream newStream( MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions) { return transport.newStream( method, headers, callOptions.withStreamTracerFactory(streamTracerFactory)); } @Override public void ping(PingCallback callback, Executor executor) { transport.ping(callback, executor); } @Override public InternalLogId getLogId() { return transport.getLogId(); } @Override public ListenableFuture<SocketStats> getStats() { return transport.getStats(); } }; } if (!result.getStatus().isOk()) { if (result.isDrop()) { return new FailingClientTransport(result.getStatus(), RpcProgress.DROPPED); } if (!isWaitForReady) { return new FailingClientTransport(result.getStatus(), RpcProgress.PROCESSED); } } return null; } private  GrpcUtil(); static boolean shouldBeCountedForInUse(CallOptions callOptions); static ProxyDetector getDefaultProxyDetector(); static Status httpStatusToGrpcStatus(int httpStatusCode); static boolean isGrpcContentType(String contentType); static String getGrpcUserAgent(
      String transportName, @Nullable String applicationUserAgent); static URI authorityToUri(String authority); static String checkAuthority(String authority); static String authorityFromHostAndPort(String host, int port); static ThreadFactory getThreadFactory(String nameFormat, boolean daemon); static String getHost(InetSocketAddress addr); static void closeQuietly(@Nullable InputStream message); static EquivalentAddressGroup getAddressGroupFromTransport(ClientTransport transport); }
GrpcUtil { @Nullable static ClientTransport getTransportFromPickResult(PickResult result, boolean isWaitForReady) { final ClientTransport transport; Subchannel subchannel = result.getSubchannel(); if (subchannel != null) { transport = ((AbstractSubchannel) subchannel).obtainActiveTransport(); } else { transport = null; } if (transport != null) { final ClientStreamTracer.Factory streamTracerFactory = result.getStreamTracerFactory(); if (streamTracerFactory == null) { return transport; } return new ClientTransport() { @Override public ClientStream newStream( MethodDescriptor<?, ?> method, Metadata headers, CallOptions callOptions) { return transport.newStream( method, headers, callOptions.withStreamTracerFactory(streamTracerFactory)); } @Override public void ping(PingCallback callback, Executor executor) { transport.ping(callback, executor); } @Override public InternalLogId getLogId() { return transport.getLogId(); } @Override public ListenableFuture<SocketStats> getStats() { return transport.getStats(); } }; } if (!result.getStatus().isOk()) { if (result.isDrop()) { return new FailingClientTransport(result.getStatus(), RpcProgress.DROPPED); } if (!isWaitForReady) { return new FailingClientTransport(result.getStatus(), RpcProgress.PROCESSED); } } return null; } private  GrpcUtil(); static boolean shouldBeCountedForInUse(CallOptions callOptions); static ProxyDetector getDefaultProxyDetector(); static Status httpStatusToGrpcStatus(int httpStatusCode); static boolean isGrpcContentType(String contentType); static String getGrpcUserAgent(
      String transportName, @Nullable String applicationUserAgent); static URI authorityToUri(String authority); static String checkAuthority(String authority); static String authorityFromHostAndPort(String host, int port); static ThreadFactory getThreadFactory(String nameFormat, boolean daemon); static String getHost(InetSocketAddress addr); static void closeQuietly(@Nullable InputStream message); static EquivalentAddressGroup getAddressGroupFromTransport(ClientTransport transport); static final Charset US_ASCII; static final boolean IS_RESTRICTED_APPENGINE; static final Metadata.Key<Long> TIMEOUT_KEY; static final Metadata.Key<String> MESSAGE_ENCODING_KEY; static final Metadata.Key<byte[]> MESSAGE_ACCEPT_ENCODING_KEY; static final Metadata.Key<String> CONTENT_ENCODING_KEY; static final Metadata.Key<byte[]> CONTENT_ACCEPT_ENCODING_KEY; static final Metadata.Key<String> CONTENT_TYPE_KEY; static final Metadata.Key<String> TE_HEADER; static final Metadata.Key<String> USER_AGENT_KEY; static final int DEFAULT_PORT_PLAINTEXT; static final int DEFAULT_PORT_SSL; static final String CONTENT_TYPE_GRPC; static final String HTTP_METHOD; static final String TE_TRAILERS; static final String TIMEOUT; static final String MESSAGE_ENCODING; static final String MESSAGE_ACCEPT_ENCODING; static final String CONTENT_ENCODING; static final String CONTENT_ACCEPT_ENCODING; static final int DEFAULT_MAX_MESSAGE_SIZE; static final int DEFAULT_MAX_HEADER_LIST_SIZE; static final Splitter ACCEPT_ENCODING_SPLITTER; static final long DEFAULT_KEEPALIVE_TIME_NANOS; static final long DEFAULT_KEEPALIVE_TIMEOUT_NANOS; static final long KEEPALIVE_TIME_NANOS_DISABLED; static final long DEFAULT_SERVER_KEEPALIVE_TIME_NANOS; static final long DEFAULT_SERVER_KEEPALIVE_TIMEOUT_NANOS; static final long SERVER_KEEPALIVE_TIME_NANOS_DISABLED; static final ProxyDetector DEFAULT_PROXY_DETECTOR; static final ProxyDetector NOOP_PROXY_DETECTOR; static final CallOptions.Key<Boolean> CALL_OPTIONS_RPC_OWNED_BY_BALANCER; static final Resource<Executor> SHARED_CHANNEL_EXECUTOR; static final Resource<ScheduledExecutorService> TIMER_SERVICE; static final Supplier<Stopwatch> STOPWATCH_SUPPLIER; }