Skip to content

Commit

Permalink
feat: Update transaction.proto to include different lock modes (#845)
Browse files Browse the repository at this point in the history
* feat: Update transaction.proto to include different lock modes

PiperOrigin-RevId: 481838475

Source-Link: googleapis/googleapis@922f1f3

Source-Link: googleapis/googleapis-gen@bf32c6e
Copy-Tag: eyJwIjoiLmdpdGh1Yi8uT3dsQm90LnlhbWwiLCJoIjoiYmYzMmM2ZTQxM2Q0ZDdmZDNjOTliNzI1ZmFiNjUzZWI5ODNkOWRkNiJ9

* 🦉 Updates from OwlBot post-processor

See https://github.com/googleapis/repo-automation-bots/blob/main/packages/owl-bot/README.md

Co-authored-by: Owl Bot <gcf-owl-bot[bot]@users.noreply.github.com>
  • Loading branch information
gcf-owl-bot[bot] and gcf-owl-bot[bot] committed Oct 18, 2022
1 parent 0aa4cad commit c191296
Show file tree
Hide file tree
Showing 2 changed files with 73 additions and 12 deletions.
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

0 comments on commit c191296

Please sign in to comment.