@@ -28,7 +28,7 @@ func TestKVStoreTxs(t *testing.T) {
28
28
29
29
// Test that if an action fails midway through the transaction, then
30
30
// it is rolled back.
31
- err = store .Update (func (tx KVStoreTx ) error {
31
+ err = store .Update (ctx , func (ctx context. Context , tx KVStoreTx ) error {
32
32
err := tx .Global ().Set (ctx , "test" , []byte {1 })
33
33
if err != nil {
34
34
return err
@@ -46,7 +46,7 @@ func TestKVStoreTxs(t *testing.T) {
46
46
require .Error (t , err )
47
47
48
48
var v []byte
49
- err = store .View (func (tx KVStoreTx ) error {
49
+ err = store .View (ctx , func (ctx context. Context , tx KVStoreTx ) error {
50
50
b , err := tx .Global ().Get (ctx , "test" )
51
51
if err != nil {
52
52
return err
@@ -94,7 +94,7 @@ func testTempAndPermStores(t *testing.T, featureSpecificStore bool) {
94
94
95
95
store := db .GetKVStores ("test-rule" , [4 ]byte {1 , 1 , 1 , 1 }, featureName )
96
96
97
- err = store .Update (func (tx KVStoreTx ) error {
97
+ err = store .Update (ctx , func (ctx context. Context , tx KVStoreTx ) error {
98
98
// Set an item in the temp store.
99
99
err := tx .LocalTemp ().Set (ctx , "test" , []byte {4 , 3 , 2 })
100
100
if err != nil {
@@ -112,7 +112,7 @@ func testTempAndPermStores(t *testing.T, featureSpecificStore bool) {
112
112
v1 []byte
113
113
v2 []byte
114
114
)
115
- err = store .View (func (tx KVStoreTx ) error {
115
+ err = store .View (ctx , func (ctx context. Context , tx KVStoreTx ) error {
116
116
b , err := tx .LocalTemp ().Get (ctx , "test" )
117
117
if err != nil {
118
118
return err
@@ -144,7 +144,7 @@ func testTempAndPermStores(t *testing.T, featureSpecificStore bool) {
144
144
145
145
// The temp store should no longer have the stored value but the perm
146
146
// store should .
147
- err = store .View (func (tx KVStoreTx ) error {
147
+ err = store .View (ctx , func (ctx context. Context , tx KVStoreTx ) error {
148
148
b , err := tx .LocalTemp ().Get (ctx , "test" )
149
149
if err != nil {
150
150
return err
@@ -188,29 +188,37 @@ func TestKVStoreNameSpaces(t *testing.T) {
188
188
rulesDB3 := db .GetKVStores ("test-rule" , groupID2 , "re-balance" )
189
189
190
190
// Test that the three ruleDBs share the same global space.
191
- err = rulesDB1 .Update (func (tx KVStoreTx ) error {
191
+ err = rulesDB1 .Update (ctx , func (ctx context.Context ,
192
+ tx KVStoreTx ) error {
193
+
192
194
return tx .Global ().Set (
193
195
ctx , "test-global" , []byte ("global thing!" ),
194
196
)
195
197
})
196
198
require .NoError (t , err )
197
199
198
- err = rulesDB2 .Update (func (tx KVStoreTx ) error {
200
+ err = rulesDB2 .Update (ctx , func (ctx context.Context ,
201
+ tx KVStoreTx ) error {
202
+
199
203
return tx .Global ().Set (
200
204
ctx , "test-global" , []byte ("different global thing!" ),
201
205
)
202
206
})
203
207
require .NoError (t , err )
204
208
205
- err = rulesDB3 .Update (func (tx KVStoreTx ) error {
209
+ err = rulesDB3 .Update (ctx , func (ctx context.Context ,
210
+ tx KVStoreTx ) error {
211
+
206
212
return tx .Global ().Set (
207
213
ctx , "test-global" , []byte ("yet another global thing" ),
208
214
)
209
215
})
210
216
require .NoError (t , err )
211
217
212
218
var v []byte
213
- err = rulesDB1 .View (func (tx KVStoreTx ) error {
219
+ err = rulesDB1 .View (ctx , func (ctx context.Context ,
220
+ tx KVStoreTx ) error {
221
+
214
222
b , err := tx .Global ().Get (ctx , "test-global" )
215
223
if err != nil {
216
224
return err
@@ -221,7 +229,9 @@ func TestKVStoreNameSpaces(t *testing.T) {
221
229
require .NoError (t , err )
222
230
require .True (t , bytes .Equal (v , []byte ("yet another global thing" )))
223
231
224
- err = rulesDB2 .View (func (tx KVStoreTx ) error {
232
+ err = rulesDB2 .View (ctx , func (ctx context.Context ,
233
+ tx KVStoreTx ) error {
234
+
225
235
b , err := tx .Global ().Get (ctx , "test-global" )
226
236
if err != nil {
227
237
return err
@@ -232,7 +242,9 @@ func TestKVStoreNameSpaces(t *testing.T) {
232
242
require .NoError (t , err )
233
243
require .True (t , bytes .Equal (v , []byte ("yet another global thing" )))
234
244
235
- err = rulesDB3 .View (func (tx KVStoreTx ) error {
245
+ err = rulesDB3 .View (ctx , func (ctx context.Context ,
246
+ tx KVStoreTx ) error {
247
+
236
248
b , err := tx .Global ().Get (ctx , "test-global" )
237
249
if err != nil {
238
250
return err
@@ -244,22 +256,30 @@ func TestKVStoreNameSpaces(t *testing.T) {
244
256
require .True (t , bytes .Equal (v , []byte ("yet another global thing" )))
245
257
246
258
// Test that the feature space is not shared by any of the dbs.
247
- err = rulesDB1 .Update (func (tx KVStoreTx ) error {
259
+ err = rulesDB1 .Update (ctx , func (ctx context.Context ,
260
+ tx KVStoreTx ) error {
261
+
248
262
return tx .Local ().Set (ctx , "count" , []byte ("1" ))
249
263
})
250
264
require .NoError (t , err )
251
265
252
- err = rulesDB2 .Update (func (tx KVStoreTx ) error {
266
+ err = rulesDB2 .Update (ctx , func (ctx context.Context ,
267
+ tx KVStoreTx ) error {
268
+
253
269
return tx .Local ().Set (ctx , "count" , []byte ("2" ))
254
270
})
255
271
require .NoError (t , err )
256
272
257
- err = rulesDB3 .Update (func (tx KVStoreTx ) error {
273
+ err = rulesDB3 .Update (ctx , func (ctx context.Context ,
274
+ tx KVStoreTx ) error {
275
+
258
276
return tx .Local ().Set (ctx , "count" , []byte ("3" ))
259
277
})
260
278
require .NoError (t , err )
261
279
262
- err = rulesDB1 .View (func (tx KVStoreTx ) error {
280
+ err = rulesDB1 .View (ctx , func (ctx context.Context ,
281
+ tx KVStoreTx ) error {
282
+
263
283
b , err := tx .Local ().Get (ctx , "count" )
264
284
if err != nil {
265
285
return err
@@ -270,7 +290,9 @@ func TestKVStoreNameSpaces(t *testing.T) {
270
290
require .NoError (t , err )
271
291
require .True (t , bytes .Equal (v , []byte ("1" )))
272
292
273
- err = rulesDB2 .View (func (tx KVStoreTx ) error {
293
+ err = rulesDB2 .View (ctx , func (ctx context.Context ,
294
+ tx KVStoreTx ) error {
295
+
274
296
b , err := tx .Local ().Get (ctx , "count" )
275
297
if err != nil {
276
298
return err
@@ -281,7 +303,9 @@ func TestKVStoreNameSpaces(t *testing.T) {
281
303
require .NoError (t , err )
282
304
require .True (t , bytes .Equal (v , []byte ("2" )))
283
305
284
- err = rulesDB3 .View (func (tx KVStoreTx ) error {
306
+ err = rulesDB3 .View (ctx , func (ctx context.Context ,
307
+ tx KVStoreTx ) error {
308
+
285
309
b , err := tx .Local ().Get (ctx , "count" )
286
310
if err != nil {
287
311
return err
@@ -299,22 +323,30 @@ func TestKVStoreNameSpaces(t *testing.T) {
299
323
rulesDB2 = db .GetKVStores ("test-rule" , groupID1 , "" )
300
324
rulesDB3 = db .GetKVStores ("test-rule" , groupID2 , "" )
301
325
302
- err = rulesDB1 .Update (func (tx KVStoreTx ) error {
326
+ err = rulesDB1 .Update (ctx , func (ctx context.Context ,
327
+ tx KVStoreTx ) error {
328
+
303
329
return tx .Local ().Set (ctx , "test" , []byte ("thing 1" ))
304
330
})
305
331
require .NoError (t , err )
306
332
307
- err = rulesDB2 .Update (func (tx KVStoreTx ) error {
333
+ err = rulesDB2 .Update (ctx , func (ctx context.Context ,
334
+ tx KVStoreTx ) error {
335
+
308
336
return tx .Local ().Set (ctx , "test" , []byte ("thing 2" ))
309
337
})
310
338
require .NoError (t , err )
311
339
312
- err = rulesDB3 .Update (func (tx KVStoreTx ) error {
340
+ err = rulesDB3 .Update (ctx , func (ctx context.Context ,
341
+ tx KVStoreTx ) error {
342
+
313
343
return tx .Local ().Set (ctx , "test" , []byte ("thing 3" ))
314
344
})
315
345
require .NoError (t , err )
316
346
317
- err = rulesDB1 .View (func (tx KVStoreTx ) error {
347
+ err = rulesDB1 .View (ctx , func (ctx context.Context ,
348
+ tx KVStoreTx ) error {
349
+
318
350
b , err := tx .Local ().Get (ctx , "test" )
319
351
if err != nil {
320
352
return err
@@ -325,7 +357,9 @@ func TestKVStoreNameSpaces(t *testing.T) {
325
357
require .NoError (t , err )
326
358
require .True (t , bytes .Equal (v , []byte ("thing 2" )))
327
359
328
- err = rulesDB2 .View (func (tx KVStoreTx ) error {
360
+ err = rulesDB2 .View (ctx , func (ctx context.Context ,
361
+ tx KVStoreTx ) error {
362
+
329
363
b , err := tx .Local ().Get (ctx , "test" )
330
364
if err != nil {
331
365
return err
@@ -336,7 +370,9 @@ func TestKVStoreNameSpaces(t *testing.T) {
336
370
require .NoError (t , err )
337
371
require .True (t , bytes .Equal (v , []byte ("thing 2" )))
338
372
339
- err = rulesDB3 .View (func (tx KVStoreTx ) error {
373
+ err = rulesDB3 .View (ctx , func (ctx context.Context ,
374
+ tx KVStoreTx ) error {
375
+
340
376
b , err := tx .Local ().Get (ctx , "test" )
341
377
if err != nil {
342
378
return err
0 commit comments