@@ -877,6 +877,9 @@ func checkReqsForReadOptions(t *testing.T, server InMemSpannerServer, ro ReadOpt
877
877
if got , want := sqlReq .OrderBy , ro .OrderBy ; got != want {
878
878
t .Fatalf ("OrderBy mismatch, got %v, want %v" , got , want )
879
879
}
880
+ if got , want := sqlReq .LockHint , ro .LockHint ; got != want {
881
+ t .Fatalf ("LockHint mismatch, got %v, want %v" , got , want )
882
+ }
880
883
}
881
884
882
885
func checkReqsForTransactionOptions (t * testing.T , server InMemSpannerServer , txo TransactionOptions ) {
@@ -2143,6 +2146,89 @@ func TestClient_ReadWriteTransaction_Query_QueryOptions(t *testing.T) {
2143
2146
}
2144
2147
}
2145
2148
2149
+ func TestClient_ReadWriteTransaction_LockHintOptions (t * testing.T ) {
2150
+ readOptionsTestCases := []ReadOptionsTestCase {
2151
+ {
2152
+ name : "Client level" ,
2153
+ client : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_EXCLUSIVE },
2154
+ want : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_EXCLUSIVE },
2155
+ },
2156
+ {
2157
+ name : "Read level" ,
2158
+ client : & ReadOptions {},
2159
+ read : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_EXCLUSIVE },
2160
+ want : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_EXCLUSIVE },
2161
+ },
2162
+ {
2163
+ name : "Read level has precedence than client level" ,
2164
+ client : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_SHARED },
2165
+ read : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_EXCLUSIVE },
2166
+ want : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_EXCLUSIVE },
2167
+ },
2168
+ {
2169
+ name : "Client level has precendence when LOCK_HINT_UNSPECIFIED at read level" ,
2170
+ client : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_EXCLUSIVE },
2171
+ read : & ReadOptions {},
2172
+ want : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_EXCLUSIVE },
2173
+ },
2174
+ }
2175
+
2176
+ for _ , tt := range readOptionsTestCases {
2177
+ t .Run (tt .name , func (t * testing.T ) {
2178
+ ctx := context .Background ()
2179
+ server , client , teardown := setupMockedTestServerWithConfig (t , ClientConfig {ReadOptions : * tt .client })
2180
+ defer teardown ()
2181
+
2182
+ _ , err := client .ReadWriteTransaction (ctx , func (ctx context.Context , tx * ReadWriteTransaction ) error {
2183
+ var iter * RowIterator
2184
+ if tt .read == nil {
2185
+ iter = tx .Read (ctx , "Albums" , KeySets (Key {"foo" }), []string {"SingerId" , "AlbumId" , "AlbumTitle" })
2186
+ } else {
2187
+ iter = tx .ReadWithOptions (ctx , "Albums" , KeySets (Key {"foo" }), []string {"SingerId" , "AlbumId" , "AlbumTitle" }, tt .read )
2188
+ }
2189
+ testReadOptions (t , iter , server .TestSpanner , * tt .want )
2190
+ return nil
2191
+ })
2192
+ if err != nil {
2193
+ t .Fatal (err )
2194
+ }
2195
+ })
2196
+ }
2197
+ }
2198
+
2199
+ func TestClient_ReadOnlyTransaction_LockHintOptions (t * testing.T ) {
2200
+ readOptionsTestCases := []ReadOptionsTestCase {
2201
+ {
2202
+ name : "Client level Lock hint overiden in request level" ,
2203
+ client : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_EXCLUSIVE },
2204
+ read : & ReadOptions {},
2205
+ want : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_UNSPECIFIED },
2206
+ },
2207
+ {
2208
+ name : "Request level" ,
2209
+ client : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_EXCLUSIVE },
2210
+ read : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_SHARED },
2211
+ want : & ReadOptions {LockHint : sppb .ReadRequest_LOCK_HINT_SHARED },
2212
+ },
2213
+ }
2214
+
2215
+ for _ , tt := range readOptionsTestCases {
2216
+ t .Run (tt .name , func (t * testing.T ) {
2217
+ ctx := context .Background ()
2218
+ server , client , teardown := setupMockedTestServerWithConfig (t , ClientConfig {ReadOptions : * tt .client })
2219
+ defer teardown ()
2220
+
2221
+ for _ , tx := range []* ReadOnlyTransaction {
2222
+ client .Single (),
2223
+ client .ReadOnlyTransaction (),
2224
+ } {
2225
+ iter := tx .ReadWithOptions (ctx , "Albums" , KeySets (Key {"foo" }), []string {"SingerId" , "AlbumId" , "AlbumTitle" }, tt .read )
2226
+ testReadOptions (t , iter , server .TestSpanner , * tt .want )
2227
+ }
2228
+
2229
+ })
2230
+ }
2231
+ }
2146
2232
func TestClient_ReadWriteTransaction_Query_ReadOptions (t * testing.T ) {
2147
2233
for _ , tt := range readOptionsTestCases () {
2148
2234
t .Run (tt .name , func (t * testing.T ) {
0 commit comments