Search in sources :

Example 6 with HashPolicy

use of io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy in project grpc-java by grpc.

the class XdsNameResolverTest method buildUnmatchedVirtualHosts.

private List<VirtualHost> buildUnmatchedVirtualHosts() {
    Route route1 = Route.forAction(RouteMatch.withPathExactOnly(call2.getFullMethodNameForPath()), RouteAction.forCluster(cluster2, Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(15L), null), ImmutableMap.<String, FilterConfig>of());
    Route route2 = Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forCluster(cluster1, Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(15L), null), ImmutableMap.<String, FilterConfig>of());
    return Arrays.asList(VirtualHost.create("virtualhost-foo", Collections.singletonList("hello.googleapis.com"), Collections.singletonList(route1), ImmutableMap.<String, FilterConfig>of()), VirtualHost.create("virtualhost-bar", Collections.singletonList("hi.googleapis.com"), Collections.singletonList(route2), ImmutableMap.<String, FilterConfig>of()));
}
Also used : HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) FilterConfig(io.grpc.xds.Filter.FilterConfig) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) Route(io.grpc.xds.VirtualHost.Route)

Example 7 with HashPolicy

use of io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy in project grpc-java by grpc.

the class XdsNameResolverTest method resolved_noTimeout.

@Test
public void resolved_noTimeout() {
    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(0L, Collections.singletonList(virtualHost));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    ResolutionResult result = resolutionResultCaptor.getValue();
    InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
    assertCallSelectClusterResult(call1, configSelector, cluster1, null);
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Route(io.grpc.xds.VirtualHost.Route) Test(org.junit.Test)

Example 8 with HashPolicy

use of io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy in project grpc-java by grpc.

the class XdsNameResolverTest method resolving_rdsResourceRevokedAndAddedBack.

@SuppressWarnings("unchecked")
@Test
public void resolving_rdsResourceRevokedAndAddedBack() {
    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 RDS resource
    xdsClient.deliverRdsResourceNotFound(RDS_RESOURCE_NAME);
    assertEmptyResolutionResult();
    // Simulate management server adds back the previously used RDS resource.
    reset(mockListener);
    xdsClient.deliverRdsUpdate(RDS_RESOURCE_NAME, Collections.singletonList(virtualHost));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    assertServiceConfigForLoadBalancingConfig(Collections.singletonList(cluster1), (Map<String, ?>) resolutionResultCaptor.getValue().getServiceConfig().getConfig());
}
Also used : HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) Route(io.grpc.xds.VirtualHost.Route) Test(org.junit.Test)

Example 9 with HashPolicy

use of io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy in project grpc-java by grpc.

the class XdsNameResolverTest method resolved_simpleCallSucceeds_routeToRls.

@Test
public void resolved_simpleCallSucceeds_routeToRls() {
    when(mockRandom.nextInt(anyInt())).thenReturn(90, 10);
    resolver.start(mockListener);
    FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
    xdsClient.deliverLdsUpdate(Collections.singletonList(Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forClusterSpecifierPlugin(NamedPluginConfig.create("rls-plugin-foo", RlsPluginConfig.create(ImmutableMap.of("lookupService", "rls-cbt.googleapis.com"))), Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(20L), null), ImmutableMap.<String, FilterConfig>of())));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    ResolutionResult result = resolutionResultCaptor.getValue();
    assertThat(result.getAddresses()).isEmpty();
    @SuppressWarnings("unchecked") Map<String, ?> resultServiceConfig = (Map<String, ?>) result.getServiceConfig().getConfig();
    List<Map<String, ?>> rawLbConfigs = JsonUtil.getListOfObjects(resultServiceConfig, "loadBalancingConfig");
    Map<String, ?> lbConfig = Iterables.getOnlyElement(rawLbConfigs);
    assertThat(lbConfig.keySet()).containsExactly("cluster_manager_experimental");
    Map<String, ?> clusterManagerLbConfig = JsonUtil.getObject(lbConfig, "cluster_manager_experimental");
    Map<String, ?> expectedRlsLbConfig = ImmutableMap.of("routeLookupConfig", ImmutableMap.of("lookupService", "rls-cbt.googleapis.com"), "childPolicy", ImmutableList.of(ImmutableMap.of("cds_experimental", ImmutableMap.of())), "childPolicyConfigTargetFieldName", "cluster");
    Map<String, ?> expectedClusterManagerLbConfig = ImmutableMap.of("childPolicy", ImmutableMap.of("cluster_specifier_plugin:rls-plugin-foo", ImmutableMap.of("lbPolicy", ImmutableList.of(ImmutableMap.of("rls_experimental", expectedRlsLbConfig)))));
    assertThat(clusterManagerLbConfig).isEqualTo(expectedClusterManagerLbConfig);
    assertThat(result.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL)).isNotNull();
    InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
    assertCallSelectRlsPluginResult(call1, configSelector, "rls-plugin-foo", 20.0);
    // config changed
    xdsClient.deliverLdsUpdate(Collections.singletonList(Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forClusterSpecifierPlugin(NamedPluginConfig.create("rls-plugin-foo", RlsPluginConfig.create(// changed
    ImmutableMap.of("lookupService", "rls-cbt-2.googleapis.com"))), Collections.<HashPolicy>emptyList(), // changed
    TimeUnit.SECONDS.toNanos(30L), null), ImmutableMap.<String, FilterConfig>of())));
    verify(mockListener, times(2)).onResult(resolutionResultCaptor.capture());
    ResolutionResult result2 = resolutionResultCaptor.getValue();
    @SuppressWarnings("unchecked") Map<String, ?> resultServiceConfig2 = (Map<String, ?>) result2.getServiceConfig().getConfig();
    List<Map<String, ?>> rawLbConfigs2 = JsonUtil.getListOfObjects(resultServiceConfig2, "loadBalancingConfig");
    Map<String, ?> lbConfig2 = Iterables.getOnlyElement(rawLbConfigs2);
    assertThat(lbConfig2.keySet()).containsExactly("cluster_manager_experimental");
    Map<String, ?> clusterManagerLbConfig2 = JsonUtil.getObject(lbConfig2, "cluster_manager_experimental");
    Map<String, ?> expectedRlsLbConfig2 = ImmutableMap.of("routeLookupConfig", ImmutableMap.of("lookupService", "rls-cbt-2.googleapis.com"), "childPolicy", ImmutableList.of(ImmutableMap.of("cds_experimental", ImmutableMap.of())), "childPolicyConfigTargetFieldName", "cluster");
    Map<String, ?> expectedClusterManagerLbConfig2 = ImmutableMap.of("childPolicy", ImmutableMap.of("cluster_specifier_plugin:rls-plugin-foo", ImmutableMap.of("lbPolicy", ImmutableList.of(ImmutableMap.of("rls_experimental", expectedRlsLbConfig2)))));
    assertThat(clusterManagerLbConfig2).isEqualTo(expectedClusterManagerLbConfig2);
    InternalConfigSelector configSelector2 = result.getAttributes().get(InternalConfigSelector.KEY);
    assertCallSelectRlsPluginResult(call1, configSelector2, "rls-plugin-foo", 30.0);
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) Test(org.junit.Test)

Example 10 with HashPolicy

use of io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy in project grpc-java by grpc.

the class XdsNameResolverTest method resolved_resourceUpdateAfterCallStarted.

@SuppressWarnings("unchecked")
@Test
public void resolved_resourceUpdateAfterCallStarted() {
    InternalConfigSelector configSelector = resolveToClusters();
    assertCallSelectClusterResult(call1, configSelector, cluster1, 15.0);
    TestCall<?, ?> firstCall = testCall;
    reset(mockListener);
    FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
    xdsClient.deliverLdsUpdate(Arrays.asList(Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forCluster("another-cluster", Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(20L), null), ImmutableMap.<String, FilterConfig>of()), Route.forAction(RouteMatch.withPathExactOnly(call2.getFullMethodNameForPath()), RouteAction.forCluster(cluster2, Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(15L), null), ImmutableMap.<String, FilterConfig>of())));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    ResolutionResult result = resolutionResultCaptor.getValue();
    // Updated service config still contains cluster1 while it is removed resource. New calls no
    // longer routed to cluster1.
    assertServiceConfigForLoadBalancingConfig(Arrays.asList(cluster1, cluster2, "another-cluster"), (Map<String, ?>) result.getServiceConfig().getConfig());
    assertThat(result.getAttributes().get(InternalConfigSelector.KEY)).isSameInstanceAs(configSelector);
    assertCallSelectClusterResult(call1, configSelector, "another-cluster", 20.0);
    // completes previous call
    firstCall.deliverErrorStatus();
    verify(mockListener, times(2)).onResult(resolutionResultCaptor.capture());
    result = resolutionResultCaptor.getValue();
    assertServiceConfigForLoadBalancingConfig(Arrays.asList(cluster2, "another-cluster"), (Map<String, ?>) result.getServiceConfig().getConfig());
    verifyNoMoreInteractions(mockListener);
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Test(org.junit.Test)

Aggregations

HashPolicy (io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy)16 Test (org.junit.Test)13 ResolutionResult (io.grpc.NameResolver.ResolutionResult)11 InternalConfigSelector (io.grpc.InternalConfigSelector)10 Route (io.grpc.xds.VirtualHost.Route)6 FilterConfig (io.grpc.xds.Filter.FilterConfig)3 NamedFilterConfig (io.grpc.xds.Filter.NamedFilterConfig)3 Result (io.grpc.InternalConfigSelector.Result)2 Metadata (io.grpc.Metadata)2 PickSubchannelArgsImpl (io.grpc.internal.PickSubchannelArgsImpl)2 RetryPolicy (io.grpc.xds.VirtualHost.Route.RouteAction.RetryPolicy)2 VisibleForTesting (com.google.common.annotations.VisibleForTesting)1 ImmutableMap (com.google.common.collect.ImmutableMap)1 Pattern (com.google.re2j.Pattern)1 ServiceConfigParser (io.grpc.NameResolver.ServiceConfigParser)1 Status (io.grpc.Status)1 AutoConfiguredLoadBalancerFactory (io.grpc.internal.AutoConfiguredLoadBalancerFactory)1 ScParser (io.grpc.internal.ScParser)1 NamedPluginConfig (io.grpc.xds.ClusterSpecifierPlugin.NamedPluginConfig)1 PluginConfig (io.grpc.xds.ClusterSpecifierPlugin.PluginConfig)1