Search in sources :

Example 1 with TransportTracer

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());
}
Also used : Status(io.grpc.Status) InternalStatus(io.grpc.InternalStatus) ManagedClientTransport(io.grpc.internal.ManagedClientTransport) InetSocketAddress(java.net.InetSocketAddress) Metadata(io.grpc.Metadata) IOException(java.io.IOException) TransportTracer(io.grpc.internal.TransportTracer) Test(org.junit.Test)

Example 2 with TransportTracer

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());
}
Also used : ChannelOption(io.netty.channel.ChannelOption) HashMap(java.util.HashMap) LocalSocketPicker(io.grpc.netty.NettyChannelBuilder.LocalSocketPicker) NioSocketChannel(io.netty.channel.socket.nio.NioSocketChannel) SocketChannelConfig(io.netty.channel.socket.SocketChannelConfig) ChannelConfig(io.netty.channel.ChannelConfig) SocketChannelConfig(io.netty.channel.socket.SocketChannelConfig) TransportTracer(io.grpc.internal.TransportTracer) TrackingObjectPoolForTest(io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest) Test(org.junit.Test)

Example 3 with TransportTracer

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);
        }
    }
}
Also used : ChannelOption(io.netty.channel.ChannelOption) InetSocketAddress(java.net.InetSocketAddress) FakeClock(io.grpc.internal.FakeClock) LocalSocketPicker(io.grpc.netty.NettyChannelBuilder.LocalSocketPicker) ClientTransport(io.grpc.internal.ClientTransport) ManagedClientTransport(io.grpc.internal.ManagedClientTransport) TimeoutException(java.util.concurrent.TimeoutException) SSLHandshakeException(javax.net.ssl.SSLHandshakeException) SSLException(javax.net.ssl.SSLException) StatusException(io.grpc.StatusException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TransportTracer(io.grpc.internal.TransportTracer) TrackingObjectPoolForTest(io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest) Test(org.junit.Test)

Example 4 with TransportTracer

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;
}
Also used : StatsTraceContext(io.grpc.internal.StatsTraceContext) TransportTracer(io.grpc.internal.TransportTracer)

Example 5 with TransportTracer

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);
    }
}
Also used : Ticker(com.google.common.base.Ticker) Stopwatch(com.google.common.base.Stopwatch) Supplier(com.google.common.base.Supplier) TransportTracer(io.grpc.internal.TransportTracer)

Aggregations

TransportTracer (io.grpc.internal.TransportTracer)7 Test (org.junit.Test)4 ManagedClientTransport (io.grpc.internal.ManagedClientTransport)3 LocalSocketPicker (io.grpc.netty.NettyChannelBuilder.LocalSocketPicker)3 ChannelOption (io.netty.channel.ChannelOption)3 InetSocketAddress (java.net.InetSocketAddress)3 InternalStatus (io.grpc.InternalStatus)2 Status (io.grpc.Status)2 TrackingObjectPoolForTest (io.grpc.netty.NettyTestUtil.TrackingObjectPoolForTest)2 IOException (java.io.IOException)2 Stopwatch (com.google.common.base.Stopwatch)1 Supplier (com.google.common.base.Supplier)1 Ticker (com.google.common.base.Ticker)1 Metadata (io.grpc.Metadata)1 StatusException (io.grpc.StatusException)1 ClientTransport (io.grpc.internal.ClientTransport)1 FakeClock (io.grpc.internal.FakeClock)1 StatsTraceContext (io.grpc.internal.StatsTraceContext)1 ChannelConfig (io.netty.channel.ChannelConfig)1 SocketChannelConfig (io.netty.channel.socket.SocketChannelConfig)1