@@ -8358,6 +8358,94 @@ describe('Spanner', () => {
83588358 deadlineErrorInsteadOfAbort ( done , PG_DATABASE , postgreSqlTable ) ;
83598359 } ) ;
83608360 } ) ;
8361+
8362+ describe ( 'batch transactions' , ( ) => {
8363+ before ( done => {
8364+ if ( ! IS_EMULATOR_ENABLED ) {
8365+ DATABASE . runTransaction ( ( err , transaction ) => {
8366+ assert . ifError ( err ) ;
8367+
8368+ transaction ! . runUpdate (
8369+ {
8370+ sql :
8371+ 'INSERT INTO ' +
8372+ TABLE_NAME +
8373+ ' (Key, StringValue) VALUES(@key, @str)' ,
8374+ params : {
8375+ key : 'k998' ,
8376+ str : 'abc' ,
8377+ } ,
8378+ } ,
8379+ err => {
8380+ assert . ifError ( err ) ;
8381+ transaction ! . commit ( done ) ;
8382+ }
8383+ ) ;
8384+ } ) ;
8385+ } else {
8386+ done ( ) ;
8387+ }
8388+ } ) ;
8389+
8390+ it ( 'should create and execute a query partition' , function ( done ) {
8391+ if ( IS_EMULATOR_ENABLED ) {
8392+ this . skip ( ) ;
8393+ }
8394+ const selectQuery = {
8395+ sql : 'SELECT * FROM TxnTable where Key = "k998"' ,
8396+ } ;
8397+
8398+ let row_count = 0 ;
8399+ DATABASE . createBatchTransaction ( ( err , transaction ) => {
8400+ assert . ifError ( err ) ;
8401+ transaction ! . createQueryPartitions ( selectQuery , ( err , partitions ) => {
8402+ assert . ifError ( err ) ;
8403+ assert . deepStrictEqual ( partitions . length , 1 ) ;
8404+ partitions . forEach ( partition => {
8405+ transaction ! . execute ( partition , ( err , results ) => {
8406+ assert . ifError ( err ) ;
8407+ row_count += results . map ( row => row . toJSON ( ) ) . length ;
8408+ assert . deepStrictEqual ( row_count , 1 ) ;
8409+ transaction ! . close ( ) ;
8410+ done ( ) ;
8411+ } ) ;
8412+ } ) ;
8413+ } ) ;
8414+ } ) ;
8415+ } ) ;
8416+
8417+ it ( 'should create and execute a read partition' , function ( done ) {
8418+ if ( IS_EMULATOR_ENABLED ) {
8419+ this . skip ( ) ;
8420+ }
8421+ const key = 'k998' ;
8422+ const QUERY = {
8423+ table : googleSqlTable . name ,
8424+ // Set databoostenabled to true for enabling serveless analytics.
8425+ dataBoostEnabled : false ,
8426+ keys : [ key ] ,
8427+ columns : [ 'Key' ] ,
8428+ } ;
8429+
8430+ let read_row_count = 0 ;
8431+ DATABASE . createBatchTransaction ( ( err , transaction ) => {
8432+ assert . ifError ( err ) ;
8433+ transaction ! . createReadPartitions ( QUERY , ( err , partitions ) => {
8434+ assert . ifError ( err ) ;
8435+ assert . deepStrictEqual ( partitions . length , 1 ) ;
8436+ partitions . forEach ( partition => {
8437+ transaction ! . execute ( partition , ( err , results ) => {
8438+ assert . ifError ( err ) ;
8439+ read_row_count += results . map ( row => row . toJSON ( ) ) . length ;
8440+ assert . deepStrictEqual ( read_row_count , 1 ) ;
8441+ transaction ! . close ( ) ;
8442+ done ( ) ;
8443+ } ) ;
8444+ } ) ;
8445+ } ) ;
8446+ } ) ;
8447+ } ) ;
8448+ } ) ;
83618449 } ) ;
83628450} ) ;
83638451
0 commit comments