use of io.grpc.NameResolver.ResolutionResult 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.NameResolver.ResolutionResult in project grpc-java by grpc.
the class XdsNameResolverTest method assertEmptyResolutionResult.
@SuppressWarnings("unchecked")
private void assertEmptyResolutionResult() {
verify(mockListener).onResult(resolutionResultCaptor.capture());
ResolutionResult result = resolutionResultCaptor.getValue();
assertThat(result.getAddresses()).isEmpty();
assertThat((Map<String, ?>) result.getServiceConfig().getConfig()).isEmpty();
}
use of io.grpc.NameResolver.ResolutionResult in project grpc-java by grpc.
the class XdsNameResolverTest method resolved_faultConfigOverrideInLdsAndInRdsUpdate.
@Test
public void resolved_faultConfigOverrideInLdsAndInRdsUpdate() {
resolver.start(mockListener);
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
// 50%
when(mockRandom.nextInt(1000_000)).thenReturn(500_000);
FaultConfig httpFilterFaultConfig = FaultConfig.create(null, FaultAbort.forStatus(Status.UNAUTHENTICATED, FaultConfig.FractionalPercent.perMillion(1000_000)), null);
xdsClient.deliverLdsUpdateForRdsNameWithFaultInjection(RDS_RESOURCE_NAME, httpFilterFaultConfig);
// Route fault config override
FaultConfig routeFaultConfig = FaultConfig.create(null, FaultAbort.forStatus(Status.UNKNOWN, FaultConfig.FractionalPercent.perMillion(1000_000)), null);
xdsClient.deliverRdsUpdateWithFaultInjection(RDS_RESOURCE_NAME, null, routeFaultConfig, null);
verify(mockListener).onResult(resolutionResultCaptor.capture());
ResolutionResult result = resolutionResultCaptor.getValue();
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
ClientCall.Listener<Void> observer = startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT);
;
verifyRpcFailed(observer, Status.UNKNOWN.withDescription("RPC terminated due to fault injection"));
}
use of io.grpc.NameResolver.ResolutionResult in project grpc-java by grpc.
the class XdsNameResolverTest method resolved_faultAbortAndDelayInLdsUpdateInLdsUpdate.
@Test
public void resolved_faultAbortAndDelayInLdsUpdateInLdsUpdate() {
resolver.start(mockListener);
FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
// 50%
when(mockRandom.nextInt(1000_000)).thenReturn(500_000);
FaultConfig httpFilterFaultConfig = FaultConfig.create(FaultDelay.forFixedDelay(5000L, FaultConfig.FractionalPercent.perMillion(1000_000)), FaultAbort.forStatus(Status.UNAUTHENTICATED.withDescription("unauthenticated"), FaultConfig.FractionalPercent.perMillion(1000_000)), null);
xdsClient.deliverLdsUpdateWithFaultInjection(cluster1, httpFilterFaultConfig, null, null, null);
verify(mockListener).onResult(resolutionResultCaptor.capture());
ResolutionResult result = resolutionResultCaptor.getValue();
InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
ClientCall.Listener<Void> observer = startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT);
verifyRpcDelayedThenAborted(observer, 5000L, Status.UNAUTHENTICATED.withDescription("RPC terminated due to fault injection: unauthenticated"));
}
use of io.grpc.NameResolver.ResolutionResult 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