Search in sources :

Example 6 with InternalConfigSelector

use of io.grpc.InternalConfigSelector 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 InternalConfigSelector

use of io.grpc.InternalConfigSelector 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 8 with InternalConfigSelector

use of io.grpc.InternalConfigSelector 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 9 with InternalConfigSelector

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

the class XdsNameResolverTest method resolved_rpcHashingByChannelId.

@Test
public void resolved_rpcHashingByChannelId() {
    resolver.start(mockListener);
    FakeXdsClient xdsClient = (FakeXdsClient) resolver.getXdsClient();
    xdsClient.deliverLdsUpdate(Collections.singletonList(Route.forAction(RouteMatch.withPathExactOnly("/" + TestMethodDescriptors.voidMethod().getFullMethodName()), RouteAction.forCluster(cluster1, Collections.singletonList(HashPolicy.forChannelId(false)), null, null), ImmutableMap.<String, FilterConfig>of())));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    InternalConfigSelector configSelector = resolutionResultCaptor.getValue().getAttributes().get(InternalConfigSelector.KEY);
    // First call, with header "custom-key": "value1".
    startNewCall(TestMethodDescriptors.voidMethod(), configSelector, ImmutableMap.of("custom-key", "value1"), CallOptions.DEFAULT);
    long hash1 = testCall.callOptions.getOption(XdsNameResolver.RPC_HASH_KEY);
    // Second call, with no custom header.
    startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT);
    long hash2 = testCall.callOptions.getOption(XdsNameResolver.RPC_HASH_KEY);
    // A different resolver/Channel.
    resolver.shutdown();
    reset(mockListener);
    resolver = new XdsNameResolver(null, AUTHORITY, serviceConfigParser, syncContext, scheduler, xdsClientPoolFactory, mockRandom, FilterRegistry.getDefaultRegistry(), null);
    resolver.start(mockListener);
    xdsClient = (FakeXdsClient) resolver.getXdsClient();
    xdsClient.deliverLdsUpdate(Collections.singletonList(Route.forAction(RouteMatch.withPathExactOnly("/" + TestMethodDescriptors.voidMethod().getFullMethodName()), RouteAction.forCluster(cluster1, Collections.singletonList(HashPolicy.forChannelId(false)), null, null), ImmutableMap.<String, FilterConfig>of())));
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    configSelector = resolutionResultCaptor.getValue().getAttributes().get(InternalConfigSelector.KEY);
    // Third call, with no custom header.
    startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT);
    long hash3 = testCall.callOptions.getOption(XdsNameResolver.RPC_HASH_KEY);
    assertThat(hash2).isEqualTo(hash1);
    assertThat(hash3).isNotEqualTo(hash1);
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) Test(org.junit.Test)

Example 10 with InternalConfigSelector

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

the class XdsNameResolverTest method resolved_faultDelayInLdsUpdate_callWithEarlyDeadline.

@Test
public void resolved_faultDelayInLdsUpdate_callWithEarlyDeadline() {
    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, null);
    xdsClient.deliverLdsUpdateWithFaultInjection(cluster1, httpFilterFaultConfig, null, null, null);
    verify(mockListener).onResult(resolutionResultCaptor.capture());
    ResolutionResult result = resolutionResultCaptor.getValue();
    InternalConfigSelector configSelector = result.getAttributes().get(InternalConfigSelector.KEY);
    Deadline.Ticker fakeTicker = new Deadline.Ticker() {

        @Override
        public long nanoTime() {
            return fakeClock.getTicker().read();
        }
    };
    ClientCall.Listener<Void> observer = startNewCall(TestMethodDescriptors.voidMethod(), configSelector, Collections.<String, String>emptyMap(), CallOptions.DEFAULT.withDeadline(Deadline.after(4000, TimeUnit.NANOSECONDS, fakeTicker)));
    assertThat(testCall).isNull();
    verifyRpcDelayedThenAborted(observer, 4000L, Status.DEADLINE_EXCEEDED.withDescription("Deadline exceeded after up to 5000 ns of fault-injected delay:" + " Deadline exceeded after 0.000004000s. "));
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) ClientCall(io.grpc.ClientCall) NoopClientCall(io.grpc.internal.NoopClientCall) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Deadline(io.grpc.Deadline) 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