Skip to content

Commit e5ef71e

Browse files
committed
chore(spanner): update documentation
1 parent 00360f0 commit e5ef71e

File tree

1 file changed

+27
-9
lines changed

1 file changed

+27
-9
lines changed

google-cloud-spanner/src/test/java/com/google/cloud/spanner/MultiplexedSessionDatabaseClientMockServerTest.java

Lines changed: 27 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2171,9 +2171,17 @@ public void testBatchWriteAtLeastOnce() {
21712171
}
21722172

21732173
@Test
2174-
public void testReadWriteTransactionUsingTransactionManager_SetsTransactionID_DuringAborted() {
2175-
// Whenever an ABORTED exception occurs, the transaction ID that caused the ABORT should be set
2176-
// in the AbortedException class.
2174+
public void
2175+
testRWTransactionWithTransactionManager_CommitAborted_SetsTransactionId_AndUsedInNewInstance() {
2176+
// The below test verifies the behaviour of begin(AbortedException) method which is used to
2177+
// maintain transaction priority if resetForRetry() is not called.
2178+
2179+
// This test performs the following steps:
2180+
// 1. Simulates an ABORTED exception during commit and verifies that the transaction ID is
2181+
// included in the AbortedException.
2182+
// 2. Passes the ABORTED exception to the begin(AbortedException) method of a new
2183+
// TransactionManager, and verifies that the transaction ID from the failed transaction is sent
2184+
// during the inline begin of the first request.
21772185
DatabaseClientImpl client =
21782186
(DatabaseClientImpl) spanner.getDatabaseClient(DatabaseId.of("p", "i", "d"));
21792187
// Force the Commit RPC to return Aborted the first time it is called. The exception is cleared
@@ -2202,11 +2210,12 @@ public void testReadWriteTransactionUsingTransactionManager_SetsTransactionID_Du
22022210
exception = e;
22032211
}
22042212
}
2213+
// Verify that the transactionID of the aborted transaction is set.
22052214
assertNotNull(abortedTransactionID);
22062215
assertNotNull(exception);
22072216
mockSpanner.clearRequests();
22082217

2209-
// Use AbortedException while creating a new instance of TransactionManager
2218+
// Pass AbortedException while invoking begin on the new manager instance.
22102219
try (TransactionManager manager = client.transactionManager()) {
22112220
TransactionContext transaction = manager.begin(exception);
22122221
while (true) {
@@ -2226,6 +2235,8 @@ public void testReadWriteTransactionUsingTransactionManager_SetsTransactionID_Du
22262235
}
22272236
}
22282237

2238+
// Verify that the ExecuteSqlRequest with the inline begin passes the transactionID of the
2239+
// previously aborted transaction.
22292240
List<ExecuteSqlRequest> executeSqlRequests =
22302241
mockSpanner.getRequestsOfType(ExecuteSqlRequest.class);
22312242
assertEquals(1, executeSqlRequests.size());
@@ -2253,9 +2264,13 @@ public void testReadWriteTransactionUsingTransactionManager_SetsTransactionID_Du
22532264

22542265
@Test
22552266
public void
2256-
testReadWriteTransactionUsingTransactionManager_SetsTransactionID_DuringAbortedInExecuteSql() {
2257-
// Whenever an ABORTED exception occurs, the transaction ID that caused the ABORT should be set
2258-
// in the AbortedException class.
2267+
testRWTransactionWithTransactionManager_ExecuteSQLAborted_SetsTransactionId_AndUsedInNewInstance() {
2268+
// This test performs the following steps:
2269+
// 1. Simulates an ABORTED exception during ExecuteSQL and verifies that the transaction ID is
2270+
// included in the AbortedException.
2271+
// 2. Passes the ABORTED exception to the begin(AbortedException) method of a new
2272+
// TransactionManager, and verifies that the transaction ID from the failed transaction is sent
2273+
// during the inline begin of the first request.
22592274
DatabaseClientImpl client =
22602275
(DatabaseClientImpl) spanner.getDatabaseClient(DatabaseId.of("p", "i", "d"));
22612276

@@ -2271,6 +2286,7 @@ public void testReadWriteTransactionUsingTransactionManager_SetsTransactionID_Du
22712286
}
22722287
}
22732288

2289+
// Simulate an ABORTED in next ExecuteSQL request.
22742290
mockSpanner.setExecuteStreamingSqlExecutionTime(
22752291
SimulatedExecutionTime.ofException(
22762292
mockSpanner.createAbortedException(ByteString.copyFromUtf8("test"))));
@@ -2290,12 +2306,12 @@ public void testReadWriteTransactionUsingTransactionManager_SetsTransactionID_Du
22902306
exception = e;
22912307
}
22922308
}
2309+
// Verify that the transactionID of the aborted transaction is set.
22932310
assertNotNull(abortedTransactionID);
22942311
assertNotNull(exception);
22952312
mockSpanner.clearRequests();
22962313

2297-
// Use AbortedException while creating a new instance of TransactionManager
2298-
2314+
// Pass AbortedException while invoking begin on the new manager instance.
22992315
try (TransactionManager manager = client.transactionManager()) {
23002316
TransactionContext transaction = manager.begin(exception);
23012317
while (true) {
@@ -2315,6 +2331,8 @@ public void testReadWriteTransactionUsingTransactionManager_SetsTransactionID_Du
23152331
}
23162332
}
23172333

2334+
// Verify that the ExecuteSqlRequest with inline begin includes the transaction ID from the
2335+
// previously aborted transaction.
23182336
List<ExecuteSqlRequest> executeSqlRequests =
23192337
mockSpanner.getRequestsOfType(ExecuteSqlRequest.class);
23202338
assertEquals(1, executeSqlRequests.size());

0 commit comments

Comments
 (0)