diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionClient.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionClient.java index 20c86bdf25..e025af42d4 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionClient.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/SessionClient.java @@ -190,7 +190,7 @@ interface SessionConsumer { // SessionClient is created long before a DatabaseClientImpl is created, // as batch sessions are firstly created then later attached to each Client. private static final AtomicInteger NTH_ID = new AtomicInteger(0); - private final int nthId = NTH_ID.incrementAndGet(); + private final int nthId; private final AtomicInteger nthRequest = new AtomicInteger(0); @GuardedBy("this") @@ -205,6 +205,7 @@ interface SessionConsumer { this.executorFactory = executorFactory; this.executor = executorFactory.get(); this.commonAttributes = spanner.getTracer().createCommonAttributes(db); + this.nthId = NTH_ID.incrementAndGet(); } @Override diff --git a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java index 60a99a8bfa..d24fcd625a 100644 --- a/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java +++ b/google-cloud-spanner/src/main/java/com/google/cloud/spanner/spi/v1/GapicSpannerRpc.java @@ -2043,7 +2043,7 @@ GrpcCallContext newCallContext( } if (options != null) { // TODO(@odeke-em): Infer the affinity if it doesn't match up with in the request-id. - context = withRequestId(context, options); + context = withRequestId(context, options, method); } context = context.withExtraHeaders(metadataProvider.newExtraHeaders(resource, projectName)); if (routeToLeader && leaderAwareRoutingEnabled) { @@ -2061,15 +2061,44 @@ GrpcCallContext newCallContext( if (configurator != null) { apiCallContextFromContext = configurator.configure(context, request, method); } + + // Debug the call headers before this. + Map> hdrs = context.getExtraHeaders(); + if (false + && method != null + && method.getFullMethodName().compareTo("google.spanner.v1.Spanner/DeleteSession") != 0) { + System.out.println( + "\033[32mextraHeaders going out for " + method.getFullMethodName() + "\033[00m"); + for (Map.Entry> entry : hdrs.entrySet()) { + System.out.println( + "\t\033[36mcall.Key: " + entry.getKey() + ":: " + entry.getValue() + "\033[00m"); + } + } return (GrpcCallContext) context.merge(apiCallContextFromContext); } - GrpcCallContext withRequestId(GrpcCallContext context, Map options) { + GrpcCallContext withRequestId( + GrpcCallContext context, + Map options, + MethodDescriptor method) { XGoogSpannerRequestId reqId = (XGoogSpannerRequestId) options.get(Option.REQUEST_ID); if (reqId == null) { return context; } + if (false + && method != null + && method.getFullMethodName().compareTo("google.spanner.v1.Spanner/ExecuteStreamingSql") + == 0) { + System.out.println( + "\033[36mGapiSpannerRpc.withRequestId: " + + reqId + + " for: " + + method.getFullMethodName() + + " " + + System.identityHashCode(context) + + "\033[00m"); + } Map> withReqId = ImmutableMap.of( XGoogSpannerRequestId.REQUEST_HEADER_KEY.name(), diff --git a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java index fa8b5c982f..e89e448314 100644 --- a/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java +++ b/google-cloud-spanner/src/test/java/com/google/cloud/spanner/DatabaseClientImplTest.java @@ -2920,11 +2920,21 @@ public void testPartitionedDmlDoesNotTimeout() { "google.spanner.v1.Spanner/ExecuteStreamingSql", new XGoogSpannerRequestId(NON_DETERMINISTIC, channelId, 6, 1)), }; - if (false) { // TODO(@odeke-em): enable in next PRs. - xGoogReqIdInterceptor.checkExpectedStreamingXGoogRequestIds(wantStreamingValues); - } + xGoogReqIdInterceptor.checkExpectedStreamingXGoogRequestIds(wantStreamingValues); XGoogSpannerRequestIdTest.MethodAndRequestId[] wantUnaryValues = { + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), XGoogSpannerRequestIdTest.ofMethodAndRequestId( "google.spanner.v1.Spanner/BeginTransaction", new XGoogSpannerRequestId(NON_DETERMINISTIC, channelId, 7, 1)), @@ -2935,9 +2945,7 @@ public void testPartitionedDmlDoesNotTimeout() { "google.spanner.v1.Spanner/ExecuteSql", new XGoogSpannerRequestId(NON_DETERMINISTIC, channelId, 8, 1)), }; - if (false) { // TODO(@odeke-em): enable in next PRs. - xGoogReqIdInterceptor.checkExpectedUnaryXGoogRequestIdsAsSuffixes(wantUnaryValues); - } + xGoogReqIdInterceptor.checkExpectedUnaryXGoogRequestIds(wantUnaryValues); } } @@ -2972,6 +2980,48 @@ public void testPartitionedDmlWithLowerTimeout() { .readWriteTransaction() .run(transaction -> transaction.executeUpdate(UPDATE_STATEMENT)); assertThat(updateCount).isEqualTo(UPDATE_COUNT); + + DatabaseClientImpl dbImpl = ((DatabaseClientImpl) client); + + int channelId = 0; + try (Session session = dbImpl.getSession()) { + channelId = ((PooledSessionFuture) session).getChannel(); + } + int dbId = dbImpl.dbId; + long NON_DETERMINISTIC = XGoogSpannerRequestIdTest.NON_DETERMINISTIC; + XGoogSpannerRequestIdTest.MethodAndRequestId[] wantStreamingValues = { + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 0, 6, 1)), + }; + // TODO(@odeke-em): Uncomment this when fixed up. + // xGoogReqIdInterceptor.checkExpectedStreamingXGoogRequestIds(wantStreamingValues); + + XGoogSpannerRequestIdTest.MethodAndRequestId[] wantUnaryValues = { + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BeginTransaction", + new XGoogSpannerRequestId(NON_DETERMINISTIC, channelId, 7, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/CreateSession", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 0, 1, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, channelId, 8, 1)), + }; + // TODO(@odeke-em): Uncomment this when fixed up. + // xGoogReqIdInterceptor.checkExpectedUnaryXGoogRequestIds(wantUnaryValues); } } @@ -3034,11 +3084,21 @@ public void testPartitionedDmlWithHigherTimeout() { new XGoogSpannerRequestId(NON_DETERMINISTIC, channelId, 6, 1)), }; - if (false) { // TODO(@odeke-em): enable in next PRs. - xGoogReqIdInterceptor.checkExpectedStreamingXGoogRequestIds(wantStreamingValues); - } + xGoogReqIdInterceptor.checkExpectedStreamingXGoogRequestIds(wantStreamingValues); XGoogSpannerRequestIdTest.MethodAndRequestId[] wantUnaryValues = { + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), XGoogSpannerRequestIdTest.ofMethodAndRequestId( "google.spanner.v1.Spanner/BeginTransaction", new XGoogSpannerRequestId(NON_DETERMINISTIC, channelId, 7, 1)), @@ -3049,9 +3109,7 @@ public void testPartitionedDmlWithHigherTimeout() { "google.spanner.v1.Spanner/ExecuteSql", new XGoogSpannerRequestId(NON_DETERMINISTIC, channelId, 8, 1)), }; - if (false) { // TODO(@odeke-em): enable in next PRs. - xGoogReqIdInterceptor.checkExpectedUnaryXGoogRequestIdsAsSuffixes(wantUnaryValues); - } + xGoogReqIdInterceptor.checkExpectedUnaryXGoogRequestIds(wantUnaryValues); } } @@ -3069,6 +3127,43 @@ public void testPartitionedDmlRetriesOnUnavailable() { spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE)); long updateCount = client.executePartitionedUpdate(UPDATE_STATEMENT); assertThat(updateCount).isEqualTo(UPDATE_COUNT); + + DatabaseClientImpl dbImpl = ((DatabaseClientImpl) client); + int channelId = 0; + try (Session session = dbImpl.getSession()) { + channelId = ((PooledSessionFuture) session).getChannel(); + } + int dbId = dbImpl.dbId; + long NON_DETERMINISTIC = XGoogSpannerRequestIdTest.NON_DETERMINISTIC; + XGoogSpannerRequestIdTest.MethodAndRequestId[] wantStreamingValues = { + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, channelId, 6, 1)), + }; + + xGoogReqIdInterceptor.checkExpectedStreamingXGoogRequestIds(wantStreamingValues); + + XGoogSpannerRequestIdTest.MethodAndRequestId[] wantUnaryValues = { + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BeginTransaction", + new XGoogSpannerRequestId(NON_DETERMINISTIC, channelId, 7, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/CreateSession", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 0, 1, 1)), + }; + xGoogReqIdInterceptor.checkExpectedUnaryXGoogRequestIds(wantUnaryValues); } } @@ -3476,6 +3571,63 @@ public void testNestedTransactionsUsingTwoDatabases() throws InterruptedExceptio // All sessions should now be checked back in to the pools. assertThat(client1.pool.getNumberOfSessionsInPool()).isEqualTo(minSessions); assertThat(client2.pool.getNumberOfSessionsInPool()).isEqualTo(minSessions); + + int channelId = 0; + try (Session session = client1.getSession()) { + channelId = ((PooledSessionFuture) session).getChannel(); + } + int dbId = client1.dbId; + long NON_DETERMINISTIC = XGoogSpannerRequestIdTest.NON_DETERMINISTIC; + XGoogSpannerRequestIdTest.MethodAndRequestId[] wantStreamingValues = { + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 6, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 6, 1)), + }; + xGoogReqIdInterceptor.checkExpectedStreamingXGoogRequestIds(wantStreamingValues); + + XGoogSpannerRequestIdTest.MethodAndRequestId[] wantUnaryValues = { + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BeginTransaction", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BeginTransaction", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/Commit", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, 7, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/Commit", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, 7, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/CreateSession", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, 1, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/CreateSession", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, 1, 1)), + }; + // TODO(@odeke-em): Uncomment this when fixed up. + // xGoogReqIdInterceptor.checkExpectedUnaryXGoogRequestIds(wantUnaryValues); } @Test @@ -5238,9 +5390,9 @@ public void testRetryOnResourceExhausted() { .setRetryableCodes(StatusCode.Code.UNAVAILABLE, StatusCode.Code.RESOURCE_EXHAUSTED) .setRetrySettings(retrySettings); + DatabaseClient client; try (Spanner spanner = builder.build().getService()) { - DatabaseClient client = - spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE)); + client = spanner.getDatabaseClient(DatabaseId.of(TEST_PROJECT, TEST_INSTANCE, TEST_DATABASE)); final int expectedRowCount = 5; RandomResultSetGenerator generator = new RandomResultSetGenerator(expectedRowCount); Statement statement = Statement.of("select * from random_table"); @@ -5285,6 +5437,81 @@ public void testRetryOnResourceExhausted() { mockSpanner.clearRequests(); } } + + DatabaseClientImpl dbClient = (DatabaseClientImpl) client; + int channelId = 0; + try (Session session = dbClient.getSession()) { + channelId = ((PooledSessionFuture) session).getChannel(); + } + int dbId = dbClient.dbId; + long NON_DETERMINISTIC = XGoogSpannerRequestIdTest.NON_DETERMINISTIC; + XGoogSpannerRequestIdTest.MethodAndRequestId[] wantStreamingValues = { + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 5, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId( + NON_DETERMINISTIC, 1, 5, 1)), // TODO(@odeke-em): investigate why not 2. + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 6, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId( + NON_DETERMINISTIC, 1, 6, 1)), // TODO(@odeke-em): investigate why not 2. + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 7, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 7, 2)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 8, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 8, 2)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 9, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 9, 2)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 10, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 10, 2)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 11, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 11, 2)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 12, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/ExecuteStreamingSql", + new XGoogSpannerRequestId(NON_DETERMINISTIC, 1, 12, 2)), + }; + // TODO(@odeke-em): Uncomment this when fixed up. + // xGoogReqIdInterceptor.checkExpectedStreamingXGoogRequestIds(wantStreamingValues); + + // BatchCreateSession can create a non-deterministic number of calls so + // we have to just ensure that we have at least the following. + XGoogSpannerRequestIdTest.MethodAndRequestId[] wantUnaryValues = { + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + }; + xGoogReqIdInterceptor.checkAtLeastHasExpectedUnaryXGoogRequestIds(wantUnaryValues); + // xGoogReqIdInterceptor.assertIntegrity(); } } @@ -5349,7 +5576,8 @@ public void testSessionPoolExhaustedError_containsStackTraces() { spannerException.getMessage(), spannerException.getMessage().contains("Session was checked out from the pool at")); - SessionPool pool = ((DatabaseClientImpl) client).pool; + DatabaseClientImpl dbClient = (DatabaseClientImpl) client; + SessionPool pool = dbClient.pool; // Verify that there are no sessions in the pool. assertEquals(0, pool.getNumberOfSessionsInPool()); // Verify that the sessions have not (yet) been marked as in use. @@ -5390,13 +5618,17 @@ public void testSessionPoolExhaustedError_containsStackTraces() { long NON_DETERMINISTIC = XGoogSpannerRequestIdTest.NON_DETERMINISTIC; XGoogSpannerRequestIdTest.MethodAndRequestId[] wantUnaryValues = { + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), + XGoogSpannerRequestIdTest.ofMethodAndRequestId( + "google.spanner.v1.Spanner/BatchCreateSessions", + new XGoogSpannerRequestId(NON_DETERMINISTIC, NON_DETERMINISTIC, NON_DETERMINISTIC, 1)), XGoogSpannerRequestIdTest.ofMethodAndRequestId( "google.spanner.v1.Spanner/CreateSession", new XGoogSpannerRequestId(NON_DETERMINISTIC, 0, 1, 1)), }; - if (false) { // TODO(@odeke-em): enable in next PRs. - xGoogReqIdInterceptor.checkExpectedUnaryXGoogRequestIdsAsSuffixes(wantUnaryValues); - } + xGoogReqIdInterceptor.checkExpectedUnaryXGoogRequestIds(wantUnaryValues); } }