Skip to content

Commit 5c4a2c7

Browse files
test: add support for channel configurators to session client (#2880)
Change-Id: Iff9040f0ed03754f2424ffafb143752f69e0d8a6 Thank you for opening a Pull Request! Before submitting your PR, there are a few things you can do to make sure it goes smoothly: - [ ] Make sure to open an issue as a [bug/issue](https://togithub.com/googleapis/java-bigtable/issues/new/choose) before writing your code! That way we can discuss the change, evaluate designs, and agree on the general idea - [ ] Ensure the tests and linter pass - [ ] Code coverage does not decrease (if any source code was changed) - [ ] Appropriate docs were updated (if necessary) - [ ] Rollback plan is reviewed and LGTMed - [ ] All new data plane features have a completed end to end testing plan Fixes #<issue_number_goes_here> ☕️ If you write sample code, please follow the [samples format]( https://togithub.com/GoogleCloudPlatform/java-docs-samples/blob/main/SAMPLE_FORMAT.md).
1 parent 2742460 commit 5c4a2c7

2 files changed

Lines changed: 15 additions & 1 deletion

File tree

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/compat/GaxBasicChannelProvider.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.cloud.bigtable.data.v2.internal.compat;
1717

18+
import com.google.api.core.ApiFunction;
1819
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
1920
import com.google.auth.Credentials;
2021
import com.google.bigtable.v2.FeatureFlags;
@@ -32,11 +33,15 @@
3233
import javax.annotation.Nullable;
3334

3435
public class GaxBasicChannelProvider implements ChannelProvider {
36+
private final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator;
3537
private final InstantiatingGrpcChannelProvider inner;
3638
private final @Nullable CallCredentials credentials;
3739

40+
@SuppressWarnings("rawtypes")
3841
public GaxBasicChannelProvider(
3942
InstantiatingGrpcChannelProvider inner, @Nullable Credentials credentials) {
43+
this.channelConfigurator =
44+
Optional.ofNullable(inner.toBuilder().getChannelConfigurator()).orElse(b -> b);
4045
this.inner = inner.toBuilder().setAttemptDirectPath(false).build();
4146
this.credentials = Optional.ofNullable(credentials).map(MoreCallCredentials::from).orElse(null);
4247
}
@@ -56,6 +61,7 @@ public ManagedChannelBuilder<?> newChannelBuilder() {
5661
if (credentials != null) {
5762
builder.intercept(new CredInterceptor(credentials));
5863
}
64+
builder = channelConfigurator.apply(builder);
5965
return builder;
6066
} catch (IOException e) {
6167
throw new RuntimeException("Gax channel provider failed to provide a channel builder", e);

google-cloud-bigtable/src/main/java/com/google/cloud/bigtable/data/v2/internal/compat/GaxDirectAccessChannelProvider.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,6 +15,7 @@
1515
*/
1616
package com.google.cloud.bigtable.data.v2.internal.compat;
1717

18+
import com.google.api.core.ApiFunction;
1819
import com.google.api.gax.grpc.InstantiatingGrpcChannelProvider;
1920
import com.google.auth.Credentials;
2021
import com.google.bigtable.v2.FeatureFlags;
@@ -26,6 +27,10 @@
2627

2728
public class GaxDirectAccessChannelProvider implements ChannelProvider {
2829
private final InstantiatingGrpcChannelProvider inner;
30+
31+
@SuppressWarnings("rawtypes")
32+
private final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> channelConfigurator;
33+
2934
private final Optional<ChannelProvider> fallback;
3035

3136
public static ChannelProvider create(
@@ -67,6 +72,9 @@ private GaxDirectAccessChannelProvider(
6772
@SuppressWarnings("unused") @Nullable Credentials credentials,
6873
Optional<ChannelProvider> fallback) {
6974
this.inner = directAccessProvider;
75+
this.channelConfigurator =
76+
Optional.ofNullable(directAccessProvider.toBuilder().getChannelConfigurator())
77+
.orElse(b -> b);
7078
this.fallback = fallback;
7179
}
7280

@@ -81,7 +89,7 @@ public FeatureFlags updateFeatureFlags(FeatureFlags featureFlags) {
8189
@Override
8290
public ManagedChannelBuilder<?> newChannelBuilder() {
8391
try {
84-
return inner.createChannelBuilder();
92+
return channelConfigurator.apply(inner.createChannelBuilder());
8593
} catch (IOException e) {
8694
throw new RuntimeException("Gax channel provider failed to provide a channel builder", e);
8795
}

0 commit comments

Comments
 (0)