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
|
'use strict';
/**
* count_odd.js
*
* Count odd numbered entries while updating and deleting even numbered entries.
*
* @tags: [
* requires_non_retryable_writes,
* ]
*
*/
var $config = (function() {
var states = (function() {
function init(db, collName) {
}
function write(db, collName) {
const coll = db[collName];
const i = Random.randInt(499) * 2;
assertAlways.writeOK(coll.update({i: i}, {$set: {i: 2000}}, {multi: true}));
assertAlways.writeOK(coll.remove({i: 2000}));
assertAlways.writeOK(coll.save({i: i}));
}
function count(db, collName) {
const num_odd_doc = db[collName].countDocuments({i: {$mod: [2, 1]}});
assertAlways.eq(500, num_odd_doc);
}
return {init: init, write: write, count: count};
})();
let setup = function(db, collName) {
assert.commandWorked(db[collName].createIndex({i: 1}));
const bulk = db[collName].initializeUnorderedBulkOp();
for (let i = 0; i < 1000; ++i) {
bulk.insert({i: i});
}
assert.commandWorked(bulk.execute());
};
let transitions = {
init: {write: 0.5, count: 0.5},
write: {write: 0.5, count: 0.5},
count: {write: 0.5, count: 0.5}
};
return {
threadCount: 10,
iterations: 20,
states: states,
setup: setup,
transitions: transitions
};
})();
|