Search in sources :

Example 1 with FakeXdsClientPoolFactory

use of io.grpc.xds.XdsServerTestHelper.FakeXdsClientPoolFactory in project grpc-java by grpc.

the class XdsServerWrapperTest method testBootstrap_templateWithXdstp.

@Test
public void testBootstrap_templateWithXdstp() throws Exception {
    Bootstrapper.BootstrapInfo b = Bootstrapper.BootstrapInfo.builder().servers(Arrays.asList(Bootstrapper.ServerInfo.create("uri", InsecureChannelCredentials.create(), true))).node(EnvoyProtoData.Node.newBuilder().setId("id").build()).serverListenerResourceNameTemplate("xdstp://xds.authority.com/envoy.config.listener.v3.Listener/grpc/server/%s").build();
    XdsClient xdsClient = mock(XdsClient.class);
    when(xdsClient.getBootstrapInfo()).thenReturn(b);
    xdsServerWrapper = new XdsServerWrapper("[::FFFF:129.144.52.38]:80", mockBuilder, listener, selectorManager, new FakeXdsClientPoolFactory(xdsClient), filterRegistry);
    Executors.newSingleThreadExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                xdsServerWrapper.start();
            } catch (IOException ex) {
            // ignore
            }
        }
    });
    verify(xdsClient, timeout(5000)).watchLdsResource(eq("xdstp://xds.authority.com/envoy.config.listener.v3.Listener/grpc/server/" + "%5B::FFFF:129.144.52.38%5D:80"), any(LdsResourceWatcher.class));
}
Also used : FakeXdsClient(io.grpc.xds.XdsServerTestHelper.FakeXdsClient) FakeXdsClientPoolFactory(io.grpc.xds.XdsServerTestHelper.FakeXdsClientPoolFactory) IOException(java.io.IOException) LdsResourceWatcher(io.grpc.xds.XdsClient.LdsResourceWatcher) Test(org.junit.Test)

Example 2 with FakeXdsClientPoolFactory

use of io.grpc.xds.XdsServerTestHelper.FakeXdsClientPoolFactory in project grpc-java by grpc.

the class XdsServerWrapperTest method verifyBootstrapFail.

private void verifyBootstrapFail(Bootstrapper.BootstrapInfo b) throws Exception {
    XdsClient xdsClient = mock(XdsClient.class);
    when(xdsClient.getBootstrapInfo()).thenReturn(b);
    xdsServerWrapper = new XdsServerWrapper("0.0.0.0:1", mockBuilder, listener, selectorManager, new FakeXdsClientPoolFactory(xdsClient), filterRegistry);
    final SettableFuture<Server> start = SettableFuture.create();
    Executors.newSingleThreadExecutor().execute(new Runnable() {

        @Override
        public void run() {
            try {
                start.set(xdsServerWrapper.start());
            } catch (Exception ex) {
                start.setException(ex);
            }
        }
    });
    try {
        start.get(5000, TimeUnit.MILLISECONDS);
        fail("Start should throw exception");
    } catch (ExecutionException ex) {
        assertThat(ex.getCause()).isInstanceOf(IOException.class);
        Throwable cause = ex.getCause().getCause();
        assertThat(cause).isInstanceOf(StatusException.class);
        assertThat(((StatusException) cause).getStatus().getCode()).isEqualTo(Status.UNAVAILABLE.getCode());
    }
}
Also used : StatusException(io.grpc.StatusException) FakeXdsClient(io.grpc.xds.XdsServerTestHelper.FakeXdsClient) Server(io.grpc.Server) FakeXdsClientPoolFactory(io.grpc.xds.XdsServerTestHelper.FakeXdsClientPoolFactory) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) TimeoutException(java.util.concurrent.TimeoutException) StatusException(io.grpc.StatusException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Aggregations

FakeXdsClient (io.grpc.xds.XdsServerTestHelper.FakeXdsClient)2 FakeXdsClientPoolFactory (io.grpc.xds.XdsServerTestHelper.FakeXdsClientPoolFactory)2 IOException (java.io.IOException)2 Server (io.grpc.Server)1 StatusException (io.grpc.StatusException)1 LdsResourceWatcher (io.grpc.xds.XdsClient.LdsResourceWatcher)1 ExecutionException (java.util.concurrent.ExecutionException)1 TimeoutException (java.util.concurrent.TimeoutException)1 Test (org.junit.Test)1