diff options
author | Andy Schwerin <schwerin@mongodb.com> | 2014-11-04 16:17:48 -0500 |
---|---|---|
committer | Andy Schwerin <schwerin@mongodb.com> | 2014-11-05 15:38:53 -0500 |
commit | d324cff2fccfd7f2f1397093e01a1eb4af9a3e52 (patch) | |
tree | 6b789f95a95ba33d6889c9ba898b77c03508ea8c /src/mongo/dbtests/dbtests.cpp | |
parent | ca0d6d5d907ebe39437b4032ccb4795946573183 (diff) | |
download | mongo-d324cff2fccfd7f2f1397093e01a1eb4af9a3e52.tar.gz |
SERVER-15882 Get rid of ensureIndex in dbtests.
Diffstat (limited to 'src/mongo/dbtests/dbtests.cpp')
-rw-r--r-- | src/mongo/dbtests/dbtests.cpp | 59 |
1 files changed, 53 insertions, 6 deletions
diff --git a/src/mongo/dbtests/dbtests.cpp b/src/mongo/dbtests/dbtests.cpp index 5ec745a8451..dc92aee5375 100644 --- a/src/mongo/dbtests/dbtests.cpp +++ b/src/mongo/dbtests/dbtests.cpp @@ -29,34 +29,81 @@ * then also delete it in the license file. */ -#include "mongo/pch.h" +#include "mongo/platform/basic.h" + +#include "mongo/dbtests/dbtests.h" #include "mongo/base/initializer.h" -#include "mongo/db/commands.h" #include "mongo/db/auth/authorization_manager.h" #include "mongo/db/auth/authorization_manager_global.h" #include "mongo/db/auth/authz_manager_external_state_mock.h" +#include "mongo/db/catalog/index_create.h" +#include "mongo/db/commands.h" #include "mongo/db/global_environment_d.h" #include "mongo/db/global_environment_experiment.h" #include "mongo/db/repl/repl_coordinator_global.h" #include "mongo/db/repl/repl_coordinator_mock.h" -#include "mongo/dbtests/dbtests.h" #include "mongo/dbtests/framework.h" -#include "mongo/util/exception_filter_win32.h" #include "mongo/util/gcov.h" +#include "mongo/util/quick_exit.h" +#include "mongo/util/signal_handlers_synchronous.h" #include "mongo/util/startup_test.h" #include "mongo/util/text.h" -#include "mongo/util/quick_exit.h" namespace mongo { +namespace dbtests { // This specifies default dbpath for our testing framework const std::string default_test_dbpath = "/tmp/unittest"; + + Status createIndex(OperationContext* txn, + const StringData &ns, + const BSONObj& keys, + bool unique) { + BSONObjBuilder specBuilder; + specBuilder << + "name" << DBClientBase::genIndexName(keys) << + "ns" << ns << + "key" << keys; + if (unique) { + specBuilder << "unique" << true; + } + return createIndexFromSpec(txn, ns, specBuilder.done()); + } + + Status createIndexFromSpec(OperationContext* txn, const StringData& ns, const BSONObj& spec) { + AutoGetOrCreateDb autoDb(txn, nsToDatabaseSubstring(ns), MODE_X); + Collection* coll; + { + WriteUnitOfWork wunit(txn); + coll = autoDb.getDb()->getOrCreateCollection(txn, ns); + invariant(coll); + wunit.commit(); + } + MultiIndexBlock indexer(txn, coll); + Status status = indexer.init(spec); + if (status == ErrorCodes::IndexAlreadyExists) { + return Status::OK(); + } + if (!status.isOK()) { + return status; + } + status = indexer.insertAllDocumentsInCollection(); + if (!status.isOK()) { + return status; + } + WriteUnitOfWork wunit(txn); + indexer.commit(); + wunit.commit(); + return Status::OK(); + } + +} // namespace dbtests } // namespace mongo int dbtestsMain( int argc, char** argv, char** envp ) { static StaticObserver StaticObserver; - setWindowsUnhandledExceptionFilter(); + ::mongo::setupSynchronousSignalHandlers(); setGlobalEnvironment(new GlobalEnvironmentMongoD()); repl::ReplSettings replSettings; replSettings.oplogSize = 10 * 1024 * 1024; |