@@ -627,165 +627,6 @@ def test_transaction_read_and_insert_or_update_then_commit(self):
627627 rows = list (session .read (self .TABLE , self .COLUMNS , self .ALL ))
628628 self ._check_rows_data (rows )
629629
630- def _generate_insert_statements (self ):
631- insert_template = (
632- 'INSERT INTO {table} ({column_list}) '
633- 'VALUES ({row_data})'
634- )
635- for row in self .ROW_DATA :
636- yield insert_template .format (
637- table = self .TABLE ,
638- column_list = ', ' .join (self .COLUMNS ),
639- row_data = '{}, "{}", "{}", "{}"' .format (* row )
640- )
641-
642- @RetryErrors (exception = exceptions .ServerError )
643- @RetryErrors (exception = exceptions .Conflict )
644- def test_transaction_execute_sql_w_dml_read_rollback (self ):
645- retry = RetryInstanceState (_has_all_ddl )
646- retry (self ._db .reload )()
647-
648- session = self ._db .session ()
649- session .create ()
650- self .to_delete .append (session )
651-
652- with session .batch () as batch :
653- batch .delete (self .TABLE , self .ALL )
654-
655- transaction = session .transaction ()
656- transaction .begin ()
657-
658- rows = list (
659- transaction .read (self .TABLE , self .COLUMNS , self .ALL ))
660- self .assertEqual (rows , [])
661-
662- for insert_statement in self ._generate_insert_statements ():
663- result = transaction .execute_sql (insert_statement )
664- list (result ) # iterate to get stats
665- self .assertEqual (result .stats .row_count_exact , 1 )
666-
667- # Rows inserted via DML *can* be read before commit.
668- during_rows = list (
669- transaction .read (self .TABLE , self .COLUMNS , self .ALL ))
670- self ._check_rows_data (during_rows )
671-
672- transaction .rollback ()
673-
674- rows = list (session .read (self .TABLE , self .COLUMNS , self .ALL ))
675- self ._check_rows_data (rows , [])
676-
677- @RetryErrors (exception = exceptions .ServerError )
678- @RetryErrors (exception = exceptions .Conflict )
679- def test_transaction_execute_update_read_commit (self ):
680- retry = RetryInstanceState (_has_all_ddl )
681- retry (self ._db .reload )()
682-
683- session = self ._db .session ()
684- session .create ()
685- self .to_delete .append (session )
686-
687- with session .batch () as batch :
688- batch .delete (self .TABLE , self .ALL )
689-
690- with session .transaction () as transaction :
691- rows = list (transaction .read (self .TABLE , self .COLUMNS , self .ALL ))
692- self .assertEqual (rows , [])
693-
694- for insert_statement in self ._generate_insert_statements ():
695- row_count = transaction .execute_update (insert_statement )
696- self .assertEqual (row_count , 1 )
697-
698- # Rows inserted via DML *can* be read before commit.
699- during_rows = list (
700- transaction .read (self .TABLE , self .COLUMNS , self .ALL ))
701- self ._check_rows_data (during_rows )
702-
703- rows = list (session .read (self .TABLE , self .COLUMNS , self .ALL ))
704- self ._check_rows_data (rows )
705-
706- @RetryErrors (exception = exceptions .ServerError )
707- @RetryErrors (exception = exceptions .Conflict )
708- def test_transaction_execute_update_then_insert_commit (self ):
709- retry = RetryInstanceState (_has_all_ddl )
710- retry (self ._db .reload )()
711-
712- session = self ._db .session ()
713- session .create ()
714- self .to_delete .append (session )
715-
716- with session .batch () as batch :
717- batch .delete (self .TABLE , self .ALL )
718-
719- insert_statement = list (self ._generate_insert_statements ())[0 ]
720-
721- with session .transaction () as transaction :
722- rows = list (transaction .read (self .TABLE , self .COLUMNS , self .ALL ))
723- self .assertEqual (rows , [])
724-
725- row_count = transaction .execute_update (insert_statement )
726- self .assertEqual (row_count , 1 )
727-
728- transaction .insert (self .TABLE , self .COLUMNS , self .ROW_DATA [1 :])
729-
730- rows = list (session .read (self .TABLE , self .COLUMNS , self .ALL ))
731- self ._check_rows_data (rows )
732-
733- def test_execute_partitioned_dml (self ):
734- retry = RetryInstanceState (_has_all_ddl )
735- retry (self ._db .reload )()
736-
737- delete_statement = 'DELETE FROM {} WHERE true' .format (self .TABLE )
738-
739- def _setup_table (txn ):
740- txn .execute_update (delete_statement )
741- for insert_statement in self ._generate_insert_statements ():
742- txn .execute_update (insert_statement )
743-
744- committed = self ._db .run_in_transaction (_setup_table )
745-
746- with self ._db .snapshot (read_timestamp = committed ) as snapshot :
747- before_pdml = list (snapshot .read (
748- self .TABLE , self .COLUMNS , self .ALL ))
749-
750- self ._check_rows_data (before_pdml )
751-
752- nonesuch = 'nonesuch@example.com'
753- target = 'phred@example.com'
754- update_statement = (
755- 'UPDATE {table} SET {table}.email = @email '
756- 'WHERE {table}.email = @target' ).format (
757- table = self .TABLE )
758-
759- row_count = self ._db .execute_partitioned_dml (
760- update_statement ,
761- params = {
762- 'email' : nonesuch ,
763- 'target' : target ,
764- },
765- param_types = {
766- 'email' : Type (code = STRING ),
767- 'target' : Type (code = STRING ),
768- },
769- )
770- self .assertEqual (row_count , 1 )
771-
772- row = self .ROW_DATA [0 ]
773- updated = [row [:3 ] + (nonesuch ,)] + list (self .ROW_DATA [1 :])
774-
775- with self ._db .snapshot (read_timestamp = committed ) as snapshot :
776- after_update = list (snapshot .read (
777- self .TABLE , self .COLUMNS , self .ALL ))
778- self ._check_rows_data (after_update , updated )
779-
780- row_count = self ._db .execute_partitioned_dml (delete_statement )
781- self .assertEqual (row_count , len (self .ROW_DATA ))
782-
783- with self ._db .snapshot (read_timestamp = committed ) as snapshot :
784- after_delete = list (snapshot .read (
785- self .TABLE , self .COLUMNS , self .ALL ))
786-
787- self ._check_rows_data (after_delete , [])
788-
789630 def _transaction_concurrency_helper (self , unit_of_work , pkey ):
790631 INITIAL_VALUE = 123
791632 NUM_THREADS = 3 # conforms to equivalent Java systest.
0 commit comments