Skip to content

Commit ff6f80e

Browse files
committed
chore(spanner): update mock spanner to not count the beginTransaction request for multiplexed sessions
1 parent d56908b commit ff6f80e

File tree

1 file changed

+10
-5
lines changed

1 file changed

+10
-5
lines changed

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

Lines changed: 10 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,7 @@
6262
import com.google.spanner.v1.PartitionReadRequest;
6363
import com.google.spanner.v1.PartitionResponse;
6464
import com.google.spanner.v1.ReadRequest;
65+
import com.google.spanner.v1.RequestOptions;
6566
import com.google.spanner.v1.ResultSet;
6667
import com.google.spanner.v1.ResultSetMetadata;
6768
import com.google.spanner.v1.ResultSetStats;
@@ -1829,7 +1830,7 @@ private ByteString getTransactionId(Session session, TransactionSelector tx) {
18291830
transactionId = null;
18301831
break;
18311832
case BEGIN:
1832-
transactionId = beginTransaction(session, tx.getBegin(), null).getId();
1833+
transactionId = beginTransaction(session, tx.getBegin(), null, null).getId();
18331834
break;
18341835
case ID:
18351836
Transaction transaction = transactions.get(tx.getId());
@@ -1895,7 +1896,7 @@ public void beginTransaction(
18951896
beginTransactionExecutionTime.simulateExecutionTime(
18961897
exceptions, stickyGlobalExceptions, freezeLock);
18971898
Transaction transaction =
1898-
beginTransaction(session, request.getOptions(), request.getMutationKey());
1899+
beginTransaction(session, request.getOptions(), request.getMutationKey(), request.getRequestOptions());
18991900
responseObserver.onNext(transaction);
19001901
responseObserver.onCompleted();
19011902
} catch (StatusRuntimeException t) {
@@ -1906,7 +1907,7 @@ public void beginTransaction(
19061907
}
19071908

19081909
private Transaction beginTransaction(
1909-
Session session, TransactionOptions options, com.google.spanner.v1.Mutation mutationKey) {
1910+
Session session, TransactionOptions options, com.google.spanner.v1.Mutation mutationKey, RequestOptions requestOptions) {
19101911
ByteString transactionId = generateTransactionName(session.getName());
19111912
Transaction.Builder builder = Transaction.newBuilder().setId(transactionId);
19121913
if (options != null && options.getModeCase() == ModeCase.READ_ONLY) {
@@ -1920,7 +1921,10 @@ private Transaction beginTransaction(
19201921
}
19211922
Transaction transaction = builder.build();
19221923
transactions.put(transaction.getId(), transaction);
1923-
transactionsStarted.add(transaction.getId());
1924+
// Do not add transaction id to transactionsStarted if this request was from background thread
1925+
if (requestOptions == null || !requestOptions.getTransactionTag().equals("multiplexed-rw-background-begin-txn")) {
1926+
transactionsStarted.add(transaction.getId());
1927+
}
19241928
isPartitionedDmlTransaction.put(
19251929
transaction.getId(), options.getModeCase() == ModeCase.PARTITIONED_DML);
19261930
if (abortNextTransaction.getAndSet(false)) {
@@ -2025,7 +2029,8 @@ public void commit(CommitRequest request, StreamObserver<CommitResponse> respons
20252029
TransactionOptions.newBuilder()
20262030
.setReadWrite(ReadWrite.getDefaultInstance())
20272031
.build(),
2028-
null);
2032+
null,
2033+
request.getRequestOptions());
20292034
} else if (request.getTransactionId() != null) {
20302035
transaction = transactions.get(request.getTransactionId());
20312036
Optional<Boolean> aborted =

0 commit comments

Comments
 (0)