Skip to content

Commit dbcc69a

Browse files
committed
Updated transaction tests
JAVA-3343 JAVA-3446
1 parent 069195d commit dbcc69a

File tree

16 files changed

+382
-242
lines changed

16 files changed

+382
-242
lines changed

driver-async/src/test/functional/com/mongodb/async/client/TransactionsTest.java

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,7 @@
7878
import static org.junit.Assert.assertNotNull;
7979
import static org.junit.Assert.assertNull;
8080
import static org.junit.Assert.assertTrue;
81+
import static org.junit.Assert.fail;
8182
import static org.junit.Assume.assumeFalse;
8283
import static org.junit.Assume.assumeTrue;
8384

@@ -391,6 +392,22 @@ public void execute() {
391392
final BsonDocument arguments = operation.getDocument("arguments", new BsonDocument());
392393
assertNull(sessionsMap.get(arguments.getString("session").getValue()).getPinnedServerAddress());
393394
}
395+
} else if (operationName.equals("assertSessionTransactionState")) {
396+
final BsonDocument arguments = operation.getDocument("arguments", new BsonDocument());
397+
ClientSession session = sessionsMap.get(arguments.getString("session").getValue());
398+
String state = arguments.getString("state").getValue();
399+
if (state.equals("starting") || state.equals("in_progress")) {
400+
assertTrue(session.hasActiveTransaction());
401+
} else {
402+
assertFalse(session.hasActiveTransaction());
403+
}
404+
} else if (operation.getBoolean("error", BsonBoolean.FALSE).getValue()) {
405+
try {
406+
helper.getOperationResults(operation, clientSession);
407+
fail("Error expected but none thrown");
408+
} catch (Exception e) {
409+
// Expected failure ignore
410+
}
394411
} else {
395412
BsonDocument actualOutcome = helper.getOperationResults(operation, clientSession);
396413
if (expectedResult != null) {

driver-core/src/test/resources/transactions-convenient-api/README.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ following fields:
129129
executed. Elements in this array will follow the same structure as the
130130
``operations`` field defined above (and in the CRUD and Transactions specs).
131131

132-
Note that drivers are expected to evaluate ``error` and ``result``
132+
Note that drivers are expected to evaluate ``error`` and ``result``
133133
assertions when executing operations within ``callback.operations``.
134134

135135
- ``options`` (optional): Names and values of options to pass to

driver-core/src/test/resources/transactions-convenient-api/callback-retry.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -235,7 +235,8 @@
235235
"errorLabelsOmit": [
236236
"TransientTransactionError",
237237
"UnknownTransactionCommitResult"
238-
]
238+
],
239+
"errorContains": "E11000"
239240
}
240241
}
241242
],

driver-core/src/test/resources/transactions-convenient-api/transaction-options.json

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@
192192
"session0": {
193193
"defaultTransactionOptions": {
194194
"readConcern": {
195-
"level": "snapshot"
195+
"level": "majority"
196196
},
197197
"writeConcern": {
198198
"w": 1
@@ -243,7 +243,7 @@
243243
"startTransaction": true,
244244
"autocommit": false,
245245
"readConcern": {
246-
"level": "snapshot"
246+
"level": "majority"
247247
},
248248
"writeConcern": null
249249
},
@@ -308,7 +308,7 @@
308308
},
309309
"options": {
310310
"readConcern": {
311-
"level": "snapshot"
311+
"level": "majority"
312312
},
313313
"writeConcern": {
314314
"w": 1
@@ -335,7 +335,7 @@
335335
"startTransaction": true,
336336
"autocommit": false,
337337
"readConcern": {
338-
"level": "snapshot"
338+
"level": "majority"
339339
},
340340
"writeConcern": null
341341
},
@@ -380,7 +380,7 @@
380380
"session0": {
381381
"defaultTransactionOptions": {
382382
"readConcern": {
383-
"level": "majority"
383+
"level": "snapshot"
384384
},
385385
"writeConcern": {
386386
"w": "majority"
@@ -412,7 +412,7 @@
412412
},
413413
"options": {
414414
"readConcern": {
415-
"level": "snapshot"
415+
"level": "majority"
416416
},
417417
"writeConcern": {
418418
"w": 1
@@ -439,7 +439,7 @@
439439
"startTransaction": true,
440440
"autocommit": false,
441441
"readConcern": {
442-
"level": "snapshot"
442+
"level": "majority"
443443
},
444444
"writeConcern": null
445445
},
@@ -481,7 +481,7 @@
481481
"description": "withTransaction explicit transaction options override client options",
482482
"useMultipleMongoses": true,
483483
"clientOptions": {
484-
"readConcernLevel": "majority",
484+
"readConcernLevel": "local",
485485
"w": "majority"
486486
},
487487
"operations": [
@@ -508,7 +508,7 @@
508508
},
509509
"options": {
510510
"readConcern": {
511-
"level": "snapshot"
511+
"level": "majority"
512512
},
513513
"writeConcern": {
514514
"w": 1
@@ -535,7 +535,7 @@
535535
"startTransaction": true,
536536
"autocommit": false,
537537
"readConcern": {
538-
"level": "snapshot"
538+
"level": "majority"
539539
},
540540
"writeConcern": null
541541
},

driver-core/src/test/resources/transactions/README.rst

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -147,7 +147,7 @@ Each YAML file has the following keys:
147147
- ``arguments``: Optional, the names and values of arguments.
148148

149149
- ``error``: Optional. If true, the test should expect an error or
150-
exception.
150+
exception. This could be a server-generated or a driver-generated error.
151151

152152
- ``result``: The return value from the operation, if any. This field may
153153
be a single document or an array of documents in the case of a
@@ -342,6 +342,26 @@ fail point on the mongos server which "session0" is pinned to::
342342
failCommands: ["commitTransaction"]
343343
closeConnection: true
344344

345+
Tests that use the "targetedFailPoint" operation do not include
346+
``configureFailPoint`` commands in their command expectations. Drivers MUST
347+
ensure that ``configureFailPoint`` commands do not appear in the list of logged
348+
commands, either by manually filtering it from the list of observed commands or
349+
by using a different MongoClient to execute ``configureFailPoint``.
350+
351+
assertSessionTransactionState
352+
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
353+
354+
The "assertSessionTransactionState" operation instructs the test runner to
355+
assert that the transaction state of the given session is equal to the
356+
specified value. The possible values are as follows: ``none``, ``starting``,
357+
``in_progress``, ``committed``, ``aborted``::
358+
359+
- name: assertSessionTransactionState
360+
object: testRunner
361+
arguments:
362+
session: session0
363+
state: in_progress
364+
345365
assertSessionPinned
346366
~~~~~~~~~~~~~~~~~~~
347367

driver-core/src/test/resources/transactions/abort.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -458,7 +458,8 @@
458458
"errorLabelsOmit": [
459459
"TransientTransactionError",
460460
"UnknownTransactionCommitResult"
461-
]
461+
],
462+
"errorContains": "E11000"
462463
}
463464
},
464465
{

driver-core/src/test/resources/transactions/bulk.json

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -304,9 +304,7 @@
304304
"$set": {
305305
"x": 1
306306
}
307-
},
308-
"multi": false,
309-
"upsert": false
307+
}
310308
},
311309
{
312310
"q": {
@@ -317,7 +315,6 @@
317315
"x": 2
318316
}
319317
},
320-
"multi": false,
321318
"upsert": true
322319
}
323320
],
@@ -379,19 +376,15 @@
379376
},
380377
"u": {
381378
"y": 1
382-
},
383-
"multi": false,
384-
"upsert": false
379+
}
385380
},
386381
{
387382
"q": {
388383
"_id": 2
389384
},
390385
"u": {
391386
"y": 2
392-
},
393-
"multi": false,
394-
"upsert": false
387+
}
395388
}
396389
],
397390
"ordered": true,
@@ -454,8 +447,7 @@
454447
"z": 1
455448
}
456449
},
457-
"multi": true,
458-
"upsert": false
450+
"multi": true
459451
}
460452
],
461453
"ordered": true,

driver-core/src/test/resources/transactions/causal-consistency.json

Lines changed: 6 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,7 @@
4040
"$inc": {
4141
"count": 1
4242
}
43-
},
44-
"upsert": false
43+
}
4544
},
4645
"result": {
4746
"matchedCount": 1,
@@ -65,8 +64,7 @@
6564
"$inc": {
6665
"count": 1
6766
}
68-
},
69-
"upsert": false
67+
}
7068
},
7169
"result": {
7270
"matchedCount": 1,
@@ -93,9 +91,7 @@
9391
"$inc": {
9492
"count": 1
9593
}
96-
},
97-
"multi": false,
98-
"upsert": false
94+
}
9995
}
10096
],
10197
"ordered": true,
@@ -123,9 +119,7 @@
123119
"$inc": {
124120
"count": 1
125121
}
126-
},
127-
"multi": false,
128-
"upsert": false
122+
}
129123
}
130124
],
131125
"ordered": true,
@@ -212,8 +206,7 @@
212206
"$inc": {
213207
"count": 1
214208
}
215-
},
216-
"upsert": false
209+
}
217210
},
218211
"result": {
219212
"matchedCount": 1,
@@ -260,9 +253,7 @@
260253
"$inc": {
261254
"count": 1
262255
}
263-
},
264-
"multi": false,
265-
"upsert": false
256+
}
266257
}
267258
],
268259
"ordered": true,

driver-core/src/test/resources/transactions/error-labels.json

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,8 @@
4242
"errorLabelsOmit": [
4343
"TransientTransactionError",
4444
"UnknownTransactionCommitResult"
45-
]
45+
],
46+
"errorContains": "E11000"
4647
}
4748
},
4849
{

0 commit comments

Comments
 (0)