Search in sources :

Example 1 with ChannelLogger

use of io.grpc.ChannelLogger in project grpc-java by grpc.

the class AltsProtocolNegotiatorTest method setup.

@Before
public void setup() throws Exception {
    ChannelHandler uncaughtExceptionHandler = new ChannelDuplexHandler() {

        @Override
        public void exceptionCaught(ChannelHandlerContext ctx, Throwable cause) throws Exception {
            caughtException = cause;
            super.exceptionCaught(ctx, cause);
            ctx.close();
        }
    };
    TsiHandshakerFactory handshakerFactory = new DelegatingTsiHandshakerFactory(FakeTsiHandshaker.clientHandshakerFactory()) {

        @Override
        public TsiHandshaker newHandshaker(String authority, ChannelLogger logger) {
            return new DelegatingTsiHandshaker(super.newHandshaker(authority, logger)) {

                @Override
                public TsiPeer extractPeer() throws GeneralSecurityException {
                    return mockedTsiPeer;
                }

                @Override
                public Object extractPeerObject() throws GeneralSecurityException {
                    return mockedAltsContext;
                }
            };
        }
    };
    ManagedChannel fakeChannel = NettyChannelBuilder.forTarget("localhost:8080").build();
    ObjectPool<Channel> fakeChannelPool = new FixedObjectPool<Channel>(fakeChannel);
    LazyChannel lazyFakeChannel = new LazyChannel(fakeChannelPool);
    ChannelHandler altsServerHandler = new ServerAltsProtocolNegotiator(handshakerFactory, lazyFakeChannel).newHandler(grpcHandler);
    // On real server, WBAEH fires default ProtocolNegotiationEvent. KickNH provides this behavior.
    ChannelHandler handler = new KickNegotiationHandler(altsServerHandler);
    channel = new EmbeddedChannel(uncaughtExceptionHandler, handler);
}
Also used : ServerAltsProtocolNegotiator(io.grpc.alts.internal.AltsProtocolNegotiator.ServerAltsProtocolNegotiator) LazyChannel(io.grpc.alts.internal.AltsProtocolNegotiator.LazyChannel) ManagedChannel(io.grpc.ManagedChannel) Channel(io.grpc.Channel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) LazyChannel(io.grpc.alts.internal.AltsProtocolNegotiator.LazyChannel) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) ChannelDuplexHandler(io.netty.channel.ChannelDuplexHandler) ManagedChannel(io.grpc.ManagedChannel) ChannelLogger(io.grpc.ChannelLogger) NoopChannelLogger(io.grpc.internal.TestUtils.NoopChannelLogger) FixedObjectPool(io.grpc.internal.FixedObjectPool) Before(org.junit.Before)

Example 2 with ChannelLogger

use of io.grpc.ChannelLogger in project grpc-java by grpc.

the class NettyTransportTest method channelHasUnresolvedHostname.

@Test
public void channelHasUnresolvedHostname() throws Exception {
    server = null;
    final SettableFuture<Status> future = SettableFuture.create();
    ChannelLogger logger = transportLogger();
    ManagedClientTransport transport = clientFactory.newClientTransport(InetSocketAddress.createUnresolved("invalid", 1234), new ClientTransportFactory.ClientTransportOptions().setChannelLogger(logger), logger);
    Runnable runnable = transport.start(new ManagedClientTransport.Listener() {

        @Override
        public void transportShutdown(Status s) {
            future.set(s);
        }

        @Override
        public void transportTerminated() {
        }

        @Override
        public void transportReady() {
            Throwable t = new Throwable("transport should have failed and shutdown but didnt");
            future.setException(t);
        }

        @Override
        public void transportInUse(boolean inUse) {
            Throwable t = new Throwable("transport should have failed and shutdown but didnt");
            future.setException(t);
        }
    });
    if (runnable != null) {
        runnable.run();
    }
    try {
        Status status = future.get();
        assertEquals(Status.Code.UNAVAILABLE, status.getCode());
        assertThat(status.getCause()).isInstanceOf(UnresolvedAddressException.class);
        assertEquals("unresolved address", status.getDescription());
    } finally {
        transport.shutdown(Status.UNAVAILABLE.withDescription("test shutdown"));
    }
}
Also used : Status(io.grpc.Status) ManagedClientTransport(io.grpc.internal.ManagedClientTransport) ChannelLogger(io.grpc.ChannelLogger) AbstractTransportTest(io.grpc.internal.AbstractTransportTest) Test(org.junit.Test)

Example 3 with ChannelLogger

use of io.grpc.ChannelLogger in project grpc-java by grpc.

the class SdsProtocolNegotiatorsTest method clientSdsProtocolNegotiatorNewHandler_withTlsContextAttribute.

@Test
public void clientSdsProtocolNegotiatorNewHandler_withTlsContextAttribute() {
    UpstreamTlsContext upstreamTlsContext = CommonTlsContextTestsUtil.buildUpstreamTlsContext(CommonTlsContext.newBuilder().build());
    ClientSdsProtocolNegotiator pn = new ClientSdsProtocolNegotiator(InternalProtocolNegotiators.plaintext());
    GrpcHttp2ConnectionHandler mockHandler = mock(GrpcHttp2ConnectionHandler.class);
    ChannelLogger logger = mock(ChannelLogger.class);
    doNothing().when(logger).log(any(ChannelLogLevel.class), anyString());
    when(mockHandler.getNegotiationLogger()).thenReturn(logger);
    TlsContextManager mockTlsContextManager = mock(TlsContextManager.class);
    when(mockHandler.getEagAttributes()).thenReturn(Attributes.newBuilder().set(InternalXdsAttributes.ATTR_SSL_CONTEXT_PROVIDER_SUPPLIER, new SslContextProviderSupplier(upstreamTlsContext, mockTlsContextManager)).build());
    ChannelHandler newHandler = pn.newHandler(mockHandler);
    assertThat(newHandler).isNotNull();
    assertThat(newHandler).isInstanceOf(ClientSdsHandler.class);
}
Also used : ClientSdsProtocolNegotiator(io.grpc.xds.internal.sds.SdsProtocolNegotiators.ClientSdsProtocolNegotiator) UpstreamTlsContext(io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext) TlsContextManager(io.grpc.xds.TlsContextManager) ChannelLogger(io.grpc.ChannelLogger) NoopChannelLogger(io.grpc.internal.TestUtils.NoopChannelLogger) ChannelHandler(io.netty.channel.ChannelHandler) GrpcHttp2ConnectionHandler(io.grpc.netty.GrpcHttp2ConnectionHandler) ChannelLogLevel(io.grpc.ChannelLogger.ChannelLogLevel) Test(org.junit.Test)

Example 4 with ChannelLogger

use of io.grpc.ChannelLogger in project grpc-java by grpc.

the class ProtocolNegotiators method httpProxy.

/**
 * Returns a {@link ProtocolNegotiator} that does HTTP CONNECT proxy negotiation.
 */
public static ProtocolNegotiator httpProxy(final SocketAddress proxyAddress, @Nullable final String proxyUsername, @Nullable final String proxyPassword, final ProtocolNegotiator negotiator) {
    checkNotNull(negotiator, "negotiator");
    checkNotNull(proxyAddress, "proxyAddress");
    final AsciiString scheme = negotiator.scheme();
    class ProxyNegotiator implements ProtocolNegotiator {

        @Override
        public ChannelHandler newHandler(GrpcHttp2ConnectionHandler http2Handler) {
            ChannelHandler protocolNegotiationHandler = negotiator.newHandler(http2Handler);
            ChannelLogger negotiationLogger = http2Handler.getNegotiationLogger();
            return new ProxyProtocolNegotiationHandler(proxyAddress, proxyUsername, proxyPassword, protocolNegotiationHandler, negotiationLogger);
        }

        @Override
        public AsciiString scheme() {
            return scheme;
        }

        // This method is not normally called, because we use httpProxy on a per-connection basis in
        // NettyChannelBuilder. Instead, we expect `negotiator' to be closed by NettyTransportFactory.
        @Override
        public void close() {
            negotiator.close();
        }
    }
    return new ProxyNegotiator();
}
Also used : AsciiString(io.netty.util.AsciiString) ChannelHandler(io.netty.channel.ChannelHandler) ChannelLogger(io.grpc.ChannelLogger)

Example 5 with ChannelLogger

use of io.grpc.ChannelLogger in project grpc-java by grpc.

the class AbstractClientTransportFactoryTest method newClientTransportAfterCloseShouldThrow.

@Test(expected = IllegalStateException.class)
public void newClientTransportAfterCloseShouldThrow() {
    ClientTransportFactory transportFactory = newClientTransportFactory();
    transportFactory.close();
    transportFactory.newClientTransport(new InetSocketAddress("localhost", 12345), new ClientTransportFactory.ClientTransportOptions(), new ChannelLogger() {

        @Override
        public void log(ChannelLogLevel level, String message) {
        }

        @Override
        public void log(ChannelLogLevel level, String messageFormat, Object... args) {
        }
    });
}
Also used : ClientTransportFactory(io.grpc.internal.ClientTransportFactory) InetSocketAddress(java.net.InetSocketAddress) ChannelLogger(io.grpc.ChannelLogger) Test(org.junit.Test)

Aggregations

ChannelLogger (io.grpc.ChannelLogger)5 ChannelHandler (io.netty.channel.ChannelHandler)3 Test (org.junit.Test)3 NoopChannelLogger (io.grpc.internal.TestUtils.NoopChannelLogger)2 Channel (io.grpc.Channel)1 ChannelLogLevel (io.grpc.ChannelLogger.ChannelLogLevel)1 ManagedChannel (io.grpc.ManagedChannel)1 Status (io.grpc.Status)1 LazyChannel (io.grpc.alts.internal.AltsProtocolNegotiator.LazyChannel)1 ServerAltsProtocolNegotiator (io.grpc.alts.internal.AltsProtocolNegotiator.ServerAltsProtocolNegotiator)1 AbstractTransportTest (io.grpc.internal.AbstractTransportTest)1 ClientTransportFactory (io.grpc.internal.ClientTransportFactory)1 FixedObjectPool (io.grpc.internal.FixedObjectPool)1 ManagedClientTransport (io.grpc.internal.ManagedClientTransport)1 GrpcHttp2ConnectionHandler (io.grpc.netty.GrpcHttp2ConnectionHandler)1 UpstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext)1 TlsContextManager (io.grpc.xds.TlsContextManager)1 ClientSdsProtocolNegotiator (io.grpc.xds.internal.sds.SdsProtocolNegotiators.ClientSdsProtocolNegotiator)1 ChannelDuplexHandler (io.netty.channel.ChannelDuplexHandler)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1