Search in sources :

Example 6 with PickSubchannelArgsImpl

use of io.grpc.internal.PickSubchannelArgsImpl 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 7 with PickSubchannelArgsImpl

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

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

use of io.grpc.internal.PickSubchannelArgsImpl 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 10 with PickSubchannelArgsImpl

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

Metadata (io.grpc.Metadata)20 PickSubchannelArgsImpl (io.grpc.internal.PickSubchannelArgsImpl)20 Test (org.junit.Test)17 SubchannelPicker (io.grpc.LoadBalancer.SubchannelPicker)13 CreateSubchannelArgs (io.grpc.LoadBalancer.CreateSubchannelArgs)12 EquivalentAddressGroup (io.grpc.EquivalentAddressGroup)10 PickResult (io.grpc.LoadBalancer.PickResult)10 PickSubchannelArgs (io.grpc.LoadBalancer.PickSubchannelArgs)10 RingHashConfig (io.grpc.xds.RingHashLoadBalancer.RingHashConfig)10 Subchannel (io.grpc.LoadBalancer.Subchannel)7 InOrder (org.mockito.InOrder)7 Result (io.grpc.InternalConfigSelector.Result)6 ResolutionResult (io.grpc.NameResolver.ResolutionResult)6 InternalConfigSelector (io.grpc.InternalConfigSelector)3 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 HashMap (java.util.HashMap)2 Map (java.util.Map)2