blob: fef2349265f5af8999fbc91b0b62e9c8cdd68cd7 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
|
/**
* Verify that transactions can be run on the in-memory storage engine. inMemory transactions are
* not fully supported, but should work for basic MongoDB user testing.
*
* TODO: remove this test when general transaction testing is turned on with the inMemory storage
* engine (SERVER-36023).
*/
(function() {
"use strict";
if (jsTest.options().storageEngine !== "inMemory") {
jsTestLog("Skipping test because storageEngine is not inMemory");
return;
}
const dbName = "test";
const collName = "transactions_work_with_in_memory_engine";
const replTest = new ReplSetTest({name: collName, nodes: 1});
replTest.startSet({storageEngine: "inMemory"});
replTest.initiate();
const primary = replTest.getPrimary();
// Initiate a session.
const sessionOptions = {
causalConsistency: false
};
const session = primary.getDB(dbName).getMongo().startSession(sessionOptions);
const sessionDb = session.getDatabase(dbName);
// Create collection.
assert.commandWorked(sessionDb[collName].insert({x: 0}));
// Execute a transaction that should succeed.
session.startTransaction();
assert.commandWorked(sessionDb[collName].insert({x: 1}));
assert.commandWorked(session.commitTransaction_forTesting());
session.endSession();
replTest.stopSet();
}());
|