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

Commit 0bc5dc5

Browse files
authored
fix: InstantiatingGrpcChannelProvider.toBuilder() should carry over all config data (#1298)
1 parent 721617b commit 0bc5dc5

File tree

2 files changed

+40
-0
lines changed

2 files changed

+40
-0
lines changed

gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -411,6 +411,7 @@ private Builder(InstantiatingGrpcChannelProvider provider) {
411411
this.credentials = provider.credentials;
412412
this.channelPrimer = provider.channelPrimer;
413413
this.attemptDirectPath = provider.attemptDirectPath;
414+
this.directPathServiceConfig = provider.directPathServiceConfig;
414415
}
415416

416417
/** Sets the number of available CPUs, used internally for testing. */

gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java

Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -157,6 +157,45 @@ public void testWithPoolSize() throws IOException {
157157
}
158158
}
159159

160+
@Test
161+
public void testToBuilder() {
162+
Duration keepaliveTime = Duration.ofSeconds(1);
163+
Duration keepaliveTimeout = Duration.ofSeconds(2);
164+
ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator =
165+
new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {
166+
@Override
167+
public ManagedChannelBuilder apply(ManagedChannelBuilder input) {
168+
throw new UnsupportedOperationException();
169+
}
170+
};
171+
Map<String, ?> directPathServiceConfig = ImmutableMap.of("loadbalancingConfig", "grpclb");
172+
173+
InstantiatingGrpcChannelProvider provider =
174+
InstantiatingGrpcChannelProvider.newBuilder()
175+
.setProcessorCount(2)
176+
.setEndpoint("fake.endpoint:443")
177+
.setMaxInboundMessageSize(12345678)
178+
.setMaxInboundMetadataSize(4096)
179+
.setKeepAliveTime(keepaliveTime)
180+
.setKeepAliveTimeout(keepaliveTimeout)
181+
.setKeepAliveWithoutCalls(true)
182+
.setChannelConfigurator(channelConfigurator)
183+
.setChannelsPerCpu(2.5)
184+
.setDirectPathServiceConfig(directPathServiceConfig)
185+
.build();
186+
187+
InstantiatingGrpcChannelProvider.Builder builder = provider.toBuilder();
188+
189+
assertThat(builder.getEndpoint()).isEqualTo("fake.endpoint:443");
190+
assertThat(builder.getMaxInboundMessageSize()).isEqualTo(12345678);
191+
assertThat(builder.getMaxInboundMetadataSize()).isEqualTo(4096);
192+
assertThat(builder.getKeepAliveTime()).isEqualTo(keepaliveTime);
193+
assertThat(builder.getKeepAliveTimeout()).isEqualTo(keepaliveTimeout);
194+
assertThat(builder.getChannelConfigurator()).isEqualTo(channelConfigurator);
195+
assertThat(builder.getPoolSize()).isEqualTo(5);
196+
assertThat(builder.build().directPathServiceConfig).isEqualTo(directPathServiceConfig);
197+
}
198+
160199
@Test
161200
public void testWithInterceptors() throws Exception {
162201
testWithInterceptors(1);

0 commit comments

Comments
 (0)