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
|
'use strict';
/**
* distinct.js
*
* Runs distinct on an indexed field and verifies the result.
* The indexed field contains unique values.
* Each thread operates on a separate collection.
*/
load('jstests/concurrency/fsm_workload_helpers/drop_utils.js'); // for dropCollections
var $config = (function() {
var data = {
numDocs: 1000,
prefix: 'distinct_fsm',
shardKey: {i: 1}
};
var states = (function() {
function init(db, collName) {
this.threadCollName = this.prefix + '_' + this.tid;
var bulk = db[this.threadCollName].initializeUnorderedBulkOp();
for (var i = 0; i < this.numDocs; ++i) {
bulk.insert({i: i});
}
var res = bulk.execute();
assertAlways.writeOK(res);
assertAlways.eq(this.numDocs, res.nInserted);
assertAlways.commandWorked(db[this.threadCollName].ensureIndex({i: 1}));
}
function distinct(db, collName) {
assertWhenOwnColl.eq(this.numDocs, db[this.threadCollName].distinct('i').length);
}
return {
init: init,
distinct: distinct
};
})();
var transitions = {
init: {distinct: 1},
distinct: {distinct: 1}
};
function teardown(db, collName, cluster) {
var pattern = new RegExp('^' + this.prefix + '_\\d+$');
dropCollections(db, pattern);
}
return {
data: data,
threadCount: 10,
iterations: 20,
states: states,
transitions: transitions,
teardown: teardown
};
})();
|