Search in sources :

Example 1 with GrpcHttp2ConnectionHandler

use of io.grpc.netty.GrpcHttp2ConnectionHandler 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 2 with GrpcHttp2ConnectionHandler

use of io.grpc.netty.GrpcHttp2ConnectionHandler in project grpc-java by grpc.

the class XdsClientWrapperForServerSdsTestMisc method getSslContextProviderSupplier.

private SslContextProviderSupplier getSslContextProviderSupplier(FilterChainSelector selector) throws Exception {
    final SettableFuture<SslContextProviderSupplier> sslSet = SettableFuture.create();
    ChannelHandler next = new ChannelInboundHandlerAdapter() {

        @Override
        public void userEventTriggered(ChannelHandlerContext ctx, Object evt) {
            ProtocolNegotiationEvent e = (ProtocolNegotiationEvent) evt;
            sslSet.set(InternalProtocolNegotiationEvent.getAttributes(e).get(ATTR_SERVER_SSL_CONTEXT_PROVIDER_SUPPLIER));
            ctx.pipeline().remove(this);
        }
    };
    ProtocolNegotiator mockDelegate = mock(ProtocolNegotiator.class);
    GrpcHttp2ConnectionHandler grpcHandler = FakeGrpcHttp2ConnectionHandler.newHandler();
    when(mockDelegate.newHandler(grpcHandler)).thenReturn(next);
    FilterChainSelectorManager manager = new FilterChainSelectorManager();
    manager.updateSelector(selector);
    FilterChainMatchingHandler filterChainMatchingHandler = new FilterChainMatchingHandler(grpcHandler, manager, mockDelegate);
    pipeline.addLast(filterChainMatchingHandler);
    ProtocolNegotiationEvent event = InternalProtocolNegotiationEvent.getDefault();
    pipeline.fireUserEventTriggered(event);
    channel.runPendingTasks();
    sslSet.set(InternalProtocolNegotiationEvent.getAttributes(event).get(ATTR_SERVER_SSL_CONTEXT_PROVIDER_SUPPLIER));
    return sslSet.get();
}
Also used : ProtocolNegotiationEvent(io.grpc.netty.ProtocolNegotiationEvent) InternalProtocolNegotiationEvent(io.grpc.netty.InternalProtocolNegotiationEvent) ProtocolNegotiator(io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator) FilterChainMatchingHandler(io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler) ChannelHandlerContext(io.netty.channel.ChannelHandlerContext) ChannelHandler(io.netty.channel.ChannelHandler) GrpcHttp2ConnectionHandler(io.grpc.netty.GrpcHttp2ConnectionHandler) SslContextProviderSupplier(io.grpc.xds.internal.sds.SslContextProviderSupplier) ChannelInboundHandlerAdapter(io.netty.channel.ChannelInboundHandlerAdapter)

Aggregations

GrpcHttp2ConnectionHandler (io.grpc.netty.GrpcHttp2ConnectionHandler)2 ChannelHandler (io.netty.channel.ChannelHandler)2 ChannelLogger (io.grpc.ChannelLogger)1 ChannelLogLevel (io.grpc.ChannelLogger.ChannelLogLevel)1 NoopChannelLogger (io.grpc.internal.TestUtils.NoopChannelLogger)1 InternalProtocolNegotiationEvent (io.grpc.netty.InternalProtocolNegotiationEvent)1 ProtocolNegotiator (io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator)1 ProtocolNegotiationEvent (io.grpc.netty.ProtocolNegotiationEvent)1 UpstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext)1 FilterChainMatchingHandler (io.grpc.xds.FilterChainMatchingProtocolNegotiators.FilterChainMatchingHandler)1 TlsContextManager (io.grpc.xds.TlsContextManager)1 ClientSdsProtocolNegotiator (io.grpc.xds.internal.sds.SdsProtocolNegotiators.ClientSdsProtocolNegotiator)1 SslContextProviderSupplier (io.grpc.xds.internal.sds.SslContextProviderSupplier)1 ChannelHandlerContext (io.netty.channel.ChannelHandlerContext)1 ChannelInboundHandlerAdapter (io.netty.channel.ChannelInboundHandlerAdapter)1 Test (org.junit.Test)1