use of io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy in project grpc-java by grpc.
the class XdsNameResolverTest method resolved_simpleCallSucceeds_routeToWeightedCluster.
@SuppressWarnings("unchecked")
@Test
public void resolved_simpleCallSucceeds_routeToWeightedCluster() {
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.forWeightedClusters(Arrays.asList(ClusterWeight.create(cluster1, 20, ImmutableMap.<String, FilterConfig>of()), ClusterWeight.create(cluster2, 80, ImmutableMap.<String, FilterConfig>of())), 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();
assertServiceConfigForLoadBalancingConfig(Arrays.asList(cluster1, cluster2), (Map<String, ?>) result.getServiceConfig().getConfig());
assertThat(result.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL)).isNotNull();
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
assertCallSelectClusterResult(call1, configSelector, cluster2, 20.0);
assertCallSelectClusterResult(call1, configSelector, cluster1, 20.0);
}
use of io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy in project grpc-java by grpc.
the class XdsNameResolverTest method resolved_simpleCallFailedToRoute_routeWithNonForwardingAction.
@SuppressWarnings("unchecked")
@Test
public void resolved_simpleCallFailedToRoute_routeWithNonForwardingAction() {
resolver.start(mockListener);
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
xdsClient.deliverLdsUpdate(Arrays.asList(Route.forNonForwardingAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), 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();
assertThat(result.getAddresses()).isEmpty();
assertServiceConfigForLoadBalancingConfig(Collections.singletonList(cluster2), (Map<String, ?>) result.getServiceConfig().getConfig());
assertThat(result.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL)).isNotNull();
assertThat(result.getAttributes().get(InternalXdsAttributes.CALL_COUNTER_PROVIDER)).isNotNull();
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
// Simulates making a call1 RPC.
Result selectResult = configSelector.selectConfig(new PickSubchannelArgsImpl(call1.methodDescriptor, new Metadata(), CallOptions.DEFAULT));
Status status = selectResult.getStatus();
assertThat(status.isOk()).isFalse();
assertThat(status.getCode()).isEqualTo(Code.UNAVAILABLE);
assertThat(status.getDescription()).isEqualTo("Could not route RPC to Route with non-forwarding action");
verifyNoMoreInteractions(mockListener);
}
use of io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy in project grpc-java by grpc.
the class XdsNameResolverTest method resolveToClusters.
@SuppressWarnings("unchecked")
private InternalConfigSelector resolveToClusters() {
resolver.start(mockListener);
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
xdsClient.deliverLdsUpdate(Arrays.asList(Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forCluster(cluster1, Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(15L), 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();
assertThat(result.getAddresses()).isEmpty();
assertServiceConfigForLoadBalancingConfig(Arrays.asList(cluster1, cluster2), (Map<String, ?>) result.getServiceConfig().getConfig());
assertThat(result.getAttributes().get(InternalXdsAttributes.XDS_CLIENT_POOL)).isNotNull();
assertThat(result.getAttributes().get(InternalXdsAttributes.CALL_COUNTER_PROVIDER)).isNotNull();
return result.getAttributes().get(InternalConfigSelector.KEY);
}
use of io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy in project grpc-java by grpc.
the class XdsNameResolverTest method resolved_resourceUpdatedBeforeCallStarted.
@SuppressWarnings("unchecked")
@Test
public void resolved_resourceUpdatedBeforeCallStarted() {
InternalConfigSelector configSelector = resolveToClusters();
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())));
// Two consecutive service config updates: one for removing clcuster1,
// one for adding "another=cluster".
verify(mockListener, times(2)).onResult(resolutionResultCaptor.capture());
ResolutionResult result = resolutionResultCaptor.getValue();
assertServiceConfigForLoadBalancingConfig(Arrays.asList(cluster2, "another-cluster"), (Map<String, ?>) result.getServiceConfig().getConfig());
assertThat(result.getAttributes().get(InternalConfigSelector.KEY)).isSameInstanceAs(configSelector);
assertCallSelectClusterResult(call1, configSelector, "another-cluster", 20.0);
verifyNoMoreInteractions(mockListener);
}
use of io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy 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());
}
Aggregations