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);
}
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);
}
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();
}
}
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");
}
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;
}
Aggregations