use of io.grpc.internal.TransportTracer in project grpc-java by grpc.
the class OkHttpClientTransportTest method unreachableServer.
@Test
public void unreachableServer() throws Exception {
clientTransport = new OkHttpClientTransport(new InetSocketAddress("localhost", 0), "authority", "userAgent", EAG_ATTRS, executor, socketFactory, sslSocketFactory, hostnameVerifier, ConnectionSpec.CLEARTEXT, DEFAULT_MAX_MESSAGE_SIZE, INITIAL_WINDOW_SIZE, NO_PROXY, tooManyPingsRunnable, DEFAULT_MAX_INBOUND_METADATA_SIZE, new TransportTracer(), false);
ManagedClientTransport.Listener listener = mock(ManagedClientTransport.Listener.class);
clientTransport.start(listener);
ArgumentCaptor<Status> captor = ArgumentCaptor.forClass(Status.class);
verify(listener, timeout(TIME_OUT_MS)).transportShutdown(captor.capture());
Status status = captor.getValue();
assertEquals(Status.UNAVAILABLE.getCode(), status.getCode());
assertTrue(status.getCause().toString(), status.getCause() instanceof IOException);
MockStreamListener streamListener = new MockStreamListener();
clientTransport.newStream(method, new Metadata(), CallOptions.DEFAULT, tracers).start(streamListener);
streamListener.waitUntilStreamClosed();
assertEquals(Status.UNAVAILABLE.getCode(), streamListener.status.getCode());
}
use of io.grpc.internal.TransportTracer in project grpc-java by grpc.
the class NettyClientTransportTest method setSoLingerChannelOption.
@Test
public void setSoLingerChannelOption() throws IOException {
startServer();
Map<ChannelOption<?>, Object> channelOptions = new HashMap<>();
// set SO_LINGER option
int soLinger = 123;
channelOptions.put(ChannelOption.SO_LINGER, soLinger);
NettyClientTransport transport = new NettyClientTransport(address, new ReflectiveChannelFactory<>(NioSocketChannel.class), channelOptions, group, newNegotiator(), false, DEFAULT_WINDOW_SIZE, DEFAULT_MAX_MESSAGE_SIZE, GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE, KEEPALIVE_TIME_NANOS_DISABLED, 1L, false, authority, null, /* user agent */
tooManyPingsRunnable, new TransportTracer(), Attributes.EMPTY, new SocketPicker(), new FakeChannelLogger(), false);
transports.add(transport);
callMeMaybe(transport.start(clientTransportListener));
// verify SO_LINGER has been set
ChannelConfig config = transport.channel().config();
assertTrue(config instanceof SocketChannelConfig);
assertEquals(soLinger, ((SocketChannelConfig) config).getSoLinger());
}
use of io.grpc.internal.TransportTracer in project grpc-java by grpc.
the class NettyClientTransportTest method failingToConstructChannelShouldFailGracefully.
@Test
public void failingToConstructChannelShouldFailGracefully() throws Exception {
address = TestUtils.testServerAddress(new InetSocketAddress(12345));
authority = GrpcUtil.authorityFromHostAndPort(address.getHostString(), address.getPort());
NettyClientTransport transport = new NettyClientTransport(address, new ReflectiveChannelFactory<>(CantConstructChannel.class), new HashMap<ChannelOption<?>, Object>(), group, newNegotiator(), false, DEFAULT_WINDOW_SIZE, DEFAULT_MAX_MESSAGE_SIZE, GrpcUtil.DEFAULT_MAX_HEADER_LIST_SIZE, KEEPALIVE_TIME_NANOS_DISABLED, 1, false, authority, null, tooManyPingsRunnable, new TransportTracer(), Attributes.EMPTY, new SocketPicker(), new FakeChannelLogger(), false);
transports.add(transport);
// Should not throw
callMeMaybe(transport.start(clientTransportListener));
// And RPCs and PINGs should fail cleanly, reporting the failure
Rpc rpc = new Rpc(transport);
try {
rpc.waitForResponse();
fail("Expected exception");
} catch (Exception ex) {
if (!(getRootCause(ex) instanceof CantConstructChannelError)) {
throw new AssertionError("Could not find expected error", ex);
}
}
final SettableFuture<Object> pingResult = SettableFuture.create();
FakeClock clock = new FakeClock();
ClientTransport.PingCallback pingCallback = new ClientTransport.PingCallback() {
@Override
public void onSuccess(long roundTripTimeNanos) {
pingResult.set(roundTripTimeNanos);
}
@Override
public void onFailure(Throwable cause) {
pingResult.setException(cause);
}
};
transport.ping(pingCallback, clock.getScheduledExecutorService());
assertFalse(pingResult.isDone());
clock.runDueTasks();
assertTrue(pingResult.isDone());
try {
pingResult.get();
fail("Expected exception");
} catch (Exception ex) {
if (!(getRootCause(ex) instanceof CantConstructChannelError)) {
throw new AssertionError("Could not find expected error", ex);
}
}
}
use of io.grpc.internal.TransportTracer in project grpc-java by grpc.
the class NettyServerStreamTest method createStream.
@Override
protected NettyServerStream createStream() {
when(handler.getWriteQueue()).thenReturn(writeQueue);
StatsTraceContext statsTraceCtx = StatsTraceContext.NOOP;
TransportTracer transportTracer = new TransportTracer();
NettyServerStream.TransportState state = new NettyServerStream.TransportState(handler, channel.eventLoop(), http2Stream, DEFAULT_MAX_MESSAGE_SIZE, statsTraceCtx, transportTracer, "method");
NettyServerStream stream = new NettyServerStream(channel, state, Attributes.EMPTY, "test-authority", statsTraceCtx, transportTracer);
stream.transportState().setListener(serverListener);
state.onStreamAllocated();
verify(serverListener, atLeastOnce()).onReady();
verifyNoMoreInteractions(serverListener);
return stream;
}
use of io.grpc.internal.TransportTracer in project grpc-java by grpc.
the class OkHttpClientTransportTest method startTransport.
private void startTransport(int startId, @Nullable Runnable connectingCallback, boolean waitingForConnected, int maxMessageSize, int initialWindowSize, String userAgent) throws Exception {
connectedFuture = SettableFuture.create();
final Ticker ticker = new Ticker() {
@Override
public long read() {
return nanoTime;
}
};
Supplier<Stopwatch> stopwatchSupplier = new Supplier<Stopwatch>() {
@Override
public Stopwatch get() {
return Stopwatch.createUnstarted(ticker);
}
};
clientTransport = new OkHttpClientTransport(userAgent, executor, frameReader, frameWriter, new OkHttpFrameLogger(Level.FINE, logger), startId, socket, stopwatchSupplier, connectingCallback, connectedFuture, maxMessageSize, initialWindowSize, tooManyPingsRunnable, new TransportTracer());
clientTransport.start(transportListener);
if (waitingForConnected) {
connectedFuture.get(TIME_OUT_MS, TimeUnit.MILLISECONDS);
}
}
Aggregations