Skip to content

Commit

Permalink
Add authorityFor method
Browse files Browse the repository at this point in the history
  • Loading branch information
nimf committed Jul 8, 2022
1 parent af5be1e commit 8080ea2
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -394,8 +394,11 @@ public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(
}

/**
* The authority of the destination this channel connects to. Typically this is in the format
* {@code host:port}.
* The authority of the current endpoint of the default MultiEndpoint. Typically, this is in the
* format {@code host:port}.
*
* To get the authority of the current endpoint of another MultiEndpoint use {@link
* #authorityFor(String)} method.
*
* This may return different values over time because MultiEndpoint may switch between endpoints.
*
Expand All @@ -405,4 +408,18 @@ public <RequestT, ResponseT> ClientCall<RequestT, ResponseT> newCall(
public String authority() {
return pools.get(defaultMultiEndpoint.getCurrentId()).authority();
}

/**
* The authority of the current endpoint of the specified MultiEndpoint. Typically, this is in the
* format {@code host:port}.
*
* This may return different values over time because MultiEndpoint may switch between endpoints.
*/
public String authorityFor(String multiEndpointName) {
MultiEndpoint multiEndpoint = multiEndpoints.get(multiEndpointName);
if (multiEndpoint == null) {
return null;
}
return pools.get(multiEndpoint.getCurrentId()).authority();
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -566,6 +566,14 @@ public void testSpannerMultiEndpointClient() throws IOException, InterruptedExce
final String followerPoolIndex = String.format("pool-%d", currentIndex);
final String leaderPoolIndex = String.format("pool-%d", currentIndex - 1);

// Make sure authorities are overridden by channel configurator.
assertThat(gcpMultiEndpointChannel.authority()).isEqualTo(SPANNER_TARGET);
assertThat(gcpMultiEndpointChannel.authorityFor("leader"))
.isEqualTo(SPANNER_TARGET);
assertThat(gcpMultiEndpointChannel.authorityFor("follower"))
.isEqualTo(SPANNER_TARGET);
assertThat(gcpMultiEndpointChannel.authorityFor("no-such-name")).isNull();

TimeUnit.MILLISECONDS.sleep(200);

List<String> logMessages = logRecords.stream()
Expand Down

0 comments on commit 8080ea2

Please sign in to comment.