use of io.grpc.xds.VirtualHost.Route in project grpc-java by grpc.
the class XdsNameResolverTest method generateServiceConfig_forClusterManagerLoadBalancingConfig.
@Test
public void generateServiceConfig_forClusterManagerLoadBalancingConfig() throws IOException {
Route route1 = Route.forAction(RouteMatch.withPathExactOnly("HelloService/hi"), RouteAction.forCluster("cluster-foo", Collections.emptyList(), TimeUnit.SECONDS.toNanos(15L), null), ImmutableMap.of());
Route route2 = Route.forAction(RouteMatch.withPathExactOnly("HelloService/hello"), RouteAction.forWeightedClusters(ImmutableList.of(ClusterWeight.create("cluster-bar", 50, ImmutableMap.of()), ClusterWeight.create("cluster-baz", 50, ImmutableMap.of())), ImmutableList.of(), TimeUnit.SECONDS.toNanos(15L), null), ImmutableMap.of());
Map<String, ?> rlsConfig = ImmutableMap.of("lookupService", "rls.bigtable.google.com");
Route route3 = Route.forAction(RouteMatch.withPathExactOnly("HelloService/greetings"), RouteAction.forClusterSpecifierPlugin(NamedPluginConfig.create("plugin-foo", RlsPluginConfig.create(rlsConfig)), Collections.emptyList(), TimeUnit.SECONDS.toNanos(20L), null), ImmutableMap.of());
resolver.start(mockListener);
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
xdsClient.deliverLdsUpdateForRdsName(RDS_RESOURCE_NAME);
VirtualHost virtualHost = VirtualHost.create("virtualhost", Collections.singletonList(AUTHORITY), ImmutableList.of(route1, route2, route3), ImmutableMap.of());
xdsClient.deliverRdsUpdate(RDS_RESOURCE_NAME, Collections.singletonList(virtualHost));
verify(mockListener).onResult(resolutionResultCaptor.capture());
String expectedServiceConfigJson = "{\n" + " \"loadBalancingConfig\": [{\n" + " \"cluster_manager_experimental\": {\n" + " \"childPolicy\": {\n" + " \"cluster:cluster-foo\": {\n" + " \"lbPolicy\": [{\n" + " \"cds_experimental\": {\n" + " \"cluster\": \"cluster-foo\"\n" + " }\n" + " }]\n" + " },\n" + " \"cluster:cluster-bar\": {\n" + " \"lbPolicy\": [{\n" + " \"cds_experimental\": {\n" + " \"cluster\": \"cluster-bar\"\n" + " }\n" + " }]\n" + " },\n" + " \"cluster:cluster-baz\": {\n" + " \"lbPolicy\": [{\n" + " \"cds_experimental\": {\n" + " \"cluster\": \"cluster-baz\"\n" + " }\n" + " }]\n" + " },\n" + " \"cluster_specifier_plugin:plugin-foo\": {\n" + " \"lbPolicy\": [{\n" + " \"rls_experimental\": {\n" + " \"routeLookupConfig\": {\n" + " \"lookupService\": \"rls.bigtable.google.com\"\n" + " },\n" + " \"childPolicy\": [\n" + " {\"cds_experimental\": {}}\n" + " ],\n" + " \"childPolicyConfigTargetFieldName\": \"cluster\"\n" + " }\n" + " }]\n" + " }\n" + " }\n" + " }\n" + " }]\n" + "}";
assertThat(resolutionResultCaptor.getValue().getServiceConfig().getConfig()).isEqualTo(JsonParser.parse(expectedServiceConfigJson));
}
use of io.grpc.xds.VirtualHost.Route in project grpc-java by grpc.
the class XdsNameResolverTest method resolved_fallbackToHttpMaxStreamDurationAsTimeout.
@Test
public void resolved_fallbackToHttpMaxStreamDurationAsTimeout() {
resolver.start(mockListener);
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
Route route = Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forCluster(cluster1, Collections.<HashPolicy>emptyList(), null, // per-route timeout unset
null), ImmutableMap.<String, FilterConfig>of());
VirtualHost virtualHost = VirtualHost.create("does not matter", Collections.singletonList(AUTHORITY), Collections.singletonList(route), ImmutableMap.<String, FilterConfig>of());
xdsClient.deliverLdsUpdate(TimeUnit.SECONDS.toNanos(5L), Collections.singletonList(virtualHost));
verify(mockListener).onResult(resolutionResultCaptor.capture());
ResolutionResult result = resolutionResultCaptor.getValue();
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
assertCallSelectClusterResult(call1, configSelector, cluster1, 5.0);
}
use of io.grpc.xds.VirtualHost.Route in project grpc-java by grpc.
the class XdsNameResolverTest method resolving_ldsResourceRevokedAndAddedBack.
@SuppressWarnings("unchecked")
@Test
public void resolving_ldsResourceRevokedAndAddedBack() {
Route route = Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forCluster(cluster1, Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(15L), 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(route), 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);
// revoke LDS resource
xdsClient.deliverLdsResourceNotFound();
// stop subscribing to stale RDS resource
assertThat(xdsClient.rdsResource).isNull();
assertEmptyResolutionResult();
reset(mockListener);
xdsClient.deliverLdsUpdateForRdsName(RDS_RESOURCE_NAME);
// No name resolution result until new RDS resource update is received. Do not use stale config
verifyNoInteractions(mockListener);
assertThat(xdsClient.rdsResource).isEqualTo(RDS_RESOURCE_NAME);
xdsClient.deliverRdsUpdate(RDS_RESOURCE_NAME, Collections.singletonList(virtualHost));
verify(mockListener).onResult(resolutionResultCaptor.capture());
assertServiceConfigForLoadBalancingConfig(Collections.singletonList(cluster1), (Map<String, ?>) resolutionResultCaptor.getValue().getServiceConfig().getConfig());
}
use of io.grpc.xds.VirtualHost.Route 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;
}
Aggregations