Skip to content

Commit

Permalink
Required integration test cases for non-partitioned DML:
Browse files Browse the repository at this point in the history
- Rollback transaction after performing DML.
- Mix DML and batch-style mutations in a single commit.
  • Loading branch information
tseaver committed Sep 21, 2018
1 parent 5a9fb48 commit a71e8fb
Showing 1 changed file with 44 additions and 12 deletions.
56 changes: 44 additions & 12 deletions spanner/tests/system/test_system.py
Original file line number Diff line number Diff line change
Expand Up @@ -641,7 +641,42 @@ def _generate_insert_statements(self):

@RetryErrors(exception=exceptions.ServerError)
@RetryErrors(exception=exceptions.Conflict)
def test_transaction_execute_sql_w_dml_read_commit(self):
def test_transaction_execute_sql_w_dml_read_rollback(self):
retry = RetryInstanceState(_has_all_ddl)
retry(self._db.reload)()

session = self._db.session()
session.create()
self.to_delete.append(session)

with session.batch() as batch:
batch.delete(self.TABLE, self.ALL)

transaction = session.transaction()
transaction.begin()

rows = list(
transaction.read(self.TABLE, self.COLUMNS, self.ALL))
self.assertEqual(rows, [])

for insert_statement in self._generate_insert_statements():
result = transaction.execute_sql(insert_statement)
list(result) # iterate to get stats
self.assertEqual(result.stats.row_count_exact, 1)

# Rows inserted via DML *can* be read before commit.
during_rows = list(
transaction.read(self.TABLE, self.COLUMNS, self.ALL))
self._check_rows_data(during_rows)

transaction.rollback()

rows = list(session.read(self.TABLE, self.COLUMNS, self.ALL))
self._check_rows_data(rows, [])

@RetryErrors(exception=exceptions.ServerError)
@RetryErrors(exception=exceptions.Conflict)
def test_transaction_execute_update_read_commit(self):
retry = RetryInstanceState(_has_all_ddl)
retry(self._db.reload)()

Expand All @@ -657,9 +692,8 @@ def test_transaction_execute_sql_w_dml_read_commit(self):
self.assertEqual(rows, [])

for insert_statement in self._generate_insert_statements():
result = transaction.execute_sql(insert_statement)
list(result) # iterate to get stats
self.assertEqual(result.stats.row_count_exact, 1)
result = transaction.execute_update(insert_statement)
self.assertEqual(result.row_count_exact, 1)

# Rows inserted via DML *can* be read before commit.
during_rows = list(
Expand All @@ -671,7 +705,7 @@ def test_transaction_execute_sql_w_dml_read_commit(self):

@RetryErrors(exception=exceptions.ServerError)
@RetryErrors(exception=exceptions.Conflict)
def test_transaction_execute_update_read_commit(self):
def test_transaction_execute_update_then_insert_commit(self):
retry = RetryInstanceState(_has_all_ddl)
retry(self._db.reload)()

Expand All @@ -682,18 +716,16 @@ def test_transaction_execute_update_read_commit(self):
with session.batch() as batch:
batch.delete(self.TABLE, self.ALL)

insert_statement = list(self._generate_insert_statements())[0]

with session.transaction() as transaction:
rows = list(transaction.read(self.TABLE, self.COLUMNS, self.ALL))
self.assertEqual(rows, [])

for insert_statement in self._generate_insert_statements():
result = transaction.execute_update(insert_statement)
self.assertEqual(result.row_count_exact, 1)
result = transaction.execute_update(insert_statement)
self.assertEqual(result.row_count_exact, 1)

# Rows inserted via DML *can* be read before commit.
during_rows = list(
transaction.read(self.TABLE, self.COLUMNS, self.ALL))
self._check_rows_data(during_rows)
transaction.insert(self.TABLE, self.COLUMNS, self.ROW_DATA[1:])

rows = list(session.read(self.TABLE, self.COLUMNS, self.ALL))
self._check_rows_data(rows)
Expand Down

0 comments on commit a71e8fb

Please sign in to comment.