@@ -209,20 +209,20 @@ defmodule Mongo.SessionTest do
209
209
end
210
210
211
211
@ tag :mongo_4_2
212
- test "with_transaction " , % { top: top } do
212
+ test "transaction " , % { top: top } do
213
213
coll = "dogs_with_commit_transaction"
214
214
215
215
Mongo . insert_one ( top , coll , % { name: "Wuff" } )
216
216
Mongo . delete_many ( top , coll , % { } )
217
217
218
- Session . with_transaction (
218
+ Mongo . transaction (
219
219
top ,
220
- fn opts ->
221
- { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Greta" } , opts )
220
+ fn ->
221
+ { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Greta" } )
222
222
assert id != nil
223
- { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Waldo" } , opts )
223
+ { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Waldo" } )
224
224
assert id != nil
225
- { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Tom" } , opts )
225
+ { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Tom" } )
226
226
assert id != nil
227
227
{ :ok , :ok }
228
228
end ,
@@ -233,20 +233,20 @@ defmodule Mongo.SessionTest do
233
233
end
234
234
235
235
@ tag :mongo_4_2
236
- test "with_transaction_causal_consistency " , % { top: top } do
236
+ test "transaction_causal_consistency " , % { top: top } do
237
237
coll = "dogs_with_commit_transaction_causal_consistency"
238
238
239
239
Mongo . insert_one ( top , coll , % { name: "Wuff" } )
240
240
Mongo . delete_many ( top , coll , % { } )
241
241
242
- Session . with_transaction (
242
+ Mongo . transaction (
243
243
top ,
244
- fn opts ->
245
- { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Greta" } , opts )
244
+ fn ->
245
+ { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Greta" } )
246
246
assert id != nil
247
- { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Waldo" } , opts )
247
+ { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Waldo" } )
248
248
assert id != nil
249
- { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Tom" } , opts )
249
+ { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Tom" } )
250
250
assert id != nil
251
251
{ :ok , :ok }
252
252
end ,
@@ -258,21 +258,21 @@ defmodule Mongo.SessionTest do
258
258
end
259
259
260
260
@ tag :mongo_4_2
261
- test "with_transaction_abort " , % { top: top } do
261
+ test "transaction_abort " , % { top: top } do
262
262
coll = "dogs_with_about_transaction"
263
263
264
264
Mongo . insert_one ( top , coll , % { name: "Wuff" } )
265
265
Mongo . delete_many ( top , coll , % { } )
266
266
267
- assert { :error , :error } ==
268
- Session . with_transaction (
267
+ assert :error ==
268
+ Mongo . transaction (
269
269
top ,
270
- fn opts ->
271
- { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Greta" } , opts )
270
+ fn ->
271
+ { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Greta" } )
272
272
assert id != nil
273
- { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Waldo" } , opts )
273
+ { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Waldo" } )
274
274
assert id != nil
275
- { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Tom" } , opts )
275
+ { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Tom" } )
276
276
assert id != nil
277
277
:error
278
278
end ,
@@ -283,21 +283,21 @@ defmodule Mongo.SessionTest do
283
283
end
284
284
285
285
@ tag :mongo_4_2
286
- test "with_transaction_abort_exception " , % { top: top } do
286
+ test "transaction_abort_exception " , % { top: top } do
287
287
coll = "dogs_with_transaction_abort_exception"
288
288
289
289
Mongo . insert_one ( top , coll , % { name: "Wuff" } )
290
290
Mongo . delete_many ( top , coll , % { } )
291
291
292
292
assert { :error , % ArgumentError { message: "test" } } ==
293
- Session . with_transaction (
293
+ Mongo . transaction (
294
294
top ,
295
- fn opts ->
296
- { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Greta" } , opts )
295
+ fn ->
296
+ { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Greta" } )
297
297
assert id != nil
298
- { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Waldo" } , opts )
298
+ { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Waldo" } )
299
299
assert id != nil
300
- { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Tom" } , opts )
300
+ { :ok , % InsertOneResult { :inserted_id => id } } = Mongo . insert_one ( top , coll , % { name: "Tom" } )
301
301
assert id != nil
302
302
303
303
raise ( ArgumentError , "test" )
@@ -328,10 +328,10 @@ defmodule Mongo.SessionTest do
328
328
|> UnorderedBulk . delete_one ( % { kind: "dog" } )
329
329
330
330
{ :ok , result } =
331
- Session . with_transaction (
331
+ Mongo . transaction (
332
332
top ,
333
- fn opts ->
334
- { :ok , BulkWrite . write ( top , bulk , opts ) }
333
+ fn ->
334
+ { :ok , BulkWrite . write ( top , bulk ) }
335
335
end ,
336
336
w: 1
337
337
)
@@ -363,10 +363,10 @@ defmodule Mongo.SessionTest do
363
363
assert { :ok , _ } = Mongo . admin_command ( top , cmd )
364
364
365
365
{ :error , [ result | _xs ] } =
366
- Session . with_transaction (
366
+ Mongo . transaction (
367
367
top ,
368
- fn opts ->
369
- % BulkWriteResult { errors: errors } = result = BulkWrite . write ( top , bulk , opts )
368
+ fn ->
369
+ % BulkWriteResult { errors: errors } = result = BulkWrite . write ( top , bulk )
370
370
371
371
case Enum . empty? ( errors ) do
372
372
true -> { :ok , result }
@@ -387,16 +387,16 @@ defmodule Mongo.SessionTest do
387
387
Mongo . delete_many ( top , coll , % { } )
388
388
389
389
assert { :ok , :ok } =
390
- Session . with_transaction (
390
+ Mongo . transaction (
391
391
top ,
392
- fn opts ->
392
+ fn ->
393
393
1 .. 1000
394
394
|> Stream . map ( fn
395
395
1 -> BulkOps . get_insert_one ( % { count: 1 } )
396
396
1000 -> BulkOps . get_delete_one ( % { count: 999 } )
397
397
i -> BulkOps . get_update_one ( % { count: i - 1 } , % { "$set": % { count: i } } )
398
398
end )
399
- |> OrderedBulk . write ( top , coll , 25 , opts )
399
+ |> OrderedBulk . write ( top , coll , 25 )
400
400
|> Stream . run ( )
401
401
402
402
{ :ok , :ok }
@@ -407,23 +407,23 @@ defmodule Mongo.SessionTest do
407
407
408
408
@ tag :mongo_4_2
409
409
test "commit empty transaction" , % { top: top } do
410
- assert { :ok , :ok } =
411
- Session . with_transaction (
410
+ assert :ok =
411
+ Mongo . transaction (
412
412
top ,
413
413
fn _opts ->
414
- { :ok , :ok }
414
+ :ok
415
415
end ,
416
416
w: 1
417
417
)
418
418
end
419
419
420
420
@ tag :mongo_4_2
421
421
test "abort empty transaction" , % { top: top } do
422
- assert { :error , :ok } =
423
- Session . with_transaction (
422
+ assert :error =
423
+ Mongo . transaction (
424
424
top ,
425
425
fn _opts ->
426
- { :error , :ok }
426
+ :error
427
427
end ,
428
428
w: 1
429
429
)
@@ -450,10 +450,10 @@ defmodule Mongo.SessionTest do
450
450
|> OrderedBulk . delete_one ( % { kind: "cat" } )
451
451
452
452
{ :ok , result } =
453
- Session . with_transaction (
453
+ Mongo . transaction (
454
454
top ,
455
- fn opts ->
456
- result = BulkWrite . write ( top , bulk , opts )
455
+ fn ->
456
+ result = BulkWrite . write ( top , bulk )
457
457
{ :ok , result }
458
458
end ,
459
459
w: 1
0 commit comments