|
33 | 33 | import com.google.api.gax.rpc.HeaderProvider;
|
34 | 34 | import com.google.auth.oauth2.AccessToken;
|
35 | 35 | import com.google.auth.oauth2.OAuth2Credentials;
|
| 36 | +import com.google.cloud.ServiceOptions; |
36 | 37 | import com.google.cloud.spanner.DatabaseClient;
|
37 | 38 | import com.google.cloud.spanner.DatabaseId;
|
38 | 39 | import com.google.cloud.spanner.Dialect;
|
|
77 | 78 | import java.net.InetSocketAddress;
|
78 | 79 | import java.util.HashMap;
|
79 | 80 | import java.util.Map;
|
| 81 | +import java.util.Objects; |
80 | 82 | import java.util.concurrent.TimeUnit;
|
81 | 83 | import org.junit.After;
|
82 | 84 | import org.junit.Before;
|
@@ -181,6 +183,12 @@ public <ReqT, RespT> ServerCall.Listener<ReqT> interceptCall(
|
181 | 183 | String auth =
|
182 | 184 | headers.get(Key.of("authorization", Metadata.ASCII_STRING_MARSHALLER));
|
183 | 185 | assertThat(auth).isEqualTo("Bearer " + VARIABLE_OAUTH_TOKEN);
|
| 186 | + String clientLibToken = |
| 187 | + headers.get( |
| 188 | + Metadata.Key.of("x-goog-api-client", Metadata.ASCII_STRING_MARSHALLER)); |
| 189 | + assertNotNull(clientLibToken); |
| 190 | + assertTrue( |
| 191 | + clientLibToken.contains(ServiceOptions.getGoogApiClientLibName() + "/")); |
184 | 192 | if (call.getMethodDescriptor()
|
185 | 193 | .equals(SpannerGrpc.getExecuteStreamingSqlMethod())
|
186 | 194 | || call.getMethodDescriptor().equals(SpannerGrpc.getExecuteSqlMethod())) {
|
@@ -575,6 +583,27 @@ public void testRouteToLeaderHeaderWithLeaderAwareRoutingDisabled() {
|
575 | 583 | assertFalse(isRouteToLeader);
|
576 | 584 | }
|
577 | 585 |
|
| 586 | + @Test |
| 587 | + public void testCustomClientLibToken_alsoContainsDefaultToken() { |
| 588 | + SpannerOptions options = |
| 589 | + createSpannerOptions().toBuilder().setClientLibToken("pg-adapter").build(); |
| 590 | + try (Spanner spanner = options.getService()) { |
| 591 | + DatabaseClient databaseClient = |
| 592 | + spanner.getDatabaseClient(DatabaseId.of("[PROJECT]", "[INSTANCE]", "[DATABASE]")); |
| 593 | + TransactionRunner runner = databaseClient.readWriteTransaction(); |
| 594 | + runner.run(transaction -> transaction.executeUpdate(UPDATE_FOO_STATEMENT)); |
| 595 | + } |
| 596 | + Key<String> key = Key.of("x-goog-api-client", Metadata.ASCII_STRING_MARSHALLER); |
| 597 | + assertTrue(lastSeenHeaders.containsKey(key)); |
| 598 | + assertTrue( |
| 599 | + lastSeenHeaders.get(key), |
| 600 | + Objects.requireNonNull(lastSeenHeaders.get(key)).contains("pg-adapter")); |
| 601 | + assertTrue( |
| 602 | + lastSeenHeaders.get(key), |
| 603 | + Objects.requireNonNull(lastSeenHeaders.get(key)) |
| 604 | + .contains(ServiceOptions.getGoogApiClientLibName() + "/")); |
| 605 | + } |
| 606 | + |
578 | 607 | private SpannerOptions createSpannerOptions() {
|
579 | 608 | String endpoint = address.getHostString() + ":" + server.getPort();
|
580 | 609 | return SpannerOptions.newBuilder()
|
|
0 commit comments