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
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
|
/**
* Tests the default values for causal consistency and retryable writes as part of SessionOptions.
*/
(function() {
"use strict";
const conn = MongoRunner.runMongod();
let session = conn.startSession();
assert(session.getOptions().isCausalConsistency(),
"Causal consistency should be implicitly enabled for an explicit session");
assert(!session.getOptions().shouldRetryWrites(),
"Retryable writes should not be implicitly enabled for an explicit session");
session.endSession();
session = conn.startSession({causalConsistency: true});
assert(session.getOptions().isCausalConsistency(),
"Causal consistency should be able to be explicitly enabled");
assert(!session.getOptions().shouldRetryWrites(),
"Retryable writes should not be implicitly enabled for an explicit session");
session.endSession();
session = conn.startSession({causalConsistency: false});
assert(!session.getOptions().isCausalConsistency(),
"Causal consistency should be able to be explicitly disabled");
assert(!session.getOptions().shouldRetryWrites(),
"Retryable writes should not be implicitly enabled for an explicit session");
session.endSession();
session = conn.startSession({retryWrites: false});
assert(session.getOptions().isCausalConsistency(),
"Causal consistency should be implicitly enabled for an explicit session");
assert(!session.getOptions().shouldRetryWrites(),
"Retryable writes should be able to be explicitly disabled");
session.endSession();
session = conn.startSession({retryWrites: true});
assert(session.getOptions().isCausalConsistency(),
"Causal consistency should be implicitly enabled for an explicit session");
assert(session.getOptions().shouldRetryWrites(),
"Retryable writes should be able to be explicitly enabled");
session.endSession();
function runMongoShellWithRetryWritesEnabled(func) {
const args = [MongoRunner.getMongoShellPath()];
args.push("--port", conn.port);
args.push("--retryWrites");
const jsCode = "(" + func.toString() + ")()";
args.push("--eval", jsCode);
const exitCode = runMongoProgram.apply(null, args);
assert.eq(0, exitCode, "Encountered an error in the other mongo shell");
}
runMongoShellWithRetryWritesEnabled(function() {
let session = db.getSession();
assert(session.getOptions().isCausalConsistency(),
"Causal consistency should be implicitly enabled for an explicit session");
assert(session.getOptions().shouldRetryWrites(),
"Retryable writes should be implicitly enabled on default session when using" +
" --retryWrites");
session = db.getMongo().startSession({retryWrites: false});
assert(session.getOptions().isCausalConsistency(),
"Causal consistency should be implicitly enabled for an explicit session");
assert(!session.getOptions().shouldRetryWrites(),
"Retryable writes should be able to be explicitly disabled");
session.endSession();
session = db.getMongo().startSession();
assert(session.getOptions().isCausalConsistency(),
"Causal consistency should be implicitly enabled for an explicit session");
assert(session.getOptions().shouldRetryWrites(),
"Retryable writes should be implicitly enabled on new sessions when using" +
" --retryWrites");
session.endSession();
});
MongoRunner.stopMongod(conn);
})();
|