@@ -78,6 +78,7 @@ import Priority = google.spanner.v1.RequestOptions.Priority;
7878import TypeCode = google . spanner . v1 . TypeCode ;
7979import NullValue = google . protobuf . NullValue ;
8080import IsolationLevel = google . spanner . v1 . TransactionOptions . IsolationLevel ;
81+ import ReadLockMode = google . spanner . v1 . TransactionOptions . ReadWrite . ReadLockMode ;
8182import { SessionFactory } from '../src/session-factory' ;
8283import { MultiplexedSession } from '../src/multiplexed-session' ;
8384import { WriteAtLeastOnceOptions } from '../src/database' ;
@@ -601,7 +602,7 @@ describe('Spanner with mock server', () => {
601602 const database = newTestDatabase ( ) ;
602603 await database . runTransactionAsync (
603604 {
604- optimisticLock : true ,
605+ readLockMode : ReadLockMode . OPTIMISTIC ,
605606 requestOptions : { transactionTag : 'transaction-tag' } ,
606607 } ,
607608 async tx => {
@@ -5000,7 +5001,7 @@ describe('Spanner with mock server', () => {
50005001 const database = newTestDatabase ( ) ;
50015002 await database . runTransactionAsync (
50025003 {
5003- optimisticLock : true ,
5004+ readLockMode : ReadLockMode . OPTIMISTIC ,
50045005 } ,
50055006 async tx => {
50065007 await tx ! . run ( selectSql ) ;
@@ -5105,7 +5106,7 @@ describe('Spanner with mock server', () => {
51055106 const database = newTestDatabase ( ) ;
51065107 await database . runTransactionAsync (
51075108 {
5108- optimisticLock : true ,
5109+ readLockMode : ReadLockMode . OPTIMISTIC ,
51095110 excludeTxnFromChangeStreams : true ,
51105111 } ,
51115112 async tx => {
@@ -5167,22 +5168,27 @@ describe('Spanner with mock server', () => {
51675168
51685169 it ( 'should use optimistic lock for runTransaction' , done => {
51695170 const database = newTestDatabase ( ) ;
5170- database . runTransaction ( { optimisticLock : true } , async ( err , tx ) => {
5171- assert . ifError ( err ) ;
5172- await tx ! . run ( selectSql ) ;
5173- await tx ! . commit ( ) ;
5174- await database . close ( ) ;
5171+ database . runTransaction (
5172+ {
5173+ readLockMode : ReadLockMode . OPTIMISTIC ,
5174+ } ,
5175+ async ( err , tx ) => {
5176+ assert . ifError ( err ) ;
5177+ await tx ! . run ( selectSql ) ;
5178+ await tx ! . commit ( ) ;
5179+ await database . close ( ) ;
51755180
5176- const request = spannerMock . getRequests ( ) . find ( val => {
5177- return ( val as v1 . ExecuteSqlRequest ) . sql ;
5178- } ) as v1 . ExecuteSqlRequest ;
5179- assert . ok ( request , 'no ExecuteSqlRequest found' ) ;
5180- assert . strictEqual (
5181- request . transaction ! . begin ! . readWrite ! . readLockMode ,
5182- 'OPTIMISTIC' ,
5183- ) ;
5184- done ( ) ;
5185- } ) ;
5181+ const request = spannerMock . getRequests ( ) . find ( val => {
5182+ return ( val as v1 . ExecuteSqlRequest ) . sql ;
5183+ } ) as v1 . ExecuteSqlRequest ;
5184+ assert . ok ( request , 'no ExecuteSqlRequest found' ) ;
5185+ assert . strictEqual (
5186+ request . transaction ! . begin ! . readWrite ! . readLockMode ,
5187+ 'OPTIMISTIC' ,
5188+ ) ;
5189+ done ( ) ;
5190+ } ,
5191+ ) ;
51865192 } ) ;
51875193
51885194 it ( 'should use exclude transaction from change stream for runTransaction' , done => {
@@ -5234,7 +5240,7 @@ describe('Spanner with mock server', () => {
52345240 it ( 'should use optimistic lock and transaction tag for getTransaction' , async ( ) => {
52355241 const database = newTestDatabase ( ) ;
52365242 const promise = await database . getTransaction ( {
5237- optimisticLock : true ,
5243+ readLockMode : ReadLockMode . OPTIMISTIC ,
52385244 requestOptions : { transactionTag : 'transaction-tag' } ,
52395245 } ) ;
52405246 const transaction = promise [ 0 ] ;
@@ -5275,11 +5281,16 @@ describe('Spanner with mock server', () => {
52755281 const database = newTestDatabase ( { min : 1 , max : 1 } ) ;
52765282 let session1 ;
52775283 let session2 ;
5278- await database . runTransactionAsync ( { optimisticLock : true } , async tx => {
5279- session1 = tx ! . session . id ;
5280- await tx ! . run ( selectSql ) ;
5281- await tx . commit ( ) ;
5282- } ) ;
5284+ await database . runTransactionAsync (
5285+ {
5286+ readLockMode : ReadLockMode . OPTIMISTIC ,
5287+ } ,
5288+ async tx => {
5289+ session1 = tx ! . session . id ;
5290+ await tx ! . run ( selectSql ) ;
5291+ await tx . commit ( ) ;
5292+ } ,
5293+ ) ;
52835294 spannerMock . resetRequests ( ) ;
52845295 await database . runTransactionAsync ( async tx => {
52855296 session2 = tx ! . session . id ;
@@ -5435,15 +5446,20 @@ describe('Spanner with mock server', () => {
54355446 it ( 'should use beginTransaction on retry with optimistic lock' , async ( ) => {
54365447 const database = newTestDatabase ( ) ;
54375448 let attempts = 0 ;
5438- await database . runTransactionAsync ( { optimisticLock : true } , async tx => {
5439- await tx ! . run ( selectSql ) ;
5440- if ( ! attempts ) {
5441- spannerMock . abortTransaction ( tx ) ;
5442- }
5443- attempts ++ ;
5444- await tx ! . run ( insertSql ) ;
5445- await tx . commit ( ) ;
5446- } ) ;
5449+ await database . runTransactionAsync (
5450+ {
5451+ readLockMode : ReadLockMode . OPTIMISTIC ,
5452+ } ,
5453+ async tx => {
5454+ await tx ! . run ( selectSql ) ;
5455+ if ( ! attempts ) {
5456+ spannerMock . abortTransaction ( tx ) ;
5457+ }
5458+ attempts ++ ;
5459+ await tx ! . run ( insertSql ) ;
5460+ await tx . commit ( ) ;
5461+ } ,
5462+ ) ;
54475463 await database . close ( ) ;
54485464
54495465 const beginTxnRequest = spannerMock
0 commit comments