use of io.grpc.InternalConfigSelector.Result in project grpc-java by grpc.
the class InternalConfigSelectorTest method resultBuilder.
@Test
public void resultBuilder() {
Object config = "fake_config";
InternalConfigSelector.Result.Builder builder = InternalConfigSelector.Result.newBuilder();
ClientInterceptor interceptor = mock(ClientInterceptor.class);
InternalConfigSelector.Result result = builder.setConfig(config).setInterceptor(interceptor).build();
assertThat(result.getStatus().isOk()).isTrue();
assertThat(result.getConfig()).isEqualTo(config);
assertThat(result.getInterceptor()).isSameInstanceAs(interceptor);
}
use of io.grpc.InternalConfigSelector.Result in project grpc-java by grpc.
the class InternalConfigSelectorTest method errorResult.
@Test
public void errorResult() {
Result result = Result.forError(Status.INTERNAL.withDescription("failed"));
assertThat(result.getStatus().isOk()).isFalse();
assertThat(result.getStatus().getCode()).isEqualTo(Code.INTERNAL);
assertThat(result.getStatus().getDescription()).isEqualTo("failed");
}
use of io.grpc.InternalConfigSelector.Result in project grpc-java by grpc.
the class ManagedChannelServiceConfigTest method getDefaultConfigSelectorFromConfig.
@Test
public void getDefaultConfigSelectorFromConfig() {
Map<String, ?> name = ImmutableMap.of("service", "service1", "method", "method1");
Map<String, ?> methodConfig = ImmutableMap.of("name", ImmutableList.of(name), "timeout", "1.234s");
Map<String, ?> rawServiceConfig = ImmutableMap.of("methodConfig", ImmutableList.of(methodConfig));
ManagedChannelServiceConfig serviceConfig = ManagedChannelServiceConfig.fromServiceConfig(rawServiceConfig, false, 0, 0, null);
InternalConfigSelector configSelector = serviceConfig.getDefaultConfigSelector();
MethodDescriptor<?, ?> method = methodForName("service1", "method1");
Result result = configSelector.selectConfig(new PickSubchannelArgsImpl(method, new Metadata(), CallOptions.DEFAULT));
MethodInfo methodInfoFromDefaultConfigSelector = ((ManagedChannelServiceConfig) result.getConfig()).getMethodConfig(method);
assertThat(methodInfoFromDefaultConfigSelector).isEqualTo(serviceConfig.getMethodConfig(method));
}
use of io.grpc.InternalConfigSelector.Result 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());
}
Aggregations