Search in sources :

Example 1 with ClientSdsProtocolNegotiator

use of io.grpc.xds.internal.sds.SdsProtocolNegotiators.ClientSdsProtocolNegotiator in project grpc-java by grpc.

the class SdsProtocolNegotiatorsTest method clientSdsProtocolNegotiatorNewHandler_noTlsContextAttribute.

@Test
public void clientSdsProtocolNegotiatorNewHandler_noTlsContextAttribute() {
    ChannelHandler mockChannelHandler = mock(ChannelHandler.class);
    ProtocolNegotiator mockProtocolNegotiator = mock(ProtocolNegotiator.class);
    when(mockProtocolNegotiator.newHandler(grpcHandler)).thenReturn(mockChannelHandler);
    ClientSdsProtocolNegotiator pn = new ClientSdsProtocolNegotiator(mockProtocolNegotiator);
    ChannelHandler newHandler = pn.newHandler(grpcHandler);
    assertThat(newHandler).isNotNull();
    assertThat(newHandler).isSameInstanceAs(mockChannelHandler);
}
Also used : ProtocolNegotiator(io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator) ClientSdsProtocolNegotiator(io.grpc.xds.internal.sds.SdsProtocolNegotiators.ClientSdsProtocolNegotiator) ClientSdsProtocolNegotiator(io.grpc.xds.internal.sds.SdsProtocolNegotiators.ClientSdsProtocolNegotiator) ChannelHandler(io.netty.channel.ChannelHandler) Test(org.junit.Test)

Example 2 with ClientSdsProtocolNegotiator

use of io.grpc.xds.internal.sds.SdsProtocolNegotiators.ClientSdsProtocolNegotiator in project grpc-java by grpc.

the class SdsProtocolNegotiatorsTest method clientSdsProtocolNegotiatorNewHandler_noFallback_expectException.

@Test
public void clientSdsProtocolNegotiatorNewHandler_noFallback_expectException() {
    ClientSdsProtocolNegotiator pn = new ClientSdsProtocolNegotiator(/* fallbackProtocolNegotiator= */
    null);
    try {
        pn.newHandler(grpcHandler);
        fail("exception expected!");
    } catch (NullPointerException expected) {
        assertThat(expected).hasMessageThat().contains("No TLS config and no fallbackProtocolNegotiator!");
    }
}
Also used : ClientSdsProtocolNegotiator(io.grpc.xds.internal.sds.SdsProtocolNegotiators.ClientSdsProtocolNegotiator) Test(org.junit.Test)

Example 3 with ClientSdsProtocolNegotiator

use of io.grpc.xds.internal.sds.SdsProtocolNegotiators.ClientSdsProtocolNegotiator 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)

Aggregations

ClientSdsProtocolNegotiator (io.grpc.xds.internal.sds.SdsProtocolNegotiators.ClientSdsProtocolNegotiator)3 Test (org.junit.Test)3 ChannelHandler (io.netty.channel.ChannelHandler)2 ChannelLogger (io.grpc.ChannelLogger)1 ChannelLogLevel (io.grpc.ChannelLogger.ChannelLogLevel)1 NoopChannelLogger (io.grpc.internal.TestUtils.NoopChannelLogger)1 GrpcHttp2ConnectionHandler (io.grpc.netty.GrpcHttp2ConnectionHandler)1 ProtocolNegotiator (io.grpc.netty.InternalProtocolNegotiator.ProtocolNegotiator)1 UpstreamTlsContext (io.grpc.xds.EnvoyServerProtoData.UpstreamTlsContext)1 TlsContextManager (io.grpc.xds.TlsContextManager)1