Search in sources :

Example 6 with NamedFilterConfig

use of io.grpc.xds.Filter.NamedFilterConfig in project grpc-java by grpc.

the class XdsServerWrapperTest method shutdown_inflight.

@Test
public void shutdown_inflight() throws Exception {
    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);
            }
        }
    });
    String ldsWatched = xdsClient.ldsResource.get(5, TimeUnit.SECONDS);
    assertThat(ldsWatched).isEqualTo("grpc/server?udpa.resource.listening_address=0.0.0.0:1");
    HttpConnectionManager hcmVirtual = HttpConnectionManager.forVirtualHosts(0L, Collections.singletonList(createVirtualHost("virtual-host-0")), new ArrayList<NamedFilterConfig>());
    FilterChain f0 = createFilterChain("filter-chain-0", createRds("rds"));
    FilterChain f1 = createFilterChain("filter-chain-1", hcmVirtual);
    xdsClient.deliverLdsUpdate(Collections.singletonList(f0), f1);
    xdsServerWrapper.shutdown();
    when(mockServer.isTerminated()).thenReturn(true);
    when(mockServer.awaitTermination(anyLong(), any(TimeUnit.class))).thenReturn(true);
    assertThat(xdsServerWrapper.awaitTermination(5, TimeUnit.SECONDS)).isTrue();
    xdsServerWrapper.awaitTermination();
    assertThat(xdsServerWrapper.isTerminated()).isTrue();
    verify(mockServer, never()).start();
    assertThat(xdsServerWrapper.isShutdown()).isTrue();
    assertThat(xdsClient.ldsResource).isNull();
    assertThat(xdsClient.shutdown).isTrue();
    verify(mockServer).shutdown();
    assertThat(f0.sslContextProviderSupplier().isShutdown()).isTrue();
    assertThat(f1.sslContextProviderSupplier().isShutdown()).isTrue();
    // shall we set initialStatus when shutdown?
    assertThat(start.isDone()).isFalse();
}
Also used : NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) Server(io.grpc.Server) FilterChain(io.grpc.xds.EnvoyServerProtoData.FilterChain) TimeUnit(java.util.concurrent.TimeUnit) TimeoutException(java.util.concurrent.TimeoutException) StatusException(io.grpc.StatusException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) Test(org.junit.Test)

Example 7 with NamedFilterConfig

use of io.grpc.xds.Filter.NamedFilterConfig in project grpc-java by grpc.

the class XdsServerWrapperTest method discoverState_rds.

@Test
public void discoverState_rds() throws Exception {
    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);
            }
        }
    });
    String ldsWatched = xdsClient.ldsResource.get(5, TimeUnit.SECONDS);
    assertThat(ldsWatched).isEqualTo("grpc/server?udpa.resource.listening_address=0.0.0.0:1");
    VirtualHost virtualHost = createVirtualHost("virtual-host-0");
    HttpConnectionManager hcmVirtual = HttpConnectionManager.forVirtualHosts(0L, Collections.singletonList(virtualHost), new ArrayList<NamedFilterConfig>());
    EnvoyServerProtoData.FilterChain f0 = createFilterChain("filter-chain-0", hcmVirtual);
    EnvoyServerProtoData.FilterChain f1 = createFilterChain("filter-chain-1", createRds("r0"));
    xdsClient.rdsCount = new CountDownLatch(3);
    xdsClient.deliverLdsUpdate(Arrays.asList(f0, f1), null);
    assertThat(start.isDone()).isFalse();
    assertThat(selectorManager.getSelectorToUpdateSelector()).isNull();
    verify(mockServer, never()).start();
    verify(listener, never()).onServing();
    EnvoyServerProtoData.FilterChain f2 = createFilterChain("filter-chain-2", createRds("r1"));
    EnvoyServerProtoData.FilterChain f3 = createFilterChain("filter-chain-3", createRds("r2"));
    xdsClient.deliverLdsUpdate(Arrays.asList(f0, f2), f3);
    verify(mockServer, never()).start();
    verify(listener, never()).onServing();
    xdsClient.rdsCount.await(5, TimeUnit.SECONDS);
    xdsClient.deliverRdsUpdate("r1", Collections.singletonList(createVirtualHost("virtual-host-1")));
    verify(mockServer, never()).start();
    xdsClient.deliverRdsUpdate("r2", Collections.singletonList(createVirtualHost("virtual-host-2")));
    start.get(5000, TimeUnit.MILLISECONDS);
    verify(mockServer).start();
    ServerRoutingConfig realConfig = selectorManager.getSelectorToUpdateSelector().getRoutingConfigs().get(f0).get();
    assertThat(realConfig.virtualHosts()).isEqualTo(Collections.singletonList(createVirtualHost("virtual-host-0")));
    assertThat(realConfig.interceptors()).isEqualTo(ImmutableMap.of());
    assertThat(selectorManager.getSelectorToUpdateSelector().getRoutingConfigs().size()).isEqualTo(2);
    realConfig = selectorManager.getSelectorToUpdateSelector().getRoutingConfigs().get(f2).get();
    assertThat(realConfig.virtualHosts()).isEqualTo(Collections.singletonList(createVirtualHost("virtual-host-1")));
    assertThat(realConfig.interceptors()).isEqualTo(ImmutableMap.of());
    realConfig = selectorManager.getSelectorToUpdateSelector().getDefaultRoutingConfig().get();
    assertThat(realConfig.virtualHosts()).isEqualTo(Collections.singletonList(createVirtualHost("virtual-host-2")));
    assertThat(selectorManager.getSelectorToUpdateSelector().getDefaultSslContextProviderSupplier()).isEqualTo(f3.sslContextProviderSupplier());
}
Also used : ServerRoutingConfig(io.grpc.xds.XdsServerWrapper.ServerRoutingConfig) Server(io.grpc.Server) CountDownLatch(java.util.concurrent.CountDownLatch) TimeoutException(java.util.concurrent.TimeoutException) StatusException(io.grpc.StatusException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) FilterChain(io.grpc.xds.EnvoyServerProtoData.FilterChain) Test(org.junit.Test)

Example 8 with NamedFilterConfig

use of io.grpc.xds.Filter.NamedFilterConfig in project grpc-java by grpc.

the class XdsServerWrapperTest method buildInterceptor_inline.

@Test
@SuppressWarnings("unchecked")
public void buildInterceptor_inline() throws Exception {
    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);
            }
        }
    });
    xdsClient.ldsResource.get(5, TimeUnit.SECONDS);
    RouteMatch routeMatch = RouteMatch.create(PathMatcher.fromPath("/FooService/barMethod", true), Collections.<HeaderMatcher>emptyList(), null);
    Filter filter = mock(Filter.class, withSettings().extraInterfaces(ServerInterceptorBuilder.class));
    when(filter.typeUrls()).thenReturn(new String[] { "filter-type-url" });
    filterRegistry.register(filter);
    FilterConfig f0 = mock(FilterConfig.class);
    FilterConfig f0Override = mock(FilterConfig.class);
    when(f0.typeUrl()).thenReturn("filter-type-url");
    final List<Integer> interceptorTrace = new ArrayList<>();
    ServerInterceptor interceptor0 = new ServerInterceptor() {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
            interceptorTrace.add(0);
            return next.startCall(call, headers);
        }
    };
    ServerInterceptor interceptor1 = new ServerInterceptor() {

        @Override
        public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
            interceptorTrace.add(1);
            return next.startCall(call, headers);
        }
    };
    when(((ServerInterceptorBuilder) filter).buildServerInterceptor(f0, null)).thenReturn(interceptor0);
    when(((ServerInterceptorBuilder) filter).buildServerInterceptor(f0, f0Override)).thenReturn(interceptor1);
    Route route = Route.forAction(routeMatch, null, ImmutableMap.<String, FilterConfig>of());
    VirtualHost virtualHost = VirtualHost.create("v1", Collections.singletonList("foo.google.com"), Arrays.asList(route), ImmutableMap.of("filter-config-name-0", f0Override));
    HttpConnectionManager hcmVirtual = HttpConnectionManager.forVirtualHosts(0L, Collections.singletonList(virtualHost), Arrays.asList(new NamedFilterConfig("filter-config-name-0", f0), new NamedFilterConfig("filter-config-name-1", f0)));
    EnvoyServerProtoData.FilterChain filterChain = createFilterChain("filter-chain-0", hcmVirtual);
    xdsClient.deliverLdsUpdate(Collections.singletonList(filterChain), null);
    start.get(5000, TimeUnit.MILLISECONDS);
    verify(mockServer).start();
    assertThat(selectorManager.getSelectorToUpdateSelector().getRoutingConfigs().size()).isEqualTo(1);
    ServerInterceptor realInterceptor = selectorManager.getSelectorToUpdateSelector().getRoutingConfigs().get(filterChain).get().interceptors().get(route);
    assertThat(realInterceptor).isNotNull();
    ServerCall<Void, Void> serverCall = mock(ServerCall.class);
    ServerCallHandler<Void, Void> mockNext = mock(ServerCallHandler.class);
    final ServerCall.Listener<Void> listener = new ServerCall.Listener<Void>() {
    };
    when(mockNext.startCall(any(ServerCall.class), any(Metadata.class))).thenReturn(listener);
    realInterceptor.interceptCall(serverCall, new Metadata(), mockNext);
    assertThat(interceptorTrace).isEqualTo(Arrays.asList(1, 0));
    verify(mockNext).startCall(eq(serverCall), any(Metadata.class));
}
Also used : XdsServingStatusListener(io.grpc.xds.XdsServerBuilder.XdsServingStatusListener) Server(io.grpc.Server) ServerCallHandler(io.grpc.ServerCallHandler) ArrayList(java.util.ArrayList) Metadata(io.grpc.Metadata) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) ServerCall(io.grpc.ServerCall) FilterConfig(io.grpc.xds.Filter.FilterConfig) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) ServerInterceptorBuilder(io.grpc.xds.Filter.ServerInterceptorBuilder) Route(io.grpc.xds.VirtualHost.Route) TimeoutException(java.util.concurrent.TimeoutException) StatusException(io.grpc.StatusException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException) RouteMatch(io.grpc.xds.VirtualHost.Route.RouteMatch) ServerInterceptor(io.grpc.ServerInterceptor) FilterChain(io.grpc.xds.EnvoyServerProtoData.FilterChain) Test(org.junit.Test)

Example 9 with NamedFilterConfig

use of io.grpc.xds.Filter.NamedFilterConfig in project grpc-java by grpc.

the class XdsSdsClientServerTest method buildListener.

static EnvoyServerProtoData.Listener buildListener(String name, String address, DownstreamTlsContext tlsContext, TlsContextManager tlsContextManager) {
    EnvoyServerProtoData.FilterChainMatch filterChainMatch = EnvoyServerProtoData.FilterChainMatch.create(0, ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ConnectionSourceType.ANY, ImmutableList.of(), ImmutableList.of(), "");
    String fullPath = "/" + SimpleServiceGrpc.SERVICE_NAME + "/" + "UnaryRpc";
    RouteMatch routeMatch = RouteMatch.create(PathMatcher.fromPath(fullPath, true), Collections.<HeaderMatcher>emptyList(), null);
    VirtualHost virtualHost = VirtualHost.create("virtual-host", Collections.singletonList(OVERRIDE_AUTHORITY), Arrays.asList(Route.forAction(routeMatch, null, ImmutableMap.<String, FilterConfig>of())), ImmutableMap.<String, FilterConfig>of());
    HttpConnectionManager httpConnectionManager = HttpConnectionManager.forVirtualHosts(0L, Collections.singletonList(virtualHost), new ArrayList<NamedFilterConfig>());
    EnvoyServerProtoData.FilterChain defaultFilterChain = EnvoyServerProtoData.FilterChain.create("filter-chain-foo", filterChainMatch, httpConnectionManager, tlsContext, tlsContextManager);
    EnvoyServerProtoData.Listener listener = EnvoyServerProtoData.Listener.create(name, address, ImmutableList.of(defaultFilterChain), null);
    return listener;
}
Also used : NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) RouteMatch(io.grpc.xds.VirtualHost.Route.RouteMatch)

Example 10 with NamedFilterConfig

use of io.grpc.xds.Filter.NamedFilterConfig in project grpc-java by grpc.

the class XdsServerTestHelper method buildTestListener.

static EnvoyServerProtoData.Listener buildTestListener(String name, String address, ImmutableList<Integer> sourcePorts, EnvoyServerProtoData.DownstreamTlsContext tlsContext, EnvoyServerProtoData.DownstreamTlsContext tlsContextForDefaultFilterChain, TlsContextManager tlsContextManager) {
    EnvoyServerProtoData.FilterChainMatch filterChainMatch1 = EnvoyServerProtoData.FilterChainMatch.create(0, ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ConnectionSourceType.ANY, sourcePorts, ImmutableList.of(), "");
    EnvoyServerProtoData.FilterChainMatch defaultFilterChainMatch = EnvoyServerProtoData.FilterChainMatch.create(0, ImmutableList.of(), ImmutableList.of(), ImmutableList.of(), ConnectionSourceType.ANY, ImmutableList.of(), ImmutableList.of(), "");
    VirtualHost virtualHost = VirtualHost.create("virtual-host", Collections.singletonList("auth"), new ArrayList<Route>(), ImmutableMap.<String, FilterConfig>of());
    HttpConnectionManager httpConnectionManager = HttpConnectionManager.forVirtualHosts(0L, Collections.singletonList(virtualHost), new ArrayList<NamedFilterConfig>());
    EnvoyServerProtoData.FilterChain filterChain1 = EnvoyServerProtoData.FilterChain.create("filter-chain-foo", filterChainMatch1, httpConnectionManager, tlsContext, tlsContextManager);
    EnvoyServerProtoData.FilterChain defaultFilterChain = EnvoyServerProtoData.FilterChain.create("filter-chain-bar", defaultFilterChainMatch, httpConnectionManager, tlsContextForDefaultFilterChain, tlsContextManager);
    EnvoyServerProtoData.Listener listener = EnvoyServerProtoData.Listener.create(name, address, ImmutableList.of(filterChain1), defaultFilterChain);
    return listener;
}
Also used : NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) FilterChain(io.grpc.xds.EnvoyServerProtoData.FilterChain) Listener(io.grpc.xds.EnvoyServerProtoData.Listener) Route(io.grpc.xds.VirtualHost.Route)

Aggregations

NamedFilterConfig (io.grpc.xds.Filter.NamedFilterConfig)10 FilterChain (io.grpc.xds.EnvoyServerProtoData.FilterChain)8 Server (io.grpc.Server)7 StatusException (io.grpc.StatusException)7 IOException (java.io.IOException)7 ExecutionException (java.util.concurrent.ExecutionException)7 TimeoutException (java.util.concurrent.TimeoutException)7 Test (org.junit.Test)7 Route (io.grpc.xds.VirtualHost.Route)4 FilterConfig (io.grpc.xds.Filter.FilterConfig)3 RouteMatch (io.grpc.xds.VirtualHost.Route.RouteMatch)3 ServerRoutingConfig (io.grpc.xds.XdsServerWrapper.ServerRoutingConfig)3 Metadata (io.grpc.Metadata)2 ServerCall (io.grpc.ServerCall)2 ServerCallHandler (io.grpc.ServerCallHandler)2 ServerInterceptor (io.grpc.ServerInterceptor)2 ServerInterceptorBuilder (io.grpc.xds.Filter.ServerInterceptorBuilder)2 XdsServingStatusListener (io.grpc.xds.XdsServerBuilder.XdsServingStatusListener)2 ArrayList (java.util.ArrayList)2 TimeUnit (java.util.concurrent.TimeUnit)2