From eaf507a65787759935e786a15ea58efb91fc004b Mon Sep 17 00:00:00 2001 From: Benety Goh Date: Fri, 17 Jun 2016 14:31:49 -0400 Subject: SERVER-24490 oplog buffer collection should use storage interface --- src/mongo/db/repl/storage_interface_mock.h | 95 +++++++++++++++++++++++++----- 1 file changed, 79 insertions(+), 16 deletions(-) (limited to 'src/mongo/db/repl/storage_interface_mock.h') diff --git a/src/mongo/db/repl/storage_interface_mock.h b/src/mongo/db/repl/storage_interface_mock.h index 143d5d367cd..b25d91f8978 100644 --- a/src/mongo/db/repl/storage_interface_mock.h +++ b/src/mongo/db/repl/storage_interface_mock.h @@ -87,6 +87,33 @@ class StorageInterfaceMock : public StorageInterface { MONGO_DISALLOW_COPYING(StorageInterfaceMock); public: + // Used for testing. + + using CreateCollectionForBulkFn = + stdx::function>( + const NamespaceString& nss, + const CollectionOptions& options, + const BSONObj idIndexSpec, + const std::vector& secondaryIndexSpecs)>; + using InsertDocumentFn = stdx::function; + using InsertDocumentsFn = stdx::function& docs)>; + using DropUserDatabasesFn = stdx::function; + using CreateOplogFn = stdx::function; + using CreateCollectionFn = stdx::function; + using DropCollectionFn = + stdx::function; + using FindOneFn = stdx::function(OperationContext* txn, + const NamespaceString& nss, + const BSONObj& indexKeyPattern, + ScanDirection scanDirection)>; + using DeleteOneFn = stdx::function(OperationContext* txn, + const NamespaceString& nss, + const BSONObj& indexKeyPattern, + ScanDirection scanDirection)>; + StorageInterfaceMock() = default; void startup() override; @@ -113,7 +140,7 @@ public: const CollectionOptions& options, const BSONObj idIndexSpec, const std::vector& secondaryIndexSpecs) override { - return createCollectionFn(nss, options, idIndexSpec, secondaryIndexSpecs); + return createCollectionForBulkFn(nss, options, idIndexSpec, secondaryIndexSpecs); }; Status insertDocument(OperationContext* txn, @@ -122,10 +149,10 @@ public: return insertDocumentFn(txn, nss, doc); }; - StatusWith insertOplogDocuments(OperationContext* txn, - const NamespaceString& nss, - const std::vector& ops) override { - return insertOplogDocumentsFn(txn, nss, ops); + Status insertDocuments(OperationContext* txn, + const NamespaceString& nss, + const std::vector& docs) override { + return insertDocumentsFn(txn, nss, docs); } Status dropReplicatedDatabases(OperationContext* txn) override { @@ -136,31 +163,51 @@ public: return createOplogFn(txn, nss); }; + Status createCollection(OperationContext* txn, + const NamespaceString& nss, + const CollectionOptions& options) override { + return createCollFn(txn, nss, options); + } + Status dropCollection(OperationContext* txn, const NamespaceString& nss) override { return dropCollFn(txn, nss); }; + StatusWith findOne(OperationContext* txn, + const NamespaceString& nss, + const BSONObj& indexKeyPattern, + ScanDirection scanDirection) override { + return findOneFn(txn, nss, indexKeyPattern, scanDirection); + } + + StatusWith deleteOne(OperationContext* txn, + const NamespaceString& nss, + const BSONObj& indexKeyPattern, + ScanDirection scanDirection) override { + return deleteOneFn(txn, nss, indexKeyPattern, scanDirection); + } + Status isAdminDbValid(OperationContext* txn) override { return Status::OK(); }; // Testing functions. - CreateCollectionFn createCollectionFn = [](const NamespaceString& nss, - const CollectionOptions& options, - const BSONObj idIndexSpec, - const std::vector& secondaryIndexSpecs) - -> StatusWith> { - return Status{ErrorCodes::IllegalOperation, "CreateCollectionFn not implemented."}; - }; + CreateCollectionForBulkFn createCollectionForBulkFn = + [](const NamespaceString& nss, + const CollectionOptions& options, + const BSONObj idIndexSpec, + const std::vector& + secondaryIndexSpecs) -> StatusWith> { + return Status{ErrorCodes::IllegalOperation, "CreateCollectionForBulkFn not implemented."}; + }; InsertDocumentFn insertDocumentFn = [](OperationContext* txn, const NamespaceString& nss, const BSONObj& doc) { return Status{ErrorCodes::IllegalOperation, "InsertDocumentFn not implemented."}; }; - InsertOplogDocumentsFn insertOplogDocumentsFn = - [](OperationContext* txn, const NamespaceString& nss, const std::vector& ops) { - return StatusWith( - Status{ErrorCodes::IllegalOperation, "InsertOplogDocumentsFn not implemented."}); + InsertDocumentsFn insertDocumentsFn = + [](OperationContext* txn, const NamespaceString& nss, const std::vector& docs) { + return Status{ErrorCodes::IllegalOperation, "InsertDocumentsFn not implemented."}; }; DropUserDatabasesFn dropUserDBsFn = [](OperationContext* txn) { return Status{ErrorCodes::IllegalOperation, "DropUserDatabasesFn not implemented."}; @@ -168,9 +215,25 @@ public: CreateOplogFn createOplogFn = [](OperationContext* txn, const NamespaceString& nss) { return Status{ErrorCodes::IllegalOperation, "CreateOplogFn not implemented."}; }; + CreateCollectionFn createCollFn = + [](OperationContext* txn, const NamespaceString& nss, const CollectionOptions& options) { + return Status{ErrorCodes::IllegalOperation, "CreateCollectionFn not implemented."}; + }; DropCollectionFn dropCollFn = [](OperationContext* txn, const NamespaceString& nss) { return Status{ErrorCodes::IllegalOperation, "DropCollectionFn not implemented."}; }; + FindOneFn findOneFn = [](OperationContext* txn, + const NamespaceString& nss, + const BSONObj& indexKeyPattern, + ScanDirection scanDirection) { + return Status{ErrorCodes::IllegalOperation, "FindOneFn not implemented."}; + }; + DeleteOneFn deleteOneFn = [](OperationContext* txn, + const NamespaceString& nss, + const BSONObj& indexKeyPattern, + ScanDirection scanDirection) { + return Status{ErrorCodes::IllegalOperation, "DeleteOneFn not implemented."}; + }; private: mutable stdx::mutex _initialSyncFlagMutex; -- cgit v1.2.1