Search in sources :

Example 6 with Result

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);
}
Also used : Result(io.grpc.InternalConfigSelector.Result) Result(io.grpc.InternalConfigSelector.Result) Test(org.junit.Test)

Example 7 with Result

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");
}
Also used : Result(io.grpc.InternalConfigSelector.Result) Test(org.junit.Test)

Example 8 with Result

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));
}
Also used : InternalConfigSelector(io.grpc.InternalConfigSelector) Metadata(io.grpc.Metadata) MethodInfo(io.grpc.internal.ManagedChannelServiceConfig.MethodInfo) Result(io.grpc.InternalConfigSelector.Result) Test(org.junit.Test)

Example 9 with Result

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

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