Search in sources :

Example 1 with SslContextProvider

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

the class XdsClientWrapperForServerSdsTestMisc method releaseOldSupplierOnPermDeniedError_verifyClose.

@Test
public void releaseOldSupplierOnPermDeniedError_verifyClose() throws Exception {
    SslContextProvider sslContextProvider1 = mock(SslContextProvider.class);
    when(tlsContextManager.findOrCreateServerSslContextProvider(eq(tlsContext1))).thenReturn(sslContextProvider1);
    InetAddress ipLocalAddress = InetAddress.getByName("10.1.2.3");
    localAddress = new InetSocketAddress(ipLocalAddress, PORT);
    sendListenerUpdate(localAddress, tlsContext1, null, tlsContextManager);
    SslContextProviderSupplier returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
    assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext1);
    callUpdateSslContext(returnedSupplier);
    xdsClient.ldsWatcher.onError(Status.PERMISSION_DENIED);
    verify(tlsContextManager, times(1)).releaseServerSslContextProvider(eq(sslContextProvider1));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SslContextProvider(io.grpc.xds.internal.sds.SslContextProvider) InetAddress(java.net.InetAddress) SslContextProviderSupplier(io.grpc.xds.internal.sds.SslContextProviderSupplier) Test(org.junit.Test)

Example 2 with SslContextProvider

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

the class XdsClientWrapperForServerSdsTestMisc method releaseOldSupplierOnChangedOnShutdown_verifyClose.

@Test
public void releaseOldSupplierOnChangedOnShutdown_verifyClose() throws Exception {
    SslContextProvider sslContextProvider1 = mock(SslContextProvider.class);
    when(tlsContextManager.findOrCreateServerSslContextProvider(eq(tlsContext1))).thenReturn(sslContextProvider1);
    InetAddress ipLocalAddress = InetAddress.getByName("10.1.2.3");
    localAddress = new InetSocketAddress(ipLocalAddress, PORT);
    sendListenerUpdate(localAddress, tlsContext1, null, tlsContextManager);
    SslContextProviderSupplier returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
    assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext1);
    callUpdateSslContext(returnedSupplier);
    XdsServerTestHelper.generateListenerUpdate(xdsClient, ImmutableList.of(1234), tlsContext2, tlsContext3, tlsContextManager);
    returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
    assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext2);
    verify(tlsContextManager, times(1)).releaseServerSslContextProvider(eq(sslContextProvider1));
    reset(tlsContextManager);
    SslContextProvider sslContextProvider2 = mock(SslContextProvider.class);
    when(tlsContextManager.findOrCreateServerSslContextProvider(eq(tlsContext2))).thenReturn(sslContextProvider2);
    SslContextProvider sslContextProvider3 = mock(SslContextProvider.class);
    when(tlsContextManager.findOrCreateServerSslContextProvider(eq(tlsContext3))).thenReturn(sslContextProvider3);
    callUpdateSslContext(returnedSupplier);
    InetAddress ipRemoteAddress = InetAddress.getByName("10.4.5.6");
    final InetSocketAddress remoteAddress = new InetSocketAddress(ipRemoteAddress, 1111);
    channel = new EmbeddedChannel() {

        @Override
        public SocketAddress localAddress() {
            return localAddress;
        }

        @Override
        public SocketAddress remoteAddress() {
            return remoteAddress;
        }
    };
    pipeline = channel.pipeline();
    returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
    assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext3);
    callUpdateSslContext(returnedSupplier);
    xdsServerWrapper.shutdown();
    assertThat(xdsClient.ldsResource).isNull();
    verify(tlsContextManager, never()).releaseServerSslContextProvider(eq(sslContextProvider1));
    verify(tlsContextManager, times(1)).releaseServerSslContextProvider(eq(sslContextProvider2));
    verify(tlsContextManager, times(1)).releaseServerSslContextProvider(eq(sslContextProvider3));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) EmbeddedChannel(io.netty.channel.embedded.EmbeddedChannel) SslContextProvider(io.grpc.xds.internal.sds.SslContextProvider) SocketAddress(java.net.SocketAddress) InProcessSocketAddress(io.grpc.inprocess.InProcessSocketAddress) InetSocketAddress(java.net.InetSocketAddress) InetAddress(java.net.InetAddress) SslContextProviderSupplier(io.grpc.xds.internal.sds.SslContextProviderSupplier) Test(org.junit.Test)

Example 3 with SslContextProvider

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

the class XdsClientWrapperForServerSdsTestMisc method releaseOldSupplierOnTemporaryError_noClose.

@Test
public void releaseOldSupplierOnTemporaryError_noClose() throws Exception {
    SslContextProvider sslContextProvider1 = mock(SslContextProvider.class);
    when(tlsContextManager.findOrCreateServerSslContextProvider(eq(tlsContext1))).thenReturn(sslContextProvider1);
    InetAddress ipLocalAddress = InetAddress.getByName("10.1.2.3");
    localAddress = new InetSocketAddress(ipLocalAddress, PORT);
    sendListenerUpdate(localAddress, tlsContext1, null, tlsContextManager);
    SslContextProviderSupplier returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
    assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext1);
    callUpdateSslContext(returnedSupplier);
    xdsClient.ldsWatcher.onError(Status.CANCELLED);
    verify(tlsContextManager, never()).releaseServerSslContextProvider(eq(sslContextProvider1));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SslContextProvider(io.grpc.xds.internal.sds.SslContextProvider) InetAddress(java.net.InetAddress) SslContextProviderSupplier(io.grpc.xds.internal.sds.SslContextProviderSupplier) Test(org.junit.Test)

Example 4 with SslContextProvider

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

the class XdsClientWrapperForServerSdsTestMisc method releaseOldSupplierOnNotFound_verifyClose.

@Test
public void releaseOldSupplierOnNotFound_verifyClose() throws Exception {
    SslContextProvider sslContextProvider1 = mock(SslContextProvider.class);
    when(tlsContextManager.findOrCreateServerSslContextProvider(eq(tlsContext1))).thenReturn(sslContextProvider1);
    InetAddress ipLocalAddress = InetAddress.getByName("10.1.2.3");
    localAddress = new InetSocketAddress(ipLocalAddress, PORT);
    sendListenerUpdate(localAddress, tlsContext1, null, tlsContextManager);
    SslContextProviderSupplier returnedSupplier = getSslContextProviderSupplier(selectorManager.getSelectorToUpdateSelector());
    assertThat(returnedSupplier.getTlsContext()).isSameInstanceAs(tlsContext1);
    callUpdateSslContext(returnedSupplier);
    xdsClient.ldsWatcher.onResourceDoesNotExist("not-found Error");
    verify(tlsContextManager, times(1)).releaseServerSslContextProvider(eq(sslContextProvider1));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) SslContextProvider(io.grpc.xds.internal.sds.SslContextProvider) InetAddress(java.net.InetAddress) SslContextProviderSupplier(io.grpc.xds.internal.sds.SslContextProviderSupplier) Test(org.junit.Test)

Aggregations

SslContextProvider (io.grpc.xds.internal.sds.SslContextProvider)4 SslContextProviderSupplier (io.grpc.xds.internal.sds.SslContextProviderSupplier)4 InetAddress (java.net.InetAddress)4 InetSocketAddress (java.net.InetSocketAddress)4 Test (org.junit.Test)4 InProcessSocketAddress (io.grpc.inprocess.InProcessSocketAddress)1 EmbeddedChannel (io.netty.channel.embedded.EmbeddedChannel)1 SocketAddress (java.net.SocketAddress)1