Skip to content
This repository has been archived by the owner on Sep 26, 2023. It is now read-only.

Commit

Permalink
fix: InstantiatingGrpcChannelProvider.toBuilder() should carry over a…
Browse files Browse the repository at this point in the history
…ll config data (#1298)
  • Loading branch information
dapengzhang0 committed Feb 12, 2021
1 parent 721617b commit 0bc5dc5
Show file tree
Hide file tree
Showing 2 changed files with 40 additions and 0 deletions.
Expand Up @@ -411,6 +411,7 @@ private Builder(InstantiatingGrpcChannelProvider provider) {
this.credentials = provider.credentials;
this.channelPrimer = provider.channelPrimer;
this.attemptDirectPath = provider.attemptDirectPath;
this.directPathServiceConfig = provider.directPathServiceConfig;
}

/** Sets the number of available CPUs, used internally for testing. */
Expand Down
Expand Up @@ -157,6 +157,45 @@ public void testWithPoolSize() throws IOException {
}
}

@Test
public void testToBuilder() {
Duration keepaliveTime = Duration.ofSeconds(1);
Duration keepaliveTimeout = Duration.ofSeconds(2);
ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator =
new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {
@Override
public ManagedChannelBuilder apply(ManagedChannelBuilder input) {
throw new UnsupportedOperationException();
}
};
Map<String, ?> directPathServiceConfig = ImmutableMap.of("loadbalancingConfig", "grpclb");

InstantiatingGrpcChannelProvider provider =
InstantiatingGrpcChannelProvider.newBuilder()
.setProcessorCount(2)
.setEndpoint("fake.endpoint:443")
.setMaxInboundMessageSize(12345678)
.setMaxInboundMetadataSize(4096)
.setKeepAliveTime(keepaliveTime)
.setKeepAliveTimeout(keepaliveTimeout)
.setKeepAliveWithoutCalls(true)
.setChannelConfigurator(channelConfigurator)
.setChannelsPerCpu(2.5)
.setDirectPathServiceConfig(directPathServiceConfig)
.build();

InstantiatingGrpcChannelProvider.Builder builder = provider.toBuilder();

assertThat(builder.getEndpoint()).isEqualTo("fake.endpoint:443");
assertThat(builder.getMaxInboundMessageSize()).isEqualTo(12345678);
assertThat(builder.getMaxInboundMetadataSize()).isEqualTo(4096);
assertThat(builder.getKeepAliveTime()).isEqualTo(keepaliveTime);
assertThat(builder.getKeepAliveTimeout()).isEqualTo(keepaliveTimeout);
assertThat(builder.getChannelConfigurator()).isEqualTo(channelConfigurator);
assertThat(builder.getPoolSize()).isEqualTo(5);
assertThat(builder.build().directPathServiceConfig).isEqualTo(directPathServiceConfig);
}

@Test
public void testWithInterceptors() throws Exception {
testWithInterceptors(1);
Expand Down

0 comments on commit 0bc5dc5

Please sign in to comment.