Skip to content

Commit

Permalink
feat(spanner): nit sample data refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
harshachinta committed Nov 30, 2023
1 parent e401452 commit dc94850
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 11 deletions.
8 changes: 8 additions & 0 deletions tests/system/_sample_data.py
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,14 @@
(2, "Bharney", "Rhubble", "[email protected]"),
(3, "Wylma", "Phlyntstone", "[email protected]"),
)
BATCH_WRITE_ROW_DATA = (
(1, "Phred", "Phlyntstone", "[email protected]"),
(2, "Bharney", "Rhubble", "[email protected]"),
(3, "Wylma", "Phlyntstone", "[email protected]"),
(4, "Pebbles", "Phlyntstone", "[email protected]"),
(5, "Betty", "Rhubble", "[email protected]"),
(6, "Slate", "Stephenson", "[email protected]"),
)
ALL = spanner_v1.KeySet(all_=True)
SQL = "SELECT * FROM contacts ORDER BY contact_id"

Expand Down
16 changes: 5 additions & 11 deletions tests/system/test_session_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -2523,23 +2523,17 @@ def test_partition_query(sessions_database, not_emulator):

def test_mutation_groups_insert_or_update_then_query(not_emulator, sessions_database):
sd = _sample_data
ROW_DATA = (
(1, "Phred", "Phlyntstone", "[email protected]"),
(2, "Bharney", "Rhubble", "[email protected]"),
(3, "Wylma", "Phlyntstone", "[email protected]"),
(4, "Pebbles", "Phlyntstone", "[email protected]"),
(5, "Betty", "Rhubble", "[email protected]"),
(6, "Slate", "Stephenson", "[email protected]"),
)
num_groups = 3
num_mutations_per_group = len(ROW_DATA) // num_groups
num_mutations_per_group = len(sd.BATCH_WRITE_ROW_DATA) // num_groups

with sessions_database.mutation_groups() as groups:
for i in range(num_groups):
group = groups.group()
for j in range(num_mutations_per_group):
group.insert_or_update(
sd.TABLE, sd.COLUMNS, [ROW_DATA[i * num_mutations_per_group + j]]
sd.TABLE,
sd.COLUMNS,
[sd.BATCH_WRITE_ROW_DATA[i * num_mutations_per_group + j]],
)
# Response indexes received
seen = collections.Counter()
Expand All @@ -2556,7 +2550,7 @@ def test_mutation_groups_insert_or_update_then_query(not_emulator, sessions_data
with sessions_database.snapshot() as snapshot:
rows = list(snapshot.execute_sql(sd.SQL))

sd._check_rows_data(rows, ROW_DATA)
sd._check_rows_data(rows, sd.BATCH_WRITE_ROW_DATA)


class FauxCall:
Expand Down

0 comments on commit dc94850

Please sign in to comment.