From 1e2175e1b4c230c2b7fce724cbafc61c5272b522 Mon Sep 17 00:00:00 2001 From: Eliot Horowitz Date: Tue, 4 Mar 2014 16:28:28 -0500 Subject: SERVER-11643: remove all active nsdetails calls in tests --- src/mongo/dbtests/clienttests.cpp | 13 +++++++++---- src/mongo/dbtests/namespacetests.cpp | 21 +++++++++++++-------- src/mongo/dbtests/pdfiletests.cpp | 8 ++++---- src/mongo/dbtests/query_stage_collscan.cpp | 4 +++- src/mongo/dbtests/queryutiltests.cpp | 5 ++++- src/mongo/dbtests/replsettests.cpp | 14 ++++++-------- 6 files changed, 39 insertions(+), 26 deletions(-) (limited to 'src') diff --git a/src/mongo/dbtests/clienttests.cpp b/src/mongo/dbtests/clienttests.cpp index 096b0f142c8..e47e67ea4ea 100644 --- a/src/mongo/dbtests/clienttests.cpp +++ b/src/mongo/dbtests/clienttests.cpp @@ -31,8 +31,9 @@ #include "mongo/pch.h" #include "mongo/client/dbclientcursor.h" +#include "mongo/db/catalog/collection.h" +#include "mongo/db/catalog/database.h" #include "mongo/db/d_concurrency.h" -#include "mongo/db/pdfile.h" #include "mongo/dbtests/dbtests.h" namespace ClientTests { @@ -128,7 +129,11 @@ namespace ClientTests { db.insert(ns(), BSON("x" << 1 << "y" << 2)); db.insert(ns(), BSON("x" << 2 << "y" << 2)); - ASSERT_EQUALS(1, nsdetails(ns())->getCompletedIndexCount()); + Collection* collection = ctx.ctx().db()->getCollection( ns() ); + ASSERT( collection ); + IndexCatalog* indexCatalog = collection->getIndexCatalog(); + + ASSERT_EQUALS(1, indexCatalog->numIndexesReady()); // _id index ASSERT_EQUALS(1U, db.count("test.system.indexes")); // test.buildindex @@ -138,13 +143,13 @@ namespace ClientTests { db.ensureIndex(ns(), BSON("y" << 1), true); - ASSERT_EQUALS(1, nsdetails(ns())->getCompletedIndexCount()); + ASSERT_EQUALS(1, indexCatalog->numIndexesReady()); ASSERT_EQUALS(1U, db.count("test.system.indexes")); ASSERT_EQUALS(3U, db.count("test.system.namespaces")); db.ensureIndex(ns(), BSON("x" << 1), true); - ASSERT_EQUALS(2, nsdetails(ns())->getCompletedIndexCount()); + ASSERT_EQUALS(2, indexCatalog->numIndexesReady()); ASSERT_EQUALS(2U, db.count("test.system.indexes")); ASSERT_EQUALS(4U, db.count("test.system.namespaces")); } diff --git a/src/mongo/dbtests/namespacetests.cpp b/src/mongo/dbtests/namespacetests.cpp index 4a6a3311fc8..5df2966bf12 100644 --- a/src/mongo/dbtests/namespacetests.cpp +++ b/src/mongo/dbtests/namespacetests.cpp @@ -1075,11 +1075,14 @@ namespace NamespaceTests { return ns_; } NamespaceDetails *nsd() const { - return nsdetails( ns() )->writingWithExtra(); + return collection()->details()->writingWithExtra(); + } + Database* db() const { + return _context.db(); } Collection* collection() const { - Collection* c = _context.db()->getCollection( ns() ); - verify(c); + Collection* c = db()->getCollection( ns() ); + invariant(c); return c; } IndexCatalog* indexCatalog() const { @@ -1451,7 +1454,7 @@ namespace NamespaceTests { IndexDescriptor* desc = indexCatalog()->findIdIndex(); string indexNamespace = desc->indexNamespace(); ASSERT( !NamespaceString::normal( indexNamespace ) ); - NamespaceDetails* indexNsd = nsdetails( indexNamespace ); + NamespaceDetails* indexNsd = db()->namespaceIndex().details(indexNamespace); // Check that no quantization is performed. DiskLoc actualLocation = indexNsd->alloc( NULL, indexNamespace.c_str(), 300 ); @@ -1469,7 +1472,7 @@ namespace NamespaceTests { IndexDescriptor* desc = indexCatalog()->findIdIndex(); string indexNamespace = desc->indexNamespace(); ASSERT( !NamespaceString::normal( indexNamespace.c_str() ) ); - NamespaceDetails* indexNsd = nsdetails( indexNamespace.c_str() ); + NamespaceDetails* indexNsd = db()->namespaceIndex().details(indexNamespace); // Check that multiple of 4 quantization is performed. DiskLoc actualLocation = indexNsd->alloc( NULL, indexNamespace.c_str(), 298 ); @@ -1604,7 +1607,7 @@ namespace NamespaceTests { } ASSERT( nRecords() < N ); - NamespaceDetails *nsd = nsdetails(ns()); + NamespaceDetails*nsd = collection()->details(); DiskLoc last, first; { @@ -1664,10 +1667,12 @@ namespace NamespaceTests { nsd()->cappedListOfAllDeletedRecords().drec()->nextDeleted().drec()->nextDeleted().writing() = DiskLoc(); nsd()->cappedLastDelRecLastExtent().Null(); NamespaceDetails *d = nsd(); + zero( &d->capExtent() ); zero( &d->capFirstNewRecord() ); - nsd(); + // this has a side effect of called NamespaceDetails::cappedCheckMigrate + db()->namespaceIndex().details( ns() ); ASSERT( nsd()->firstExtent() == nsd()->capExtent() ); ASSERT( nsd()->capExtent().getOfs() != 0 ); @@ -1716,7 +1721,7 @@ namespace NamespaceTests { public: void run() { create(); - NamespaceDetails *nsd = nsdetails(ns()); + NamespaceDetails *nsd = collection()->details(); // Set 2 & 54 as multikey nsd->setIndexIsMultikey(2, true); diff --git a/src/mongo/dbtests/pdfiletests.cpp b/src/mongo/dbtests/pdfiletests.cpp index ae2e37dd2eb..d3a8580acdc 100644 --- a/src/mongo/dbtests/pdfiletests.cpp +++ b/src/mongo/dbtests/pdfiletests.cpp @@ -46,16 +46,16 @@ namespace PdfileTests { Base() : _context( ns() ) { } virtual ~Base() { - if ( !nsd() ) + if ( !collection() ) return; _context.db()->dropCollection( ns() ); } protected: - static const char *ns() { + const char *ns() { return "unittests.pdfiletests.Insert"; } - static NamespaceDetails *nsd() { - return nsdetails( ns() ); + Collection* collection() { + return _context.db()->getCollection( ns() ); } Lock::GlobalWrite lk_; diff --git a/src/mongo/dbtests/query_stage_collscan.cpp b/src/mongo/dbtests/query_stage_collscan.cpp index b74fb9e53e5..c10c8662607 100644 --- a/src/mongo/dbtests/query_stage_collscan.cpp +++ b/src/mongo/dbtests/query_stage_collscan.cpp @@ -150,7 +150,9 @@ namespace QueryStageCollectionScan { static const char *ns() { return "unittests.QueryStageCollectionScanCapped"; } - static NamespaceDetails *nsd() { return nsdetails(ns()); } + Database* db() { return _context.db(); } + Collection* collection() { return db()->getCollection( ns() ); } + NamespaceDetails *nsd() { return collection()->details(); } private: Lock::GlobalWrite lk_; diff --git a/src/mongo/dbtests/queryutiltests.cpp b/src/mongo/dbtests/queryutiltests.cpp index 56d6ac73926..dea9349d0f7 100644 --- a/src/mongo/dbtests/queryutiltests.cpp +++ b/src/mongo/dbtests/queryutiltests.cpp @@ -1594,8 +1594,11 @@ namespace QueryUtilTests { } protected: static const char *ns() { return "unittests.FieldRangeSetPairTests"; } - static NamespaceDetails *nsd() { return nsdetails( ns() ); } Client::Context* ctx() { return &_ctx; } + Database* db() { return _ctx.db(); } + Collection* collection() { return db()->getCollection( ns() ); } + NamespaceDetails *nsd() { return collection()->details(); } + IndexDetails *index( const BSONObj &key, int* indexNoOut = NULL ) { stringstream ss; ss << indexNum_++; diff --git a/src/mongo/dbtests/replsettests.cpp b/src/mongo/dbtests/replsettests.cpp index b363d3f7f1e..b85b1ea9f07 100644 --- a/src/mongo/dbtests/replsettests.cpp +++ b/src/mongo/dbtests/replsettests.cpp @@ -173,14 +173,13 @@ namespace ReplSetTests { void drop() { Client::WriteContext c(ns()); - string errmsg; - BSONObjBuilder result; + Database* db = c.ctx().db(); - if (nsdetails(ns()) == NULL) { + if ( db->getCollection( ns() ) == NULL ) { return; } - c.ctx().db()->dropCollection(ns()); + db->dropCollection(ns()); } static void setup() { replSettings.replSet = "foo"; @@ -323,10 +322,9 @@ namespace ReplSetTests { void dropCapped() { Client::Context c(_cappedNs); - if (nsdetails(_cappedNs) != NULL) { - string errmsg; - BSONObjBuilder result; - c.db()->dropCollection( _cappedNs ); + Database* db = c.db(); + if ( db->getCollection( _cappedNs ) ) { + db->dropCollection( _cappedNs ); } } -- cgit v1.2.1