Search in sources :

Example 21 with InternalConfigSelector

use of io.grpc.InternalConfigSelector in project grpc-java by grpc.

the class XdsNameResolverTest method resolved_faultDelayWithMaxActiveStreamsInLdsUpdate.

@Test
public void resolved_faultDelayWithMaxActiveStreamsInLdsUpdate() {
    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)), null, /* maxActiveFaults= */
    1);
    xdsClient.deliverLdsUpdateWithFaultInjection(cluster1, httpFilterFaultConfig, null, null, null);
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    ResolutionResult result = resolutionResultCaptor.getValue();
    InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
    // Send two calls, then the first call should delayed and the second call should not be delayed
    // because maxActiveFaults is exceeded.
    ClientCall.Listener<Void> observer1 = startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT);
    assertThat(testCall).isNull();
    ClientCall.Listener<Void> observer2 = startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT);
    verifyRpcSucceeded(observer2);
    verifyRpcDelayed(observer1, 5000L);
    // Once all calls are finished, new call should be delayed.
    ClientCall.Listener<Void> observer3 = startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT);
    verifyRpcDelayed(observer3, 5000L);
}
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 22 with InternalConfigSelector

use of io.grpc.InternalConfigSelector in project grpc-java by grpc.

the class XdsNameResolverTest method retryPolicyInPerMethodConfigGeneratedByResolverIsValid.

@Test
public void retryPolicyInPerMethodConfigGeneratedByResolverIsValid() {
    ServiceConfigParser realParser = new ScParser(true, 5, 5, new AutoConfiguredLoadBalancerFactory("pick-first"));
    resolver = new XdsNameResolver(null, AUTHORITY, realParser, syncContext, scheduler, xdsClientPoolFactory, mockRandom, FilterRegistry.getDefaultRegistry(), null);
    resolver.start(mockListener);
    FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
    RetryPolicy retryPolicy = RetryPolicy.create(4, ImmutableList.of(Code.UNAVAILABLE), Durations.fromMillis(100), Durations.fromMillis(200), null);
    xdsClient.deliverLdsUpdate(Collections.singletonList(Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forCluster(cluster1, Collections.<HashPolicy>emptyList(), null, retryPolicy), ImmutableMap.<String, FilterConfig>of())));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    ResolutionResult result = resolutionResultCaptor.getValue();
    InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
    Result selectResult = configSelector.selectConfig(new PickSubchannelArgsImpl(call1.methodDescriptor, new Metadata(), CallOptions.DEFAULT));
    Object config = selectResult.getConfig();
    // Purely validating the data (io.grpc.internal.RetryPolicy).
    // However, there's no public accessor methods the data object.
    assertThat(config.getClass().getName()).isEqualTo("io.grpc.internal.ManagedChannelServiceConfig");
    assertThat(config.toString()).contains(MoreObjects.toStringHelper("RetryPolicy").add("maxAttempts", 4).add("initialBackoffNanos", TimeUnit.MILLISECONDS.toNanos(100)).add("maxBackoffNanos", TimeUnit.MILLISECONDS.toNanos(200)).add("backoffMultiplier", 2D).add("perAttemptRecvTimeoutNanos", null).add("retryableStatusCodes", ImmutableList.of(Code.UNAVAILABLE)).toString());
}
Also used : ResolutionResult(io.grpc.NameResolver.ResolutionResult) Metadata(io.grpc.Metadata) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Result(io.grpc.InternalConfigSelector.Result) AutoConfiguredLoadBalancerFactory(io.grpc.internal.AutoConfiguredLoadBalancerFactory) PickSubchannelArgsImpl(io.grpc.internal.PickSubchannelArgsImpl) ScParser(io.grpc.internal.ScParser) InternalConfigSelector(io.grpc.InternalConfigSelector) HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) ServiceConfigParser(io.grpc.NameResolver.ServiceConfigParser) RetryPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.RetryPolicy) Test(org.junit.Test)

Example 23 with InternalConfigSelector

use of io.grpc.InternalConfigSelector 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);
}
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 24 with InternalConfigSelector

use of io.grpc.InternalConfigSelector in project grpc-java by grpc.

the class XdsNameResolverTest method resolved_raceBetweenClusterReleasedAndResourceUpdateAddBackAgain.

@Test
public void resolved_raceBetweenClusterReleasedAndResourceUpdateAddBackAgain() {
    InternalConfigSelector configSelector = resolveToClusters();
    assertCallSelectClusterResult(call1, configSelector, cluster1, 15.0);
    FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
    xdsClient.deliverLdsUpdate(Collections.singletonList(Route.forAction(RouteMatch.withPathExactOnly(call2.getFullMethodNameForPath()), RouteAction.forCluster(cluster2, Collections.<HashPolicy>emptyList(), TimeUnit.SECONDS.toNanos(15L), null), ImmutableMap.<String, FilterConfig>of())));
    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())));
    testCall.deliverErrorStatus();
    verifyNoMoreInteractions(mockListener);
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) Test(org.junit.Test)

Example 25 with InternalConfigSelector

use of io.grpc.InternalConfigSelector in project grpc-java by grpc.

the class XdsNameResolverTest method resolved_raceBetweenCallAndRepeatedResourceUpdate.

@SuppressWarnings("unchecked")
@Test
public void resolved_raceBetweenCallAndRepeatedResourceUpdate() {
    InternalConfigSelector configSelector = resolveToClusters();
    assertCallSelectClusterResult(call1, configSelector, cluster1, 15.0);
    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();
    assertServiceConfigForLoadBalancingConfig(Arrays.asList(cluster1, cluster2, "another-cluster"), (Map<String, ?>) result.getServiceConfig().getConfig());
    xdsClient.deliverLdsUpdate(Arrays.asList(Route.forAction(RouteMatch.withPathExactOnly(call1.getFullMethodNameForPath()), RouteAction.forCluster("another-cluster", 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())));
    // no cluster added/deleted
    verifyNoMoreInteractions(mockListener);
    assertCallSelectClusterResult(call1, configSelector, "another-cluster", 15.0);
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) HashPolicy(io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Test(org.junit.Test)

Aggregations

InternalConfigSelector (io.grpc.InternalConfigSelector)28 Test (org.junit.Test)28 ResolutionResult (io.grpc.NameResolver.ResolutionResult)17 HashPolicy (io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy)10 ClientCall (io.grpc.ClientCall)7 Metadata (io.grpc.Metadata)7 NoopClientCall (io.grpc.internal.NoopClientCall)7 Status (io.grpc.Status)5 Result (io.grpc.InternalConfigSelector.Result)4 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)3 UnsupportedClientTransportFactoryBuilder (io.grpc.internal.ManagedChannelImplBuilder.UnsupportedClientTransportFactoryBuilder)3 PickSubchannelArgsImpl (io.grpc.internal.PickSubchannelArgsImpl)3 CallOptions (io.grpc.CallOptions)2 Channel (io.grpc.Channel)2 ClientInterceptor (io.grpc.ClientInterceptor)2 ResolvedAddresses (io.grpc.LoadBalancer.ResolvedAddresses)2 MethodDescriptor (io.grpc.MethodDescriptor)2 ConfigSelectingClientCall (io.grpc.internal.ManagedChannelImpl.ConfigSelectingClientCall)2 MethodInfo (io.grpc.internal.ManagedChannelServiceConfig.MethodInfo)2 Route (io.grpc.xds.VirtualHost.Route)2