use of io.grpc.xds.Filter.FilterConfig in project grpc-java by grpc.
the class XdsNameResolverTest method resolving_ldsResourceUpdateRdsName.
@SuppressWarnings("unchecked")
@Test
public void resolving_ldsResourceUpdateRdsName() {
Route route1 = Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forCluster(cluster1, Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(15L), null), ImmutableMap.<String, FilterConfig>of());
Route route2 = Route.forAction(RouteMatch.withPathExactOnly(call2.getFullMethodNameForPath()), RouteAction.forCluster(cluster2, Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(20L), null), ImmutableMap.<String, FilterConfig>of());
resolver.start(mockListener);
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
xdsClient.deliverLdsUpdateForRdsName(RDS_RESOURCE_NAME);
assertThat(xdsClient.rdsResource).isEqualTo(RDS_RESOURCE_NAME);
VirtualHost virtualHost = VirtualHost.create("virtualhost", Collections.singletonList(AUTHORITY), Collections.singletonList(route1), ImmutableMap.<String, FilterConfig>of());
xdsClient.deliverRdsUpdate(RDS_RESOURCE_NAME, Collections.singletonList(virtualHost));
verify(mockListener).onResult(resolutionResultCaptor.capture());
assertServiceConfigForLoadBalancingConfig(Collections.singletonList(cluster1), (Map<String, ?>) resolutionResultCaptor.getValue().getServiceConfig().getConfig());
reset(mockListener);
ArgumentCaptor<ResolutionResult> resultCaptor = ArgumentCaptor.forClass(ResolutionResult.class);
String alternativeRdsResource = "route-configuration-alter.googleapis.com";
xdsClient.deliverLdsUpdateForRdsName(alternativeRdsResource);
assertThat(xdsClient.rdsResource).isEqualTo(alternativeRdsResource);
virtualHost = VirtualHost.create("virtualhost-alter", Collections.singletonList(AUTHORITY), Collections.singletonList(route2), ImmutableMap.<String, FilterConfig>of());
xdsClient.deliverRdsUpdate(alternativeRdsResource, Collections.singletonList(virtualHost));
// Two new service config updates triggered:
// - with load balancing config being able to select cluster1 and cluster2
// - with load balancing config being able to select cluster2 only
verify(mockListener, times(2)).onResult(resultCaptor.capture());
assertServiceConfigForLoadBalancingConfig(Arrays.asList(cluster1, cluster2), (Map<String, ?>) resultCaptor.getAllValues().get(0).getServiceConfig().getConfig());
assertServiceConfigForLoadBalancingConfig(Collections.singletonList(cluster2), (Map<String, ?>) resultCaptor.getValue().getServiceConfig().getConfig());
}
use of io.grpc.xds.Filter.FilterConfig in project grpc-java by grpc.
the class ClientXdsClientDataTest method parseHttpFilter_routerFilterForServer.
@Test
public void parseHttpFilter_routerFilterForServer() {
filterRegistry.register(RouterFilter.INSTANCE);
HttpFilter httpFilter = HttpFilter.newBuilder().setIsOptional(false).setName("envoy.router").setTypedConfig(Any.pack(Router.getDefaultInstance())).build();
FilterConfig config = ClientXdsClient.parseHttpFilter(httpFilter, filterRegistry, false).getStruct();
assertThat(config.typeUrl()).isEqualTo(RouterFilter.TYPE_URL);
}
use of io.grpc.xds.Filter.FilterConfig in project grpc-java by grpc.
the class ClientXdsClientDataTest method parseHttpFilter_faultConfigForClient.
@Test
public void parseHttpFilter_faultConfigForClient() {
filterRegistry.register(FaultFilter.INSTANCE);
HttpFilter httpFilter = HttpFilter.newBuilder().setIsOptional(false).setName("envoy.fault").setTypedConfig(Any.pack(HTTPFault.newBuilder().setDelay(FaultDelay.newBuilder().setFixedDelay(Durations.fromNanos(1234L))).setAbort(FaultAbort.newBuilder().setHttpStatus(300).setPercentage(FractionalPercent.newBuilder().setNumerator(10).setDenominator(DenominatorType.HUNDRED))).build())).build();
FilterConfig config = ClientXdsClient.parseHttpFilter(httpFilter, filterRegistry, true).getStruct();
assertThat(config).isInstanceOf(FaultConfig.class);
}
use of io.grpc.xds.Filter.FilterConfig in project grpc-java by grpc.
the class ClientXdsClientDataTest method parseOverrideRbacFilterConfig.
@Test
public void parseOverrideRbacFilterConfig() {
filterRegistry.register(RbacFilter.INSTANCE);
RBACPerRoute rbacPerRoute = RBACPerRoute.newBuilder().setRbac(io.envoyproxy.envoy.extensions.filters.http.rbac.v3.RBAC.newBuilder().setRules(RBAC.newBuilder().setAction(Action.ALLOW).putPolicies("allow-all", Policy.newBuilder().addPrincipals(Principal.newBuilder().setAny(true)).addPermissions(Permission.newBuilder().setAny(true)).build()))).build();
Map<String, Any> configOverrides = ImmutableMap.of("envoy.auth", Any.pack(rbacPerRoute));
Map<String, FilterConfig> parsedConfigs = ClientXdsClient.parseOverrideFilterConfigs(configOverrides, filterRegistry).getStruct();
assertThat(parsedConfigs).hasSize(1);
assertThat(parsedConfigs).containsKey("envoy.auth");
assertThat(parsedConfigs.get("envoy.auth")).isInstanceOf(RbacConfig.class);
}
use of io.grpc.xds.Filter.FilterConfig in project grpc-java by grpc.
the class ClientXdsClientDataTest method parseOverrideFilterConfigs_unsupportedButOptional.
@Test
public void parseOverrideFilterConfigs_unsupportedButOptional() {
filterRegistry.register(FaultFilter.INSTANCE);
HTTPFault httpFault = HTTPFault.newBuilder().setDelay(FaultDelay.newBuilder().setFixedDelay(Durations.fromNanos(3000))).build();
Map<String, Any> configOverrides = ImmutableMap.of("envoy.fault", Any.pack(httpFault), "unsupported.filter", Any.pack(io.envoyproxy.envoy.config.route.v3.FilterConfig.newBuilder().setIsOptional(true).setConfig(Any.pack(StringValue.of("string value"))).build()));
Map<String, FilterConfig> parsedConfigs = ClientXdsClient.parseOverrideFilterConfigs(configOverrides, filterRegistry).getStruct();
assertThat(parsedConfigs).hasSize(1);
assertThat(parsedConfigs).containsKey("envoy.fault");
}
Aggregations