Skip to content

Commit

Permalink
test: ensure that directpath is enabled for direct path tests (#2263)
Browse files Browse the repository at this point in the history
This should unblock #2033 which disables directpath by default
  • Loading branch information
igorbernstein2 committed Jun 24, 2024
1 parent 9a2db83 commit bc81478
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 3 deletions.
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -50,7 +50,7 @@ If you are using Maven without the BOM, add this to your dependencies:
If you are using Gradle 5.x or later, add this to your dependencies:

```Groovy
implementation platform('com.google.cloud:libraries-bom:26.41.0')
implementation platform('com.google.cloud:libraries-bom:26.42.0')
implementation 'com.google.cloud:google-cloud-bigtable'
```
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -134,8 +134,9 @@ private CloudEnv(
dataSettings.stubSettings().setEndpoint(dataEndpoint);
}

setupRemoteAddrInterceptor(dataSettings.stubSettings());
configureConnection(dataSettings.stubSettings());
configureUserAgent(dataSettings.stubSettings());

if (tracingCookie != null) {
injectTracingCookie(tracingCookie, dataSettings.stubSettings());
}
Expand Down Expand Up @@ -164,21 +165,24 @@ private static void injectTracingCookie(
.build());
}

private void setupRemoteAddrInterceptor(StubSettings.Builder stubSettings) {
private void configureConnection(StubSettings.Builder stubSettings) {
// Build an remote address restricting interceptor
final ClientInterceptor interceptor;
boolean enableDirectPath = false;

switch (getConnectionMode()) {
case DEFAULT:
// nothing special
return;
case REQUIRE_DIRECT_PATH:
enableDirectPath = true;
interceptor =
buildRemoteAddrInterceptor(
"DirectPath IPv4 or IPv6",
Predicates.or(DIRECT_PATH_IPV4_MATCHER, DIRECT_PATH_IPV6_MATCHER));
break;
case REQUIRE_DIRECT_PATH_IPV4:
enableDirectPath = true;
interceptor =
buildRemoteAddrInterceptor("DirectPath IPv4", Predicates.or(DIRECT_PATH_IPV4_MATCHER));
break;
Expand All @@ -201,6 +205,10 @@ private void setupRemoteAddrInterceptor(StubSettings.Builder stubSettings) {
final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> oldConfigurator =
channelProvider.getChannelConfigurator();

if (enableDirectPath) {
channelProvider.setAttemptDirectPath(true).setAttemptDirectPathXds();
}

@SuppressWarnings("rawtypes")
final ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder> newConfigurator =
new ApiFunction<ManagedChannelBuilder, ManagedChannelBuilder>() {
Expand Down

0 comments on commit bc81478

Please sign in to comment.