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
654
655
656
657
658
659
660
661
662
|
// namespacetests.cpp : namespace.{h,cpp} unit tests.
//
/**
* Copyright (C) 2008-2014 MongoDB 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.
*/
#define MONGO_LOG_DEFAULT_COMPONENT ::mongo::logger::LogComponent::kDefault
#include "mongo/platform/basic.h"
#include <string>
#include "mongo/db/catalog/collection.h"
#include "mongo/db/catalog/database_holder.h"
#include "mongo/db/client.h"
#include "mongo/db/db_raii.h"
#include "mongo/db/index/expression_keys_private.h"
#include "mongo/db/index_legacy.h"
#include "mongo/db/index_names.h"
#include "mongo/db/json.h"
#include "mongo/db/query/internal_plans.h"
#include "mongo/db/storage/mmap_v1/catalog/namespace.h"
#include "mongo/db/storage/mmap_v1/catalog/namespace_details.h"
#include "mongo/db/storage/mmap_v1/catalog/namespace_details_rsv1_metadata.h"
#include "mongo/db/storage/mmap_v1/extent.h"
#include "mongo/db/storage/mmap_v1/extent_manager.h"
#include "mongo/db/storage/mmap_v1/mmap_v1_extent_manager.h"
#include "mongo/db/storage/mmap_v1/record_store_v1_capped.h"
#include "mongo/db/storage/mmap_v1/record_store_v1_simple.h"
#include "mongo/db/storage/storage_engine.h"
#include "mongo/dbtests/dbtests.h"
#include "mongo/util/log.h"
namespace NamespaceTests {
using std::string;
const int MinExtentSize = 4096;
namespace MissingFieldTests {
/** A missing field is represented as null in a btree index. */
class BtreeIndexMissingField {
public:
void run() {
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext();
OperationContext& txn = *txnPtr;
BSONObj spec(BSON("key" << BSON("a" << 1)));
ASSERT_EQUALS(jstNULL,
IndexLegacy::getMissingField(&txn, NULL, spec).firstElement().type());
}
};
/** A missing field is represented as null in a 2d index. */
class TwoDIndexMissingField {
public:
void run() {
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext();
OperationContext& txn = *txnPtr;
BSONObj spec(BSON("key" << BSON("a"
<< "2d")));
ASSERT_EQUALS(jstNULL,
IndexLegacy::getMissingField(&txn, NULL, spec).firstElement().type());
}
};
/** A missing field is represented with the hash of null in a hashed index. */
class HashedIndexMissingField {
public:
void run() {
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext();
OperationContext& txn = *txnPtr;
BSONObj spec(BSON("key" << BSON("a"
<< "hashed")));
BSONObj nullObj = BSON("a" << BSONNULL);
// Call getKeys on the nullObj.
BSONObjSet nullFieldKeySet;
const CollatorInterface* collator = nullptr;
ExpressionKeysPrivate::getHashKeys(nullObj, "a", 0, 0, false, collator, &nullFieldKeySet);
BSONElement nullFieldFromKey = nullFieldKeySet.begin()->firstElement();
ASSERT_EQUALS(ExpressionKeysPrivate::makeSingleHashKey(nullObj.firstElement(), 0, 0),
nullFieldFromKey.Long());
BSONObj missingField = IndexLegacy::getMissingField(&txn, NULL, spec);
ASSERT_EQUALS(NumberLong, missingField.firstElement().type());
ASSERT_EQUALS(nullFieldFromKey, missingField.firstElement());
}
};
/**
* A missing field is represented with the hash of null in a hashed index. This hash value
* depends on the hash seed.
*/
class HashedIndexMissingFieldAlternateSeed {
public:
void run() {
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext();
OperationContext& txn = *txnPtr;
BSONObj spec(BSON("key" << BSON("a"
<< "hashed") << "seed" << 0x5eed));
BSONObj nullObj = BSON("a" << BSONNULL);
BSONObjSet nullFieldKeySet;
const CollatorInterface* collator = nullptr;
ExpressionKeysPrivate::getHashKeys(
nullObj, "a", 0x5eed, 0, false, collator, &nullFieldKeySet);
BSONElement nullFieldFromKey = nullFieldKeySet.begin()->firstElement();
ASSERT_EQUALS(ExpressionKeysPrivate::makeSingleHashKey(nullObj.firstElement(), 0x5eed, 0),
nullFieldFromKey.Long());
// Ensure that getMissingField recognizes that the seed is different (and returns
// the right key).
BSONObj missingField = IndexLegacy::getMissingField(&txn, NULL, spec);
ASSERT_EQUALS(NumberLong, missingField.firstElement().type());
ASSERT_EQUALS(nullFieldFromKey, missingField.firstElement());
}
};
} // namespace MissingFieldTests
namespace NamespaceDetailsTests {
#if 0 // SERVER-13640
class Base {
const char *ns_;
Lock::GlobalWrite lk;
OldClientContext _context;
public:
Base( const char *ns = "unittests.NamespaceDetailsTests" ) : ns_( ns ) , _context( ns ) {}
virtual ~Base() {
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr;
if ( !nsd() )
return;
_context.db()->dropCollection( &txn, ns() );
}
protected:
void create() {
Lock::GlobalWrite lk;
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr;
ASSERT( userCreateNS( &txn, db(), ns(), fromjson( spec() ), false ).isOK() );
}
virtual string spec() const = 0;
int nRecords() const {
int count = 0;
const Extent* ext;
for ( RecordId extLoc = nsd()->firstExtent();
!extLoc.isNull();
extLoc = ext->xnext) {
ext = extentManager()->getExtent(extLoc);
int fileNo = ext->firstRecord.a();
if ( fileNo == -1 )
continue;
for ( int recOfs = ext->firstRecord.getOfs(); recOfs != RecordId::NullOfs;
recOfs = recordStore()->recordFor(RecordId(fileNo, recOfs))->nextOfs() ) {
++count;
}
}
ASSERT_EQUALS( count, nsd()->numRecords() );
return count;
}
int nExtents() const {
int count = 0;
for ( RecordId extLoc = nsd()->firstExtent();
!extLoc.isNull();
extLoc = extentManager()->getExtent(extLoc)->xnext ) {
++count;
}
return count;
}
const char *ns() const {
return ns_;
}
const NamespaceDetails *nsd() const {
Collection* c = collection();
if ( !c )
return NULL;
return c->detailsDeprecated();
}
const RecordStore* recordStore() const {
Collection* c = collection();
if ( !c )
return NULL;
return c->getRecordStore();
}
Database* db() const {
return _context.db();
}
const ExtentManager* extentManager() const {
return db()->getExtentManager();
}
Collection* collection() const {
return db()->getCollection( ns() );
}
static BSONObj bigObj() {
BSONObjBuilder b;
b.appendOID("_id", 0, true);
string as( 187, 'a' );
b.append( "a", as );
return b.obj();
}
};
class Create : public Base {
public:
void run() {
create();
ASSERT( nsd() );
ASSERT_EQUALS( 0, nRecords() );
ASSERT( nsd()->firstExtent() == nsd()->capExtent() );
RecordId initial = RecordId();
initial.setInvalid();
ASSERT( initial == nsd()->capFirstNewRecord() );
}
virtual string spec() const { return "{\"capped\":true,\"size\":512,\"$nExtents\":1}"; }
};
class SingleAlloc : public Base {
public:
void run() {
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr;
create();
BSONObj b = bigObj();
ASSERT( collection()->insertDocument( &txn, b, true ).isOK() );
ASSERT_EQUALS( 1, nRecords() );
}
virtual string spec() const { return "{\"capped\":true,\"size\":512,\"$nExtents\":1}"; }
};
class Realloc : public Base {
public:
void run() {
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr;
create();
const int N = 20;
const int Q = 16; // these constants depend on the size of the bson object, the extent
// size allocated by the system too
RecordId l[ N ];
for ( int i = 0; i < N; ++i ) {
BSONObj b = bigObj();
StatusWith<RecordId> status =
ASSERT( collection()->insertDocument( &txn, b, true ).isOK() );
l[ i ] = status.getValue();
ASSERT( !l[ i ].isNull() );
ASSERT( nRecords() <= Q );
//ASSERT_EQUALS( 1 + i % 2, nRecords() );
if ( i >= 16 )
ASSERT( l[ i ] == l[ i - Q] );
}
}
virtual string spec() const { return "{\"capped\":true,\"size\":512,\"$nExtents\":1}"; }
};
class TwoExtent : public Base {
public:
void run() {
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr;
create();
ASSERT_EQUALS( 2, nExtents() );
RecordId l[ 8 ];
for ( int i = 0; i < 8; ++i ) {
StatusWith<RecordId> status =
ASSERT( collection()->insertDocument( &txn, bigObj(), true ).isOK() );
l[ i ] = status.getValue();
ASSERT( !l[ i ].isNull() );
//ASSERT_EQUALS( i < 2 ? i + 1 : 3 + i % 2, nRecords() );
//if ( i > 3 )
// ASSERT( l[ i ] == l[ i - 4 ] );
}
ASSERT( nRecords() == 8 );
// Too big
BSONObjBuilder bob;
bob.appendOID( "_id", NULL, true );
bob.append( "a", string( MinExtentSize + 500, 'a' ) ); // min extent size is now 4096
BSONObj bigger = bob.done();
ASSERT( !collection()->insertDocument( &txn, bigger, false ).isOK() );
ASSERT_EQUALS( 0, nRecords() );
}
private:
virtual string spec() const {
return "{\"capped\":true,\"size\":512,\"$nExtents\":2}";
}
};
BSONObj docForRecordSize( int size ) {
BSONObjBuilder b;
b.append( "_id", 5 );
b.append( "x", string( size - Record::HeaderSize - 22, 'x' ) );
BSONObj x = b.obj();
ASSERT_EQUALS( Record::HeaderSize + x.objsize(), size );
return x;
}
/**
* alloc() does not quantize records in capped collections.
* NB: this actually tests that the code in Database::createCollection doesn't set
* PowerOf2Sizes for capped collections.
*/
class AllocCappedNotQuantized : public Base {
public:
void run() {
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr;
create();
ASSERT( nsd()->isCapped() );
ASSERT( !nsd()->isUserFlagSet( NamespaceDetails::Flag_UsePowerOf2Sizes ) );
StatusWith<RecordId> result =
collection()->insertDocument( &txn, docForRecordSize( 300 ), false );
ASSERT( result.isOK() );
Record* record = collection()->getRecordStore()->recordFor( result.getValue() );
// Check that no quantization is performed.
ASSERT_EQUALS( 300, record->lengthWithHeaders() );
}
virtual string spec() const { return "{capped:true,size:2048}"; }
};
/* test NamespaceDetails::cappedTruncateAfter(const char *ns, RecordId loc)
*/
class TruncateCapped : public Base {
virtual string spec() const {
return "{\"capped\":true,\"size\":512,\"$nExtents\":2}";
}
void pass(int p) {
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr;
create();
ASSERT_EQUALS( 2, nExtents() );
BSONObj b = bigObj();
int N = MinExtentSize / b.objsize() * nExtents() + 5;
int T = N - 4;
RecordId truncAt;
//RecordId l[ 8 ];
for ( int i = 0; i < N; ++i ) {
BSONObj bb = bigObj();
StatusWith<RecordId> status = collection()->insertDocument( &txn, bb, true );
ASSERT( status.isOK() );
RecordId a = status.getValue();
if( T == i )
truncAt = a;
ASSERT( !a.isNull() );
/*ASSERT_EQUALS( i < 2 ? i + 1 : 3 + i % 2, nRecords() );
if ( i > 3 )
ASSERT( l[ i ] == l[ i - 4 ] );*/
}
ASSERT( nRecords() < N );
RecordId last, first;
{
unique_ptr<Runner> runner(InternalPlanner::collectionScan(&txn,
ns(),
collection(),
InternalPlanner::BACKWARD));
runner->getNext(NULL, &last);
ASSERT( !last.isNull() );
}
{
unique_ptr<Runner> runner(InternalPlanner::collectionScan(&txn,
ns(),
collection(),
InternalPlanner::FORWARD));
runner->getNext(NULL, &first);
ASSERT( !first.isNull() );
ASSERT( first != last ) ;
}
collection()->temp_cappedTruncateAfter(&txn, truncAt, false);
ASSERT_EQUALS( collection()->numRecords() , 28u );
{
RecordId loc;
unique_ptr<Runner> runner(InternalPlanner::collectionScan(&txn,
ns(),
collection(),
InternalPlanner::FORWARD));
runner->getNext(NULL, &loc);
ASSERT( first == loc);
}
{
unique_ptr<Runner> runner(InternalPlanner::collectionScan(&txn,
ns(),
collection(),
InternalPlanner::BACKWARD));
RecordId loc;
runner->getNext(NULL, &loc);
ASSERT( last != loc );
ASSERT( !last.isNull() );
}
// Too big
BSONObjBuilder bob;
bob.appendOID("_id", 0, true);
bob.append( "a", string( MinExtentSize + 300, 'a' ) );
BSONObj bigger = bob.done();
ASSERT( !collection()->insertDocument( &txn, bigger, true ).isOK() );
ASSERT_EQUALS( 0, nRecords() );
}
public:
void run() {
// log() << "******** NOT RUNNING TruncateCapped test yet ************" << endl;
pass(0);
}
};
#endif // SERVER-13640
#if 0 // XXXXXX - once RecordStore is clean, we can put this back
class Migrate : public Base {
public:
void run() {
create();
nsd()->deletedListEntry( 2 ) = nsd()->cappedListOfAllDeletedRecords().drec()->
nextDeleted().drec()->nextDeleted();
nsd()->cappedListOfAllDeletedRecords().drec()->nextDeleted().drec()->
nextDeleted().writing() = RecordId();
nsd()->cappedLastDelRecLastExtent().Null();
NamespaceDetails *d = nsd();
zero( &d->capExtent() );
zero( &d->capFirstNewRecord() );
// this has a side effect of called NamespaceDetails::cappedCheckMigrate
db()->namespaceIndex().details( ns() );
ASSERT( nsd()->firstExtent() == nsd()->capExtent() );
ASSERT( nsd()->capExtent().getOfs() != 0 );
ASSERT( !nsd()->capFirstNewRecord().isValid() );
int nDeleted = 0;
for ( RecordId i = nsd()->cappedListOfAllDeletedRecords();
!i.isNull(); i = i.drec()->nextDeleted(), ++nDeleted );
ASSERT_EQUALS( 10, nDeleted );
ASSERT( nsd()->cappedLastDelRecLastExtent().isNull() );
}
private:
static void zero( RecordId *d ) {
memset( d, 0, sizeof( RecordId ) );
}
virtual string spec() const {
return "{\"capped\":true,\"size\":512,\"$nExtents\":10}";
}
};
#endif
// This isn't a particularly useful test, and because it doesn't clean up
// after itself, /tmp/unittest needs to be cleared after running.
// class BigCollection : public Base {
// public:
// BigCollection() : Base( "NamespaceDetailsTests_BigCollection" ) {}
// void run() {
// create();
// ASSERT_EQUALS( 2, nExtents() );
// }
// private:
// virtual string spec() const {
// // NOTE 256 added to size in _userCreateNS()
// long long big = DataFile::maxSize() - DataFileHeader::HeaderSize;
// stringstream ss;
// ss << "{\"capped\":true,\"size\":" << big << "}";
// return ss.str();
// }
// };
#if 0 // SERVER-13640
class SwapIndexEntriesTest : public Base {
public:
void run() {
create();
NamespaceDetails *nsd = collection()->detailsWritable();
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext(); OperationContext& txn = *txnPtr;
// Set 2 & 54 as multikey
nsd->setIndexIsMultikey(&txn, 2, true);
nsd->setIndexIsMultikey(&txn, 54, true);
ASSERT(nsd->isMultikey(2));
ASSERT(nsd->isMultikey(54));
// Flip 2 & 47
nsd->setIndexIsMultikey(&txn, 2, false);
nsd->setIndexIsMultikey(&txn, 47, true);
ASSERT(!nsd->isMultikey(2));
ASSERT(nsd->isMultikey(47));
// Reset entries that are already true
nsd->setIndexIsMultikey(&txn, 54, true);
nsd->setIndexIsMultikey(&txn, 47, true);
ASSERT(nsd->isMultikey(54));
ASSERT(nsd->isMultikey(47));
// Two non-multi-key
nsd->setIndexIsMultikey(&txn, 2, false);
nsd->setIndexIsMultikey(&txn, 43, false);
ASSERT(!nsd->isMultikey(2));
ASSERT(nsd->isMultikey(54));
ASSERT(nsd->isMultikey(47));
ASSERT(!nsd->isMultikey(43));
}
virtual string spec() const { return "{\"capped\":true,\"size\":512,\"$nExtents\":1}"; }
};
#endif // SERVER-13640
} // namespace NamespaceDetailsTests
namespace DatabaseTests {
class RollbackCreateCollection {
public:
void run() {
const string dbName = "rollback_create_collection";
const string committedName = dbName + ".committed";
const string rolledBackName = dbName + ".rolled_back";
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext();
OperationContext& txn = *txnPtr;
ScopedTransaction transaction(&txn, MODE_IX);
Lock::DBLock lk(txn.lockState(), dbName, MODE_X);
bool justCreated;
Database* db = dbHolder().openDb(&txn, dbName, &justCreated);
ASSERT(justCreated);
Collection* committedColl;
{
WriteUnitOfWork wunit(&txn);
ASSERT_FALSE(db->getCollection(committedName));
committedColl = db->createCollection(&txn, committedName);
ASSERT_EQUALS(db->getCollection(committedName), committedColl);
wunit.commit();
}
ASSERT_EQUALS(db->getCollection(committedName), committedColl);
{
WriteUnitOfWork wunit(&txn);
ASSERT_FALSE(db->getCollection(rolledBackName));
Collection* rolledBackColl = db->createCollection(&txn, rolledBackName);
ASSERT_EQUALS(db->getCollection(rolledBackName), rolledBackColl);
// not committing so creation should be rolled back
}
// The rolledBackCollection creation should have been rolled back
ASSERT_FALSE(db->getCollection(rolledBackName));
// The committedCollection should not have been affected by the rollback. Holders
// of the original Collection pointer should still be valid.
ASSERT_EQUALS(db->getCollection(committedName), committedColl);
}
};
class RollbackDropCollection {
public:
void run() {
const string dbName = "rollback_drop_collection";
const string droppedName = dbName + ".dropped";
const string rolledBackName = dbName + ".rolled_back";
const ServiceContext::UniqueOperationContext txnPtr = cc().makeOperationContext();
OperationContext& txn = *txnPtr;
ScopedTransaction transaction(&txn, MODE_IX);
Lock::DBLock lk(txn.lockState(), dbName, MODE_X);
bool justCreated;
Database* db = dbHolder().openDb(&txn, dbName, &justCreated);
ASSERT(justCreated);
{
WriteUnitOfWork wunit(&txn);
ASSERT_FALSE(db->getCollection(droppedName));
Collection* droppedColl;
droppedColl = db->createCollection(&txn, droppedName);
ASSERT_EQUALS(db->getCollection(droppedName), droppedColl);
db->dropCollection(&txn, droppedName);
wunit.commit();
}
// Should have been really dropped
ASSERT_FALSE(db->getCollection(droppedName));
{
WriteUnitOfWork wunit(&txn);
ASSERT_FALSE(db->getCollection(rolledBackName));
Collection* rolledBackColl = db->createCollection(&txn, rolledBackName);
wunit.commit();
ASSERT_EQUALS(db->getCollection(rolledBackName), rolledBackColl);
db->dropCollection(&txn, rolledBackName);
// not committing so dropping should be rolled back
}
// The rolledBackCollection dropping should have been rolled back.
// Original Collection pointers are no longer valid.
ASSERT(db->getCollection(rolledBackName));
// The droppedCollection should not have been restored by the rollback.
ASSERT_FALSE(db->getCollection(droppedName));
}
};
} // namespace DatabaseTests
class All : public Suite {
public:
All() : Suite("namespace") {}
void setupTests() {
add<MissingFieldTests::BtreeIndexMissingField>();
add<MissingFieldTests::TwoDIndexMissingField>();
add<MissingFieldTests::HashedIndexMissingField>();
add<MissingFieldTests::HashedIndexMissingFieldAlternateSeed>();
// add< NamespaceDetailsTests::Create >();
// add< NamespaceDetailsTests::SingleAlloc >();
// add< NamespaceDetailsTests::Realloc >();
// add< NamespaceDetailsTests::AllocCappedNotQuantized >();
// add< NamespaceDetailsTests::TwoExtent >();
// add< NamespaceDetailsTests::TruncateCapped >();
// add< NamespaceDetailsTests::Migrate >();
// add< NamespaceDetailsTests::SwapIndexEntriesTest >();
// add< NamespaceDetailsTests::BigCollection >();
#if 0
// until ROLLBACK_ENABLED
add< DatabaseTests::RollbackCreateCollection >();
add< DatabaseTests::RollbackDropCollection >();
#endif
}
};
SuiteInstance<All> myall;
} // namespace NamespaceTests
|