Skip to content
Permalink
Browse files
fix: InstantiatingGrpcChannelProvider.toBuilder() should carry over a…
…ll config data (#1298)
  • Loading branch information
dapengzhang0 committed Feb 12, 2021
1 parent 721617b commit 0bc5dc54c8eea00f2dc0e1d6a4a42e3417c64fc7
@@ -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. */
@@ -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);

0 comments on commit 0bc5dc5

Please sign in to comment.