2525from google .cloud .spanner_v1 .session import Session
2626from google .cloud .spanner_v1 .transaction import Transaction
2727
28- from google .cloud .spanner_v1 .types import Session as SessionPB
29- from google .cloud .spanner_v1 .types import Transaction as TransactionPB
30- from google .cloud .spanner_v1 .types import CommitResponse as CommitResponsePB
28+ from google .cloud .spanner_v1 .types import (
29+ CommitResponse as CommitResponsePB ,
30+ MultiplexedSessionPrecommitToken as PrecommitTokenPB ,
31+ Session as SessionPB ,
32+ Transaction as TransactionPB ,
33+ )
3134
3235from google .cloud ._helpers import _datetime_to_pb_timestamp
3336from tests ._helpers import HAS_OPENTELEMETRY_INSTALLED , get_test_ot_exporter
3942_INSTANCE_ID = "default-instance-id"
4043_DATABASE_ID = "default-database-id"
4144_SESSION_ID = "default-session-id"
42- _TRANSACTION_ID = b"default-transaction-id"
4345
4446_PROJECT_NAME = "projects/" + _PROJECT_ID
4547_INSTANCE_NAME = _PROJECT_NAME + "/instances/" + _INSTANCE_ID
4648_DATABASE_NAME = _INSTANCE_NAME + "/databases/" + _DATABASE_ID
4749_SESSION_NAME = _DATABASE_NAME + "/sessions/" + _SESSION_ID
4850
51+ _TRANSACTION_ID = b"default-transaction-id"
52+ _PRECOMMIT_TOKEN = b"default-precommit-token"
53+ _SEQUENCE_NUMBER = - 1
4954_TIMESTAMP = _datetime_to_pb_timestamp (datetime .now ())
5055
5156# Protocol buffers
5257# ----------------
5358
5459
55- def _build_commit_response_pb (** kwargs ) -> CommitResponsePB :
60+ def build_commit_response_pb (** kwargs ) -> CommitResponsePB :
5661 """Builds and returns a commit response protocol buffer for testing using the given arguments.
5762 If an expected argument is not provided, a default value will be used."""
5863
@@ -62,6 +67,20 @@ def _build_commit_response_pb(**kwargs) -> CommitResponsePB:
6267 return CommitResponsePB (** kwargs )
6368
6469
70+ def build_precommit_token_pb (** kwargs ) -> PrecommitTokenPB :
71+ """Builds and returns a multiplexed session precommit token protocol buffer for
72+ testing using the given arguments. If an expected argument is not provided, a
73+ default value will be used."""
74+
75+ if "precommit_token" not in kwargs :
76+ kwargs ["precommit_token" ] = _PRECOMMIT_TOKEN
77+
78+ if "seq_num" not in kwargs :
79+ kwargs ["seq_num" ] = _SEQUENCE_NUMBER
80+
81+ return PrecommitTokenPB (** kwargs )
82+
83+
6584def build_session_pb (** kwargs ) -> SessionPB :
6685 """Builds and returns a session protocol buffer for testing using the given arguments.
6786 If an expected argument is not provided, a default value will be used."""
@@ -195,7 +214,7 @@ def build_spanner_api() -> SpannerClient:
195214
196215 # Mock API calls with default return values.
197216 api .begin_transaction .return_value = build_transaction_pb ()
198- api .commit .return_value = _build_commit_response_pb ()
217+ api .commit .return_value = build_commit_response_pb ()
199218 api .create_session .return_value = build_session_pb ()
200219
201220 return api
0 commit comments