diff --git a/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java b/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java index cfee67cb4..9797b4d7d 100644 --- a/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java +++ b/gax-grpc/src/main/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProvider.java @@ -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. */ diff --git a/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java b/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java index 3b7696cc1..47f612db5 100644 --- a/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java +++ b/gax-grpc/src/test/java/com/google/api/gax/grpc/InstantiatingGrpcChannelProviderTest.java @@ -157,6 +157,45 @@ public void testWithPoolSize() throws IOException { } } + @Test + public void testToBuilder() { + Duration keepaliveTime = Duration.ofSeconds(1); + Duration keepaliveTimeout = Duration.ofSeconds(2); + ApiFunction channelConfigurator = + new ApiFunction() { + @Override + public ManagedChannelBuilder apply(ManagedChannelBuilder input) { + throw new UnsupportedOperationException(); + } + }; + Map 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);