Search in sources :

Example 1 with Result

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

the class XdsNameResolverTest method resolved_simpleCallFailedToRoute_noMatchingRoute.

@Test
public void resolved_simpleCallFailedToRoute_noMatchingRoute() {
    InternalConfigSelector configSelector = resolveToClusters();
    CallInfo call = new CallInfo("FooService", "barMethod");
    Result selectResult = configSelector.selectConfig(new PickSubchannelArgsImpl(call.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 find xDS route matching RPC");
    verifyNoMoreInteractions(mockListener);
}
Also used : Status(io.grpc.Status) PickSubchannelArgsImpl(io.grpc.internal.PickSubchannelArgsImpl) InternalConfigSelector(io.grpc.InternalConfigSelector) Metadata(io.grpc.Metadata) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Result(io.grpc.InternalConfigSelector.Result) Test(org.junit.Test)

Example 2 with Result

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

Example 3 with Result

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

the class XdsNameResolverTest method assertCallSelectClusterResult.

private void assertCallSelectClusterResult(CallInfo call, InternalConfigSelector configSelector, String expectedCluster, @Nullable Double expectedTimeoutSec) {
    Result result = configSelector.selectConfig(new PickSubchannelArgsImpl(call.methodDescriptor, new Metadata(), CallOptions.DEFAULT));
    assertThat(result.getStatus().isOk()).isTrue();
    ClientInterceptor interceptor = result.getInterceptor();
    ClientCall<Void, Void> clientCall = interceptor.interceptCall(call.methodDescriptor, CallOptions.DEFAULT, channel);
    clientCall.start(new NoopClientCallListener<Void>(), new Metadata());
    assertThat(testCall.callOptions.getOption(XdsNameResolver.CLUSTER_SELECTION_KEY)).isEqualTo("cluster:" + expectedCluster);
    @SuppressWarnings("unchecked") Map<String, ?> config = (Map<String, ?>) result.getConfig();
    if (expectedTimeoutSec != null) {
        // Verify the raw service config contains a single method config for method with the
        // specified timeout.
        List<Map<String, ?>> rawMethodConfigs = JsonUtil.getListOfObjects(config, "methodConfig");
        Map<String, ?> methodConfig = Iterables.getOnlyElement(rawMethodConfigs);
        List<Map<String, ?>> methods = JsonUtil.getListOfObjects(methodConfig, "name");
        assertThat(Iterables.getOnlyElement(methods)).isEmpty();
        assertThat(JsonUtil.getString(methodConfig, "timeout")).isEqualTo(expectedTimeoutSec + "s");
    } else {
        assertThat(config).isEmpty();
    }
}
Also used : PickSubchannelArgsImpl(io.grpc.internal.PickSubchannelArgsImpl) Metadata(io.grpc.Metadata) ClientInterceptor(io.grpc.ClientInterceptor) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Result(io.grpc.InternalConfigSelector.Result)

Example 4 with Result

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

the class XdsNameResolverTest method assertCallSelectRlsPluginResult.

private void assertCallSelectRlsPluginResult(CallInfo call, InternalConfigSelector configSelector, String expectedPluginName, Double expectedTimeoutSec) {
    Result result = configSelector.selectConfig(new PickSubchannelArgsImpl(call.methodDescriptor, new Metadata(), CallOptions.DEFAULT));
    assertThat(result.getStatus().isOk()).isTrue();
    ClientInterceptor interceptor = result.getInterceptor();
    ClientCall<Void, Void> clientCall = interceptor.interceptCall(call.methodDescriptor, CallOptions.DEFAULT, channel);
    clientCall.start(new NoopClientCallListener<Void>(), new Metadata());
    assertThat(testCall.callOptions.getOption(XdsNameResolver.CLUSTER_SELECTION_KEY)).isEqualTo("cluster_specifier_plugin:" + expectedPluginName);
    @SuppressWarnings("unchecked") Map<String, ?> config = (Map<String, ?>) result.getConfig();
    List<Map<String, ?>> rawMethodConfigs = JsonUtil.getListOfObjects(config, "methodConfig");
    Map<String, ?> methodConfig = Iterables.getOnlyElement(rawMethodConfigs);
    List<Map<String, ?>> methods = JsonUtil.getListOfObjects(methodConfig, "name");
    assertThat(Iterables.getOnlyElement(methods)).isEmpty();
    assertThat(JsonUtil.getString(methodConfig, "timeout")).isEqualTo(expectedTimeoutSec + "s");
}
Also used : PickSubchannelArgsImpl(io.grpc.internal.PickSubchannelArgsImpl) Metadata(io.grpc.Metadata) ClientInterceptor(io.grpc.ClientInterceptor) Map(java.util.Map) ImmutableMap(com.google.common.collect.ImmutableMap) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Result(io.grpc.InternalConfigSelector.Result)

Example 5 with Result

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

the class XdsNameResolverTest method startNewCall.

private <ReqT, RespT> ClientCall.Listener<RespT> startNewCall(MethodDescriptor<ReqT, RespT> method, InternalConfigSelector selector, Map<String, String> headers, CallOptions callOptions) {
    Metadata metadata = new Metadata();
    for (String key : headers.keySet()) {
        metadata.put(Metadata.Key.of(key, Metadata.ASCII_STRING_MARSHALLER), headers.get(key));
    }
    @SuppressWarnings("unchecked") ClientCall.Listener<RespT> listener = mock(ClientCall.Listener.class);
    Result result = selector.selectConfig(new PickSubchannelArgsImpl(method, metadata, callOptions));
    ClientCall<ReqT, RespT> call = ClientInterceptors.intercept(channel, result.getInterceptor()).newCall(method, callOptions);
    call.start(listener, metadata);
    return listener;
}
Also used : PickSubchannelArgsImpl(io.grpc.internal.PickSubchannelArgsImpl) ClientCall(io.grpc.ClientCall) NoopClientCall(io.grpc.internal.NoopClientCall) Metadata(io.grpc.Metadata) ResolutionResult(io.grpc.NameResolver.ResolutionResult) Result(io.grpc.InternalConfigSelector.Result)

Aggregations

Result (io.grpc.InternalConfigSelector.Result)9 Metadata (io.grpc.Metadata)7 ResolutionResult (io.grpc.NameResolver.ResolutionResult)6 PickSubchannelArgsImpl (io.grpc.internal.PickSubchannelArgsImpl)6 Test (org.junit.Test)6 InternalConfigSelector (io.grpc.InternalConfigSelector)4 ImmutableMap (com.google.common.collect.ImmutableMap)2 ClientInterceptor (io.grpc.ClientInterceptor)2 Status (io.grpc.Status)2 HashPolicy (io.grpc.xds.VirtualHost.Route.RouteAction.HashPolicy)2 Map (java.util.Map)2 ClientCall (io.grpc.ClientCall)1 ServiceConfigParser (io.grpc.NameResolver.ServiceConfigParser)1 AutoConfiguredLoadBalancerFactory (io.grpc.internal.AutoConfiguredLoadBalancerFactory)1 MethodInfo (io.grpc.internal.ManagedChannelServiceConfig.MethodInfo)1 NoopClientCall (io.grpc.internal.NoopClientCall)1 ScParser (io.grpc.internal.ScParser)1 RetryPolicy (io.grpc.xds.VirtualHost.Route.RouteAction.RetryPolicy)1