Search in sources :

Example 6 with ResolutionResult

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);
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Test(org.junit.Test)

Example 7 with ResolutionResult

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();
}
Also used : ResolutionResult(io.grpc.NameResolver.ResolutionResult) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap)

Example 8 with ResolutionResult

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"));
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) ClientCall(io.grpc.ClientCall) NoopClientCall(io.grpc.internal.NoopClientCall) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Test(org.junit.Test)

Example 9 with ResolutionResult

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"));
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) ClientCall(io.grpc.ClientCall) NoopClientCall(io.grpc.internal.NoopClientCall) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Test(org.junit.Test)

Example 10 with ResolutionResult

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());
}
Also used : HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) ResolutionResult(io.grpc.NameResolver.ResolutionResult) FilterConfig(io.grpc.xds.Filter.FilterConfig) NamedFilterConfig(io.grpc.xds.Filter.NamedFilterConfig) Route(io.grpc.xds.VirtualHost.Route) Test(org.junit.Test)

Aggregations

ResolutionResult (io.grpc.NameResolver.ResolutionResult)32 Test (org.junit.Test)29 InternalConfigSelector (io.grpc.InternalConfigSelector)16 HashPolicy (io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy)11 AddressResolver (io.grpc.internal.DnsNameResolver.AddressResolver)10 ResourceResolver (io.grpc.internal.DnsNameResolver.ResourceResolver)9 InetAddress (java.net.InetAddress)8 InetSocketAddress (java.net.InetSocketAddress)8 ArgumentMatchers.anyString (org.mockito.ArgumentMatchers.anyString)8 ClientCall (io.grpc.ClientCall)7 NoopClientCall (io.grpc.internal.NoopClientCall)7 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)5 UnknownHostException (java.net.UnknownHostException)5 JndiResourceResolver (io.grpc.internal.JndiResourceResolverFactory.JndiResourceResolver)4 IOException (java.io.IOException)4 ImmutableMap (com.google.common.collect.ImmutableMap)3 Route (io.grpc.xds.VirtualHost.Route)3 ArrayList (java.util.ArrayList)3 Map (java.util.Map)3 Result (io.grpc.InternalConfigSelector.Result)2