|
18 | 18 |
|
19 | 19 | import static com.google.common.truth.Truth.assertThat;
|
20 | 20 | import static org.junit.Assert.assertEquals;
|
| 21 | +import static org.junit.Assert.assertNotNull; |
| 22 | +import static org.junit.Assert.assertTrue; |
21 | 23 | import static org.junit.Assert.fail;
|
22 | 24 |
|
| 25 | +import com.google.cloud.ServiceOptions; |
23 | 26 | import com.google.cloud.spanner.MockSpannerServiceImpl;
|
24 | 27 | import com.google.cloud.spanner.connection.ConnectionOptions;
|
25 | 28 | import com.google.cloud.spanner.connection.ConnectionOptions.ConnectionProperty;
|
26 | 29 | import com.google.cloud.spanner.connection.SpannerPool;
|
27 | 30 | import com.google.common.collect.Collections2;
|
28 | 31 | import com.google.common.collect.ImmutableList;
|
29 | 32 | import com.google.rpc.Code;
|
| 33 | +import io.grpc.Context; |
| 34 | +import io.grpc.Contexts; |
| 35 | +import io.grpc.Metadata; |
30 | 36 | import io.grpc.Server;
|
| 37 | +import io.grpc.ServerCall; |
| 38 | +import io.grpc.ServerCall.Listener; |
| 39 | +import io.grpc.ServerCallHandler; |
| 40 | +import io.grpc.ServerInterceptor; |
31 | 41 | import io.grpc.netty.shaded.io.grpc.netty.NettyServerBuilder;
|
32 | 42 | import java.io.IOException;
|
33 | 43 | import java.net.InetSocketAddress;
|
@@ -64,7 +74,27 @@ public class JdbcDriverTest {
|
64 | 74 | public static void startStaticServer() throws IOException {
|
65 | 75 | MockSpannerServiceImpl mockSpanner = new MockSpannerServiceImpl();
|
66 | 76 | InetSocketAddress address = new InetSocketAddress("localhost", 0);
|
67 |
| - server = NettyServerBuilder.forAddress(address).addService(mockSpanner).build().start(); |
| 77 | + server = |
| 78 | + NettyServerBuilder.forAddress(address) |
| 79 | + .addService(mockSpanner) |
| 80 | + .intercept( |
| 81 | + new ServerInterceptor() { |
| 82 | + @Override |
| 83 | + public <ReqT, RespT> Listener<ReqT> interceptCall( |
| 84 | + ServerCall<ReqT, RespT> call, |
| 85 | + Metadata headers, |
| 86 | + ServerCallHandler<ReqT, RespT> next) { |
| 87 | + String clientLibToken = |
| 88 | + headers.get( |
| 89 | + Metadata.Key.of("x-goog-api-client", Metadata.ASCII_STRING_MARSHALLER)); |
| 90 | + assertNotNull(clientLibToken); |
| 91 | + assertTrue( |
| 92 | + clientLibToken.contains(ServiceOptions.getGoogApiClientLibName() + "/")); |
| 93 | + return Contexts.interceptCall(Context.current(), call, headers, next); |
| 94 | + } |
| 95 | + }) |
| 96 | + .build() |
| 97 | + .start(); |
68 | 98 | }
|
69 | 99 |
|
70 | 100 | @AfterClass
|
|
0 commit comments