summaryrefslogtreecommitdiff
path: root/src/mongo/db/ops/modifier_inc_test.cpp
blob: c14bf54eaccf46e12fe74a2b1daf8b3058685a95 (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
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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
/**
 *    Copyright (C) 2013 10gen Inc.
 *
 *    This program is free software: you can redistribute it and/or  modify
 *    it under the terms of the GNU Affero General Public License, version 3,
 *    as published by the Free Software Foundation.
 *
 *    This program is distributed in the hope that it will be useful,
 *    but WITHOUT ANY WARRANTY; without even the implied warranty of
 *    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 *    GNU Affero General Public License for more details.
 *
 *    You should have received a copy of the GNU Affero General Public License
 *    along with this program.  If not, see <http://www.gnu.org/licenses/>.
 *
 *    As a special exception, the copyright holders give permission to link the
 *    code of portions of this program with the OpenSSL library under certain
 *    conditions as described in each individual source file and distribute
 *    linked combinations including the program with the OpenSSL library. You
 *    must comply with the GNU Affero General Public License in all respects for
 *    all of the code used other than as permitted herein. If you modify file(s)
 *    with this exception, you may extend this exception to your version of the
 *    file(s), but you are not obligated to do so. If you do not wish to do so,
 *    delete this exception statement from your version. If you delete this
 *    exception statement from all source files in the program, then also delete
 *    it in the license file.
 */


#include "mongo/db/ops/modifier_inc.h"

#include "mongo/base/status.h"
#include "mongo/base/string_data.h"
#include "mongo/bson/mutable/algorithm.h"
#include "mongo/bson/mutable/document.h"
#include "mongo/bson/mutable/mutable_bson_test_utils.h"
#include "mongo/db/jsobj.h"
#include "mongo/db/json.h"
#include "mongo/db/ops/log_builder.h"
#include "mongo/platform/cstdint.h"
#include "mongo/unittest/unittest.h"

namespace {

using mongo::BSONObj;
using mongo::LogBuilder;
using mongo::ModifierInc;
using mongo::ModifierInterface;
using mongo::NumberInt;
using mongo::Status;
using mongo::StringData;
using mongo::fromjson;
using mongo::mutablebson::ConstElement;
using mongo::mutablebson::Document;
using mongo::mutablebson::Element;
using mongo::mutablebson::countChildren;

/** Helper to build and manipulate a $inc mod. */
class Mod {
public:
    explicit Mod(BSONObj modObj)
        : _modObj(modObj),
          _mod(mongoutils::str::equals(modObj.firstElement().fieldName(), "$mul")
                   ? ModifierInc::MODE_MUL
                   : ModifierInc::MODE_INC) {
        const StringData& modName = modObj.firstElement().fieldName();
        ASSERT_OK(_mod.init(_modObj[modName].embeddedObject().firstElement(),
                            ModifierInterface::Options::normal()));
    }

    Status prepare(Element root,
                   const StringData& matchedField,
                   ModifierInterface::ExecInfo* execInfo) {
        return _mod.prepare(root, matchedField, execInfo);
    }

    Status apply() const {
        return _mod.apply();
    }

    Status log(LogBuilder* logBuilder) const {
        return _mod.log(logBuilder);
    }

    ModifierInc& mod() {
        return _mod;
    }

private:
    BSONObj _modObj;
    ModifierInc _mod;
};

TEST(Init, FailToInitWithInvalidValue) {
    BSONObj modObj;
    ModifierInc mod;

    // String is an invalid increment argument
    modObj = fromjson("{ $inc : { a : '' } }");
    ASSERT_NOT_OK(mod.init(modObj["$inc"].embeddedObject().firstElement(),
                           ModifierInterface::Options::normal()));

    // Object is an invalid increment argument
    modObj = fromjson("{ $inc : { a : {} } }");
    ASSERT_NOT_OK(mod.init(modObj["$inc"].embeddedObject().firstElement(),
                           ModifierInterface::Options::normal()));

    // Array is an invalid increment argument
    modObj = fromjson("{ $inc : { a : [] } }");
    ASSERT_NOT_OK(mod.init(modObj["$inc"].embeddedObject().firstElement(),
                           ModifierInterface::Options::normal()));
}

TEST(Init, InitParsesNumberInt) {
    Mod incMod(BSON("$inc" << BSON("a" << static_cast<int>(1))));
}

TEST(Init, InitParsesNumberLong) {
    Mod incMod(BSON("$inc" << BSON("a" << static_cast<long long>(1))));
}

TEST(Init, InitParsesNumberDouble) {
    Mod incMod(BSON("$inc" << BSON("a" << 1.0)));
}

TEST(SimpleMod, PrepareSimpleOK) {
    Document doc(fromjson("{ a : 1 }"));
    Mod incMod(fromjson("{ $inc: { a : 1 }}"));

    ModifierInterface::ExecInfo execInfo;

    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));

    ASSERT_EQUALS(execInfo.fieldRef[0]->dottedField(), "a");
    ASSERT_TRUE(doc.isInPlaceModeEnabled());
    ASSERT_FALSE(execInfo.noOp);
}

TEST(SimpleMod, PrepareSimpleNonNumericObject) {
    Document doc(fromjson("{ a : {} }"));
    Mod incMod(fromjson("{ $inc: { a : 1 }}"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_NOT_OK(incMod.prepare(doc.root(), "", &execInfo));
}

TEST(SimpleMod, PrepareSimpleNonNumericArray) {
    Document doc(fromjson("{ a : [] }"));
    Mod incMod(fromjson("{ $inc: { a : 1 }}"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_NOT_OK(incMod.prepare(doc.root(), "", &execInfo));
}

TEST(SimpleMod, PrepareSimpleNonNumericString) {
    Document doc(fromjson("{ a : '' }"));
    Mod incMod(fromjson("{ $inc: { a : 1 }}"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_NOT_OK(incMod.prepare(doc.root(), "", &execInfo));
}

TEST(SimpleMod, ApplyAndLogEmptyDocument) {
    Document doc(fromjson("{}"));
    Mod incMod(fromjson("{ $inc: { a : 1 }}"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_FALSE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(fromjson("{ a : 1 }"), doc);

    Document logDoc;
    LogBuilder logBuilder(logDoc.root());
    ASSERT_OK(incMod.log(&logBuilder));
    ASSERT_EQUALS(fromjson("{ $set : { a : 1 } }"), logDoc);
}

TEST(SimpleMod, LogWithoutApplyEmptyDocument) {
    Document doc(fromjson("{}"));
    Mod incMod(fromjson("{ $inc: { a : 1 }}"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    Document logDoc;
    LogBuilder logBuilder(logDoc.root());
    ASSERT_OK(incMod.log(&logBuilder));
    ASSERT_EQUALS(fromjson("{ $set : { a : 1 } }"), logDoc);
}

TEST(SimpleMod, ApplyAndLogSimpleDocument) {
    Document doc(fromjson("{ a : 2 }"));
    Mod incMod(fromjson("{ $inc: { a : 1 }}"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_TRUE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(fromjson("{ a : 3 }"), doc);

    Document logDoc;
    LogBuilder logBuilder(logDoc.root());
    ASSERT_OK(incMod.log(&logBuilder));
    ASSERT_EQUALS(fromjson("{ $set : { a : 3 } }"), logDoc);
}

TEST(DottedMod, ApplyAndLogSimpleDocument) {
    Document doc(fromjson("{ a : { b : 2 } }"));
    Mod incMod(fromjson("{ $inc: { 'a.b' : 1 } }"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_TRUE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(fromjson("{ a : { b : 3 } }"), doc);

    Document logDoc;
    LogBuilder logBuilder(logDoc.root());
    ASSERT_OK(incMod.log(&logBuilder));
    ASSERT_EQUALS(fromjson("{ $set : { 'a.b' : 3 } }"), logDoc);
}

TEST(InPlace, IntToInt) {
    Document doc(BSON("a" << static_cast<int>(1)));
    Mod incMod(BSON("$inc" << BSON("a" << static_cast<int>(1))));
    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);
}

TEST(InPlace, LongToLong) {
    Document doc(BSON("a" << static_cast<long long>(1)));
    Mod incMod(BSON("$inc" << BSON("a" << static_cast<long long>(1))));
    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);
}

TEST(InPlace, DoubleToDouble) {
    Document doc(BSON("a" << 1.0));
    Mod incMod(BSON("$inc" << BSON("a" << 1.0)));
    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);
}

TEST(NoOp, Int) {
    Document doc(BSON("a" << static_cast<int>(1)));
    Mod incMod(BSON("$inc" << BSON("a" << static_cast<int>(0))));
    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_TRUE(execInfo.noOp);
}

TEST(NoOp, Long) {
    Document doc(BSON("a" << static_cast<long long>(1)));
    Mod incMod(BSON("$inc" << BSON("a" << static_cast<long long>(0))));
    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_TRUE(execInfo.noOp);
}

TEST(NoOp, Double) {
    Document doc(BSON("a" << 1.0));
    Mod incMod(BSON("$inc" << BSON("a" << 0.0)));
    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_TRUE(execInfo.noOp);
}

TEST(Upcasting, UpcastIntToLong) {
    // Checks that $inc : NumberLong(0) turns a NumberInt into a NumberLong and logs it
    // correctly.
    Document doc(BSON("a" << static_cast<int>(1)));
    ASSERT_EQUALS(mongo::NumberInt, doc.root()["a"].getType());

    Mod incMod(BSON("$inc" << BSON("a" << static_cast<long long>(0))));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_FALSE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(fromjson("{ a : 1 }"), doc);
    ASSERT_EQUALS(mongo::NumberLong, doc.root()["a"].getType());

    Document logDoc;
    LogBuilder logBuilder(logDoc.root());
    ASSERT_OK(incMod.log(&logBuilder));
    ASSERT_EQUALS(fromjson("{ $set : { a : 1 } }"), logDoc);
    ASSERT_EQUALS(mongo::NumberLong, logDoc.root()["$set"]["a"].getType());
}

TEST(Upcasting, UpcastIntToDouble) {
    // Checks that $inc : 0.0 turns a NumberInt into a NumberDouble and logs it
    // correctly.
    Document doc(BSON("a" << static_cast<int>(1)));
    ASSERT_EQUALS(mongo::NumberInt, doc.root()["a"].getType());

    Mod incMod(fromjson("{ $inc : { a : 0.0 } }"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_FALSE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(fromjson("{ a : 1.0 }"), doc);
    ASSERT_EQUALS(mongo::NumberDouble, doc.root()["a"].getType());

    Document logDoc;
    LogBuilder logBuilder(logDoc.root());
    ASSERT_OK(incMod.log(&logBuilder));
    ASSERT_EQUALS(fromjson("{ $set : { a : 1.0 } }"), logDoc);
    ASSERT_EQUALS(mongo::NumberDouble, logDoc.root()["$set"]["a"].getType());
}

TEST(Upcasting, UpcastLongToDouble) {
    // Checks that $inc : 0.0 turns a NumberLong into a NumberDouble and logs it
    // correctly.
    Document doc(BSON("a" << static_cast<long long>(1)));
    ASSERT_EQUALS(mongo::NumberLong, doc.root()["a"].getType());

    Mod incMod(fromjson("{ $inc : { a : 0.0 } }"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_TRUE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(fromjson("{ a : 1.0 }"), doc);
    ASSERT_EQUALS(mongo::NumberDouble, doc.root()["a"].getType());

    Document logDoc;
    LogBuilder logBuilder(logDoc.root());
    ASSERT_OK(incMod.log(&logBuilder));
    ASSERT_EQUALS(fromjson("{ $set : { a : 1.0 } }"), logDoc);
    ASSERT_EQUALS(mongo::NumberDouble, logDoc.root()["$set"]["a"].getType());
}

TEST(Upcasting, DoublesStayDoubles) {
    // Checks that $inc : 0 doesn't change a NumberDouble away from double
    Document doc(fromjson("{ a : 1.0 }"));
    ASSERT_EQUALS(mongo::NumberDouble, doc.root()["a"].getType());

    Mod incMod(fromjson("{ $inc : { a : 1 } }"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_TRUE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(fromjson("{ a : 2.0 }"), doc);
    ASSERT_EQUALS(mongo::NumberDouble, doc.root()["a"].getType());

    Document logDoc;
    LogBuilder logBuilder(logDoc.root());
    ASSERT_OK(incMod.log(&logBuilder));
    ASSERT_EQUALS(fromjson("{ $set : { a : 2.0 } }"), logDoc);
    ASSERT_EQUALS(mongo::NumberDouble, logDoc.root()["$set"]["a"].getType());
}

// The only interesting overflow cases are int->long via increment: we never overflow to
// double, and we never decrease precision on decrement.

TEST(Spilling, OverflowIntToLong) {
    const int initial_value = std::numeric_limits<int32_t>::max();

    Document doc(BSON("a" << static_cast<int>(initial_value)));
    ASSERT_EQUALS(mongo::NumberInt, doc.root()["a"].getType());

    Mod incMod(fromjson("{ $inc : { a : 1 } }"));
    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    const long long target_value = static_cast<long long>(initial_value) + 1;

    ASSERT_OK(incMod.apply());
    ASSERT_FALSE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(BSON("a" << target_value), doc);
}

TEST(Spilling, UnderflowIntToLong) {
    const int initial_value = std::numeric_limits<int32_t>::min();

    Document doc(BSON("a" << static_cast<int>(initial_value)));
    ASSERT_EQUALS(mongo::NumberInt, doc.root()["a"].getType());

    Mod incMod(fromjson("{ $inc : { a : -1 } }"));
    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    const long long target_value = static_cast<long long>(initial_value) - 1;

    ASSERT_OK(incMod.apply());
    ASSERT_FALSE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(BSON("a" << target_value), doc);
}

TEST(Lifecycle, IncModCanBeReused) {
    Document doc1(fromjson("{ a : 1 }"));
    Document doc2(fromjson("{ a : 1 }"));

    Mod incMod(fromjson("{ $inc: { a : 1 }}"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc1.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_TRUE(doc1.isInPlaceModeEnabled());
    ASSERT_EQUALS(fromjson("{ a : 2 }"), doc1);

    ASSERT_OK(incMod.prepare(doc2.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_TRUE(doc2.isInPlaceModeEnabled());
    ASSERT_EQUALS(fromjson("{ a : 2 }"), doc2);
}

// Given the current implementation of $mul, we really only need one test for
// $mul. However, in the future, we should probably write additional ones, or, perhaps find
// a way to run all the obove tests in both modes.
TEST(Multiplication, ApplyAndLogSimpleDocument) {
    Document doc(fromjson("{ a : { b : 2 } }"));
    Mod incMod(fromjson("{ $mul: { 'a.b' : 3 } }"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_TRUE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(fromjson("{ a : { b : 6 } }"), doc);

    Document logDoc;
    LogBuilder logBuilder(logDoc.root());
    ASSERT_OK(incMod.log(&logBuilder));
    ASSERT_EQUALS(fromjson("{ $set : { 'a.b' : 6 } }"), logDoc);
}

TEST(Multiplication, ApplyAndLogMissingElement) {
    Document doc(fromjson("{ a : 0 }"));
    Mod incMod(fromjson("{ $mul : { b : 3 } }"));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_FALSE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(fromjson("{ a : 0, b : 0 }"), doc);

    Document logDoc;
    LogBuilder logBuilder(logDoc.root());
    ASSERT_OK(incMod.log(&logBuilder));
    ASSERT_EQUALS(fromjson("{ $set : { b : 0 } }"), logDoc);
}

TEST(Multiplication, ApplyMissingElementInt) {
    const int int_zero = 0;
    const int int_three = 3;

    Document doc(BSON("a" << int_zero));
    Mod incMod(BSON("$mul" << BSON("b" << int_three)));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_FALSE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(BSON("a" << int_zero << "b" << int_zero), doc);
    ASSERT_EQUALS(mongo::NumberInt, doc.root().rightChild().getType());
}

TEST(Multiplication, ApplyMissingElementLongLong) {
    const long long ll_zero = 0;
    const long long ll_three = 3;

    Document doc(BSON("a" << ll_zero));
    Mod incMod(BSON("$mul" << BSON("b" << ll_three)));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_FALSE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(BSON("a" << ll_zero << "b" << ll_zero), doc);
    ASSERT_EQUALS(mongo::NumberLong, doc.root().rightChild().getType());
}

TEST(Multiplication, ApplyMissingElementDouble) {
    const double double_zero = 0;
    const double double_three = 3;

    Document doc(BSON("a" << double_zero));
    Mod incMod(BSON("$mul" << BSON("b" << double_three)));

    ModifierInterface::ExecInfo execInfo;
    ASSERT_OK(incMod.prepare(doc.root(), "", &execInfo));
    ASSERT_FALSE(execInfo.noOp);

    ASSERT_OK(incMod.apply());
    ASSERT_FALSE(doc.isInPlaceModeEnabled());
    ASSERT_EQUALS(BSON("a" << double_zero << "b" << 0), doc);
    ASSERT_EQUALS(mongo::NumberDouble, doc.root().rightChild().getType());
}

}  // namespace