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
|
/**
* Test that the server returns an error response for map-reduce operations that attempt to insert a
* document larger than 16MB as a result of the reduce() or finalize() functions and using the
* "replace" action for the out collection.
*/
(function() {
function mapper() {
// Emit multiple values to ensure that the reducer gets called.
emit(this._id, 1);
emit(this._id, 1);
}
function createBigDocument() {
// Returns a document of the form { _id: ObjectId(...), value: '...' } with the specified
// 'targetSize' in bytes.
function makeDocWithSize(targetSize) {
var doc = {_id: new ObjectId(), value: ''};
var size = Object.bsonsize(doc);
assert.gte(targetSize, size);
// Set 'value' as a string with enough characters to make the whole document 'size'
// bytes long.
doc.value = new Array(targetSize - size + 1).join('x');
assert.eq(targetSize, Object.bsonsize(doc));
return doc;
}
var maxDocSize = 16 * 1024 * 1024;
return makeDocWithSize(maxDocSize + 1).value;
}
function runTest(testOptions) {
db.input.drop();
db.mr_bigobject_replace.drop();
// Insert a document so the mapper gets run.
assert.writeOK(db.input.insert({}));
var res = db.runCommand(Object.extend({
mapReduce: "input",
map: mapper,
out: {replace: "mr_bigobject_replace"},
},
testOptions));
assert.commandFailed(res, "creating a document larger than 16MB didn't fail");
assert.lte(0,
res.errmsg.indexOf("object to insert too large"),
"map-reduce command failed for a reason other than inserting a large document");
}
runTest({reduce: createBigDocument});
runTest({
reduce: function() {
return 1;
},
finalize: createBigDocument
});
})();
|