summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/query_stage_collscan.cpp
blob: aa0fb3a2e6530ad492f1485de3079f9f3dce5f68 (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
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
/**
 *    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.
 */

/**
 * This file tests db/exec/collection_scan.cpp.
 */

#include "mongo/client/dbclientcursor.h"
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/database.h"
#include "mongo/db/exec/collection_scan.h"
#include "mongo/db/exec/plan_stage.h"
#include "mongo/db/instance.h"
#include "mongo/db/json.h"
#include "mongo/db/matcher/expression_parser.h"
#include "mongo/db/pdfile.h"
#include "mongo/db/query/plan_executor.h"
#include "mongo/db/storage/extent.h"
#include "mongo/db/storage/extent_manager.h"
#include "mongo/db/operation_context_impl.h"
#include "mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h"
#include "mongo/db/structure/catalog/namespace_details.h"
#include "mongo/db/structure/record_store.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/util/fail_point_service.h"

namespace QueryStageCollectionScan {
#if 0 // SERVER-13640
    //
    // Test some nitty-gritty capped collection details.  Ported and polished from pdfiletests.cpp.
    //
    class QueryStageCollectionScanCappedBase {
    public:
        QueryStageCollectionScanCappedBase() : _context(ns()) { }

        virtual ~QueryStageCollectionScanCappedBase() {
            _context.db()->dropCollection( &_txn, ns() );
        }

        void run() {
            // Create the capped collection.
            stringstream spec;
            spec << "{\"capped\":true,\"size\":2000,\"$nExtents\":" << nExtents() << "}";

            ASSERT( userCreateNS( &_txn, db(), ns(), fromjson( spec.str() ), false ).isOK() );

            // Tell the test to add data/extents/etc.
            insertTestData();

            CollectionScanParams params;
            params.collection = collection();
            params.direction = CollectionScanParams::FORWARD;
            params.tailable = false;
            params.start = DiskLoc();

            // Walk the collection going forward.
            {
                // Create an executor to handle the scan.
                WorkingSet* ws = new WorkingSet();
                PlanStage* ps = new CollectionScan(params, ws, NULL);
                PlanExecutor runner(ws, ps, collection());

                int resultCount = 0;
                BSONObj obj;
                while (Runner::RUNNER_ADVANCED == runner.getNext(&obj, NULL)) {
                    ASSERT_EQUALS(resultCount, obj.firstElement().number());
                    ++resultCount;
                }

                ASSERT_EQUALS(expectedCount(), resultCount);
            }

            // Walk the collection going backwards.
            {
                params.direction = CollectionScanParams::BACKWARD;

                WorkingSet* ws = new WorkingSet();
                PlanStage* ps = new CollectionScan(params, ws, NULL);
                PlanExecutor runner(ws, ps, collection());

                // Going backwards.
                int resultCount = expectedCount() - 1;
                BSONObj obj;
                while (Runner::RUNNER_ADVANCED == runner.getNext(&obj, NULL)) {
                    ASSERT_EQUALS(resultCount, obj.firstElement().number());
                    --resultCount;
                }

                ASSERT_EQUALS(-1, resultCount);
            }
        }

    protected:
        // Insert records into the collection.
        virtual void insertTestData() = 0;

        // How many records do we expect to find in our scan?
        virtual int expectedCount() const = 0;

        // How many extents do we create when we make the collection?
        virtual int nExtents() const = 0;

        // Quote: bypass standard alloc/insert routines to use the extent we want.
        DiskLoc insert( const DiskLoc& ext, int i ) {
            // Copied verbatim.
            BSONObjBuilder b;
            b.append( "a", i );
            BSONObj o = b.done();
            int len = o.objsize();
            Extent *e = extentManager()->getExtent(ext);
            e = _txn.recoveryUnit()->writing(e);
            int ofs;
            if ( e->lastRecord.isNull() ) {
                ofs = ext.getOfs() + ( e->_extentData - (char *)e );
            }
            else {
                ofs = e->lastRecord.getOfs()
                    + recordStore()->recordFor(e->lastRecord)->lengthWithHeaders();
            }
            DiskLoc dl( ext.a(), ofs );
            Record *r = recordStore()->recordFor(dl);
            r = (Record*) _txn.recoveryUnit()->writingPtr(r, Record::HeaderSize + len);
            r->lengthWithHeaders() = Record::HeaderSize + len;
            r->extentOfs() = e->myLoc.getOfs();
            r->nextOfs() = DiskLoc::NullOfs;
            r->prevOfs() = e->lastRecord.isNull() ? DiskLoc::NullOfs : e->lastRecord.getOfs();
            memcpy( r->data(), o.objdata(), len );
            if ( e->firstRecord.isNull() )
                e->firstRecord = dl;
            else
                _txn.recoveryUnit()->writingInt(recordStore()->recordFor(e->lastRecord)->nextOfs()) = ofs;
            e->lastRecord = dl;
            return dl;
        }

        static const char *ns() { return "unittests.QueryStageCollectionScanCapped"; }

        Database* db() { return _context.db(); }
        ExtentManager* extentManager() { return db()->getExtentManager(); }
        Collection* collection() { return db()->getCollection( ns() ); }
        NamespaceDetails *nsd() { return collection()->detailsWritable(); }

    protected:
        const RecordStore* recordStore() {
            Collection* c = collection();
            if ( !c )
                return NULL;
            return c->getRecordStore();
        }

        Lock::GlobalWrite lk_;
        Client::Context _context;
        OperationContextImpl _txn;
    };

    class QueryStageCollscanEmpty : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {}
        virtual int expectedCount() const { return 0; }
        virtual int nExtents() const { return 0; }
    };

    class QueryStageCollscanEmptyLooped : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {
            nsd()->setCapFirstNewRecord( &_txn, DiskLoc() );
        }
        virtual int expectedCount() const { return 0; }
        virtual int nExtents() const { return 0; }
    };

    class QueryStageCollscanEmptyMultiExtentLooped : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {
            nsd()->setCapFirstNewRecord( &_txn, DiskLoc() );
        }
        virtual int expectedCount() const { return 0; }
        virtual int nExtents() const { return 3; }
    };

    class QueryStageCollscanSingle : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {
            nsd()->setCapFirstNewRecord( &_txn, insert( nsd()->capExtent(), 0 ) );
        }
        virtual int expectedCount() const { return 1; }
        virtual int nExtents() const { return 0; }
    };

    class QueryStageCollscanNewCapFirst : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {
            DiskLoc x = insert( nsd()->capExtent(), 0 );
            nsd()->setCapFirstNewRecord( &_txn, x );
            insert( nsd()->capExtent(), 1 );
        }
        virtual int expectedCount() const { return 2; }
        virtual int nExtents() const { return 0; }
    };

    class QueryStageCollscanNewCapLast : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {
            insert( nsd()->capExtent(), 0 );
            nsd()->setCapFirstNewRecord( &_txn, insert( nsd()->capExtent(), 1 ) );
        }
        virtual int expectedCount() const { return 2; }
        virtual int nExtents() const { return 0; }
    };

    class QueryStageCollscanNewCapMiddle : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {
            insert( nsd()->capExtent(), 0 );
            nsd()->setCapFirstNewRecord( &_txn, insert( nsd()->capExtent(), 1 ) );
            insert( nsd()->capExtent(), 2 );
        }
        virtual int expectedCount() const { return 3; }
        virtual int nExtents() const { return 0; }
    };

    class QueryStageCollscanFirstExtent : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {
            insert( nsd()->capExtent(), 0 );
            insert( nsd()->lastExtent(), 1 );
            nsd()->setCapFirstNewRecord( &_txn, insert( nsd()->capExtent(), 2 ) );
            insert( nsd()->capExtent(), 3 );
        }
        virtual int expectedCount() const { return 4; }
        virtual int nExtents() const { return 2; }
    };

    class QueryStageCollscanLastExtent : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {
            nsd()->setCapExtent( &_txn, nsd()->lastExtent() );
            insert( nsd()->capExtent(), 0 );
            insert( nsd()->firstExtent(), 1 );
            nsd()->setCapFirstNewRecord( &_txn, insert( nsd()->capExtent(), 2 ) );
            insert( nsd()->capExtent(), 3 );
        }
        virtual int expectedCount() const { return 4; }
        virtual int nExtents() const { return 2; }
    };

    class QueryStageCollscanMidExtent : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {
            nsd()->setCapExtent( &_txn, extentManager()->getExtent(nsd()->firstExtent())->xnext );
            insert( nsd()->capExtent(), 0 );
            insert( nsd()->lastExtent(), 1 );
            insert( nsd()->firstExtent(), 2 );
            nsd()->setCapFirstNewRecord( &_txn, insert( nsd()->capExtent(), 3 ) );
            insert( nsd()->capExtent(), 4 );
        }
        virtual int expectedCount() const { return 5; }
        virtual int nExtents() const { return 3; }
    };

    class QueryStageCollscanAloneInExtent : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {
            nsd()->setCapExtent( &_txn, extentManager()->getExtent(nsd()->firstExtent())->xnext );
            insert( nsd()->lastExtent(), 0 );
            insert( nsd()->firstExtent(), 1 );
            nsd()->setCapFirstNewRecord( &_txn, insert( nsd()->capExtent(), 2 ) );
        }
        virtual int expectedCount() const { return 3; }
        virtual int nExtents() const { return 3; }
    };

    class QueryStageCollscanFirstInExtent : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {
            nsd()->setCapExtent( &_txn, extentManager()->getExtent(nsd()->firstExtent())->xnext );
            insert( nsd()->lastExtent(), 0 );
            insert( nsd()->firstExtent(), 1 );
            nsd()->setCapFirstNewRecord( &_txn, insert( nsd()->capExtent(), 2 ) );
            insert( nsd()->capExtent(), 3 );
        }
        virtual int expectedCount() const { return 4; }
        virtual int nExtents() const { return 3; }
    };

    class QueryStageCollscanLastInExtent : public QueryStageCollectionScanCappedBase {
        virtual void insertTestData() {
            nsd()->setCapExtent( &_txn, extentManager()->getExtent(nsd()->firstExtent())->xnext );
            insert( nsd()->capExtent(), 0 );
            insert( nsd()->lastExtent(), 1 );
            insert( nsd()->firstExtent(), 2 );
            nsd()->setCapFirstNewRecord( &_txn, insert( nsd()->capExtent(), 3 ) );
        }
        virtual int expectedCount() const { return 4; }
        virtual int nExtents() const { return 3; }
    };
#endif // SERVER-13640
    //
    // Stage-specific tests.
    //

    class QueryStageCollectionScanBase {
    public:
        QueryStageCollectionScanBase() {
            Client::WriteContext ctx(ns());

            for (int i = 0; i < numObj(); ++i) {
                BSONObjBuilder bob;
                bob.append("foo", i);
                _client.insert(ns(), bob.obj());
            }
        }

        virtual ~QueryStageCollectionScanBase() {
            Client::WriteContext ctx(ns());
            _client.dropCollection(ns());
        }

        void remove(const BSONObj& obj) {
            _client.remove(ns(), obj);
        }

        int countResults(CollectionScanParams::Direction direction, const BSONObj& filterObj) {
            Client::ReadContext ctx(ns());

            // Configure the scan.
            CollectionScanParams params;
            params.collection = ctx.ctx().db()->getCollection( ns() );
            params.direction = direction;
            params.tailable = false;

            // Make the filter.
            StatusWithMatchExpression swme = MatchExpressionParser::parse(filterObj);
            verify(swme.isOK());
            auto_ptr<MatchExpression> filterExpr(swme.getValue());

            // Make a scan and have the runner own it.
            WorkingSet* ws = new WorkingSet();
            PlanStage* ps = new CollectionScan(params, ws, filterExpr.get());
            PlanExecutor runner(ws, ps, params.collection);

            // Use the runner to count the number of objects scanned.
            int count = 0;
            for (BSONObj obj; Runner::RUNNER_ADVANCED == runner.getNext(&obj, NULL); ) { ++count; }
            return count;
        }

        void getLocs(Collection* collection,
                     CollectionScanParams::Direction direction,
                     vector<DiskLoc>* out) {
            WorkingSet ws;

            CollectionScanParams params;
            params.collection = collection;
            params.direction = direction;
            params.tailable = false;

            scoped_ptr<CollectionScan> scan(new CollectionScan(params, &ws, NULL));
            while (!scan->isEOF()) {
                WorkingSetID id = WorkingSet::INVALID_ID;
                PlanStage::StageState state = scan->work(&id);
                if (PlanStage::ADVANCED == state) {
                    WorkingSetMember* member = ws.get(id);
                    verify(member->hasLoc());
                    out->push_back(member->loc);
                }
            }
        }

        static int numObj() { return 50; }

        static const char* ns() { return "unittests.QueryStageCollectionScan"; }

    private:
        static DBDirectClient _client;
    };

    DBDirectClient QueryStageCollectionScanBase::_client;

    //
    // Go forwards, get everything.
    //
    class QueryStageCollscanBasicForward : public QueryStageCollectionScanBase {
    public:
        void run() {
            ASSERT_EQUALS(numObj(), countResults(CollectionScanParams::FORWARD, BSONObj()));
        }
    };

    //
    // Go backwards, get everything.
    //

    class QueryStageCollscanBasicBackward : public QueryStageCollectionScanBase {
    public:
        void run() {
            ASSERT_EQUALS(numObj(), countResults(CollectionScanParams::BACKWARD, BSONObj()));
        }
    };

    //
    // Go forwards and match half the docs.
    //

    class QueryStageCollscanBasicForwardWithMatch : public QueryStageCollectionScanBase {
    public:
        void run() {
            BSONObj obj = BSON("foo" << BSON("$lt" << 25));
            ASSERT_EQUALS(25, countResults(CollectionScanParams::FORWARD, obj));
        }
    };

    //
    // Go backwards and match half the docs.
    //

    class QueryStageCollscanBasicBackwardWithMatch : public QueryStageCollectionScanBase {
    public:
        void run() {
            BSONObj obj = BSON("foo" << BSON("$lt" << 25));
            ASSERT_EQUALS(25, countResults(CollectionScanParams::BACKWARD, obj));
        }
    };

    //
    // Get objects in the order we inserted them.
    //

    class QueryStageCollscanObjectsInOrderForward : public QueryStageCollectionScanBase {
    public:
        void run() {
            Client::ReadContext ctx(ns());

            // Configure the scan.
            CollectionScanParams params;
            params.collection = ctx.ctx().db()->getCollection( ns() );
            params.direction = CollectionScanParams::FORWARD;
            params.tailable = false;

            // Make a scan and have the runner own it.
            WorkingSet* ws = new WorkingSet();
            PlanStage* ps = new CollectionScan(params, ws, NULL);
            PlanExecutor runner(ws, ps, params.collection);

            int count = 0;
            for (BSONObj obj; Runner::RUNNER_ADVANCED == runner.getNext(&obj, NULL); ) {
                // Make sure we get the objects in the order we want
                ASSERT_EQUALS(count, obj["foo"].numberInt());
                ++count;
            }

            ASSERT_EQUALS(numObj(), count);
        }
    };

    //
    // Get objects in the reverse order we inserted them when we go backwards.
    //

    class QueryStageCollscanObjectsInOrderBackward : public QueryStageCollectionScanBase {
    public:
        void run() {
            Client::ReadContext ctx(ns());

            CollectionScanParams params;
            params.collection = ctx.ctx().db()->getCollection( ns() );
            params.direction = CollectionScanParams::BACKWARD;
            params.tailable = false;

            WorkingSet* ws = new WorkingSet();
            PlanStage* ps = new CollectionScan(params, ws, NULL);
            PlanExecutor runner(ws, ps, params.collection);

            int count = 0;
            for (BSONObj obj; Runner::RUNNER_ADVANCED == runner.getNext(&obj, NULL); ) {
                ++count;
                ASSERT_EQUALS(numObj() - count, obj["foo"].numberInt());
            }

            ASSERT_EQUALS(numObj(), count);
        }
    };

    //
    // Scan through half the objects, delete the one we're about to fetch, then expect to get the
    // "next" object we would have gotten after that.
    //

    class QueryStageCollscanInvalidateUpcomingObject : public QueryStageCollectionScanBase {
    public:
        void run() {
            Client::WriteContext ctx(ns());

            Collection* coll = ctx.ctx().db()->getCollection( ns() );

            // Get the DiskLocs that would be returned by an in-order scan.
            vector<DiskLoc> locs;
            getLocs(coll, CollectionScanParams::FORWARD, &locs);

            // Configure the scan.
            CollectionScanParams params;
            params.collection = coll;
            params.direction = CollectionScanParams::FORWARD;
            params.tailable = false;

            WorkingSet ws;
            scoped_ptr<CollectionScan> scan(new CollectionScan(params, &ws, NULL));

            int count = 0;
            while (count < 10) {
                WorkingSetID id = WorkingSet::INVALID_ID;
                PlanStage::StageState state = scan->work(&id);
                if (PlanStage::ADVANCED == state) {
                    WorkingSetMember* member = ws.get(id);
                    ASSERT_EQUALS(coll->docFor(locs[count])["foo"].numberInt(),
                                  member->obj["foo"].numberInt());
                    ++count;
                }
            }

            // Remove locs[count].
            scan->prepareToYield();
            scan->invalidate(locs[count], INVALIDATION_DELETION);
            remove(coll->docFor(locs[count]));
            scan->recoverFromYield();

            // Skip over locs[count].
            ++count;

            // Expect the rest.
            while (!scan->isEOF()) {
                WorkingSetID id = WorkingSet::INVALID_ID;
                PlanStage::StageState state = scan->work(&id);
                if (PlanStage::ADVANCED == state) {
                    WorkingSetMember* member = ws.get(id);
                    ASSERT_EQUALS(coll->docFor(locs[count])["foo"].numberInt(),
                                  member->obj["foo"].numberInt());
                    ++count;
                }
            }

            ASSERT_EQUALS(numObj(), count);
        }
    };

    //
    // Scan through half the objects, delete the one we're about to fetch, then expect to get the
    // "next" object we would have gotten after that.  But, do it in reverse!
    //

    class QueryStageCollscanInvalidateUpcomingObjectBackward : public QueryStageCollectionScanBase {
    public:
        void run() {
            Client::WriteContext ctx(ns());
            Collection* coll = ctx.ctx().db()->getCollection(ns());

            // Get the DiskLocs that would be returned by an in-order scan.
            vector<DiskLoc> locs;
            getLocs(coll, CollectionScanParams::BACKWARD, &locs);

            // Configure the scan.
            CollectionScanParams params;
            params.collection = coll;
            params.direction = CollectionScanParams::BACKWARD;
            params.tailable = false;

            WorkingSet ws;
            scoped_ptr<CollectionScan> scan(new CollectionScan(params, &ws, NULL));

            int count = 0;
            while (count < 10) {
                WorkingSetID id = WorkingSet::INVALID_ID;
                PlanStage::StageState state = scan->work(&id);
                if (PlanStage::ADVANCED == state) {
                    WorkingSetMember* member = ws.get(id);
                    ASSERT_EQUALS(coll->docFor(locs[count])["foo"].numberInt(),
                                  member->obj["foo"].numberInt());
                    ++count;
                }
            }

            // Remove locs[count].
            scan->prepareToYield();
            scan->invalidate(locs[count], INVALIDATION_DELETION);
            remove(coll->docFor(locs[count]));
            scan->recoverFromYield();

            // Skip over locs[count].
            ++count;

            // Expect the rest.
            while (!scan->isEOF()) {
                WorkingSetID id = WorkingSet::INVALID_ID;
                PlanStage::StageState state = scan->work(&id);
                if (PlanStage::ADVANCED == state) {
                    WorkingSetMember* member = ws.get(id);
                    ASSERT_EQUALS(coll->docFor(locs[count])["foo"].numberInt(),
                                  member->obj["foo"].numberInt());
                    ++count;
                }
            }

            ASSERT_EQUALS(numObj(), count);
        }
    };

    class All : public Suite {
    public:
        All() : Suite( "QueryStageCollectionScan" ) {}

        void setupTests() {
            // These tests are ported from pdfile.cpp
            /* SERVER-13640
            add<QueryStageCollscanEmpty>();
            add<QueryStageCollscanEmptyLooped>();
            add<QueryStageCollscanEmptyMultiExtentLooped>();
            add<QueryStageCollscanSingle>();
            add<QueryStageCollscanNewCapFirst>();
            add<QueryStageCollscanNewCapLast>();
            add<QueryStageCollscanNewCapMiddle>();
            add<QueryStageCollscanFirstExtent>();
            add<QueryStageCollscanLastExtent>();
            add<QueryStageCollscanMidExtent>();
            add<QueryStageCollscanAloneInExtent>();
            add<QueryStageCollscanFirstInExtent>();
            add<QueryStageCollscanLastInExtent>();
            */
            // These are not.  Stage-specific tests below.
            add<QueryStageCollscanBasicForward>();
            add<QueryStageCollscanBasicBackward>();
            add<QueryStageCollscanBasicForwardWithMatch>();
            add<QueryStageCollscanBasicBackwardWithMatch>();
            add<QueryStageCollscanObjectsInOrderForward>();
            add<QueryStageCollscanObjectsInOrderBackward>();
            add<QueryStageCollscanInvalidateUpcomingObject>();
            add<QueryStageCollscanInvalidateUpcomingObjectBackward>();
        }
    } all;

}