Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions google/cloud/spanner_v1/types/transaction.py
Original file line number Diff line number Diff line change
Expand Up @@ -401,8 +401,25 @@ class ReadWrite(proto.Message):
r"""Message type to initiate a read-write transaction. Currently
this transaction type has no options.

Attributes:
read_lock_mode (google.cloud.spanner_v1.types.TransactionOptions.ReadWrite.ReadLockMode):
Read lock mode for the transaction.
"""

class ReadLockMode(proto.Enum):
r"""``ReadLockMode`` is used to set the read lock mode for read-write
transactions.
"""
READ_LOCK_MODE_UNSPECIFIED = 0
PESSIMISTIC = 1
OPTIMISTIC = 2

read_lock_mode = proto.Field(
proto.ENUM,
number=1,
enum="TransactionOptions.ReadWrite.ReadLockMode",
)

class PartitionedDml(proto.Message):
r"""Message type to initiate a Partitioned DML transaction."""

Expand Down
68 changes: 56 additions & 12 deletions tests/unit/gapic/spanner_v1/test_spanner.py
Original file line number Diff line number Diff line change
Expand Up @@ -2926,7 +2926,11 @@ def test_begin_transaction_flattened():
# using the keyword arguments to the method.
client.begin_transaction(
session="session_value",
options=transaction.TransactionOptions(read_write=None),
options=transaction.TransactionOptions(
read_write=transaction.TransactionOptions.ReadWrite(
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
)
),
)

# Establish that the underlying call was made with the expected
Expand All @@ -2937,7 +2941,11 @@ def test_begin_transaction_flattened():
mock_val = "session_value"
assert arg == mock_val
arg = args[0].options
mock_val = transaction.TransactionOptions(read_write=None)
mock_val = transaction.TransactionOptions(
read_write=transaction.TransactionOptions.ReadWrite(
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
)
)
assert arg == mock_val


Expand All @@ -2952,7 +2960,11 @@ def test_begin_transaction_flattened_error():
client.begin_transaction(
spanner.BeginTransactionRequest(),
session="session_value",
options=transaction.TransactionOptions(read_write=None),
options=transaction.TransactionOptions(
read_write=transaction.TransactionOptions.ReadWrite(
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
)
),
)


Expand All @@ -2976,7 +2988,11 @@ async def test_begin_transaction_flattened_async():
# using the keyword arguments to the method.
response = await client.begin_transaction(
session="session_value",
options=transaction.TransactionOptions(read_write=None),
options=transaction.TransactionOptions(
read_write=transaction.TransactionOptions.ReadWrite(
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
)
),
)

# Establish that the underlying call was made with the expected
Expand All @@ -2987,7 +3003,11 @@ async def test_begin_transaction_flattened_async():
mock_val = "session_value"
assert arg == mock_val
arg = args[0].options
mock_val = transaction.TransactionOptions(read_write=None)
mock_val = transaction.TransactionOptions(
read_write=transaction.TransactionOptions.ReadWrite(
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
)
)
assert arg == mock_val


Expand All @@ -3003,7 +3023,11 @@ async def test_begin_transaction_flattened_error_async():
await client.begin_transaction(
spanner.BeginTransactionRequest(),
session="session_value",
options=transaction.TransactionOptions(read_write=None),
options=transaction.TransactionOptions(
read_write=transaction.TransactionOptions.ReadWrite(
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
)
),
)


Expand Down Expand Up @@ -3168,7 +3192,11 @@ def test_commit_flattened():
mutations=[
mutation.Mutation(insert=mutation.Mutation.Write(table="table_value"))
],
single_use_transaction=transaction.TransactionOptions(read_write=None),
single_use_transaction=transaction.TransactionOptions(
read_write=transaction.TransactionOptions.ReadWrite(
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
)
),
)

# Establish that the underlying call was made with the expected
Expand All @@ -3184,7 +3212,9 @@ def test_commit_flattened():
]
assert arg == mock_val
assert args[0].single_use_transaction == transaction.TransactionOptions(
read_write=None
read_write=transaction.TransactionOptions.ReadWrite(
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
)
)


Expand All @@ -3203,7 +3233,11 @@ def test_commit_flattened_error():
mutations=[
mutation.Mutation(insert=mutation.Mutation.Write(table="table_value"))
],
single_use_transaction=transaction.TransactionOptions(read_write=None),
single_use_transaction=transaction.TransactionOptions(
read_write=transaction.TransactionOptions.ReadWrite(
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
)
),
)


Expand All @@ -3229,7 +3263,11 @@ async def test_commit_flattened_async():
mutations=[
mutation.Mutation(insert=mutation.Mutation.Write(table="table_value"))
],
single_use_transaction=transaction.TransactionOptions(read_write=None),
single_use_transaction=transaction.TransactionOptions(
read_write=transaction.TransactionOptions.ReadWrite(
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
)
),
)

# Establish that the underlying call was made with the expected
Expand All @@ -3245,7 +3283,9 @@ async def test_commit_flattened_async():
]
assert arg == mock_val
assert args[0].single_use_transaction == transaction.TransactionOptions(
read_write=None
read_write=transaction.TransactionOptions.ReadWrite(
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
)
)


Expand All @@ -3265,7 +3305,11 @@ async def test_commit_flattened_error_async():
mutations=[
mutation.Mutation(insert=mutation.Mutation.Write(table="table_value"))
],
single_use_transaction=transaction.TransactionOptions(read_write=None),
single_use_transaction=transaction.TransactionOptions(
read_write=transaction.TransactionOptions.ReadWrite(
read_lock_mode=transaction.TransactionOptions.ReadWrite.ReadLockMode.PESSIMISTIC
)
),
)


Expand Down