diff options
Diffstat (limited to 'src/mongo/db/repl/base_cloner_test_fixture.h')
-rw-r--r-- | src/mongo/db/repl/base_cloner_test_fixture.h | 201 |
1 files changed, 97 insertions, 104 deletions
diff --git a/src/mongo/db/repl/base_cloner_test_fixture.h b/src/mongo/db/repl/base_cloner_test_fixture.h index a7e5f68e448..cab5c517916 100644 --- a/src/mongo/db/repl/base_cloner_test_fixture.h +++ b/src/mongo/db/repl/base_cloner_test_fixture.h @@ -44,133 +44,126 @@ namespace mongo { - struct CollectionOptions; - class OperationContext; +struct CollectionOptions; +class OperationContext; namespace repl { - class BaseCloner; - class ClonerStorageInterfaceMock; - - class BaseClonerTest : public ReplicationExecutorTest { - public: - typedef executor::NetworkInterfaceMock::NetworkOperationIterator NetworkOperationIterator; - - /** - * Creates a cursor response with given array of documents. - */ - static BSONObj createCursorResponse(CursorId cursorId, - const std::string& ns, - const BSONArray& docs, - const char* batchFieldName); - - static BSONObj createCursorResponse(CursorId cursorId, - const BSONArray& docs, - const char* batchFieldName); - - static BSONObj createCursorResponse(CursorId cursorId, - const BSONArray& docs); - - /** - * Creates a listCollections response with given array of index specs. - */ - static BSONObj createListCollectionsResponse(CursorId cursorId, - const BSONArray& colls, - const char* batchFieldName); - - static BSONObj createListCollectionsResponse(CursorId cursorId, const BSONArray& colls); - - /** - * Creates a listIndexes response with given array of index specs. - */ - static BSONObj createListIndexesResponse(CursorId cursorId, - const BSONArray& specs, - const char* batchFieldName); +class BaseCloner; +class ClonerStorageInterfaceMock; + +class BaseClonerTest : public ReplicationExecutorTest { +public: + typedef executor::NetworkInterfaceMock::NetworkOperationIterator NetworkOperationIterator; + + /** + * Creates a cursor response with given array of documents. + */ + static BSONObj createCursorResponse(CursorId cursorId, + const std::string& ns, + const BSONArray& docs, + const char* batchFieldName); - static BSONObj createListIndexesResponse(CursorId cursorId, const BSONArray& specs); + static BSONObj createCursorResponse(CursorId cursorId, + const BSONArray& docs, + const char* batchFieldName); + + static BSONObj createCursorResponse(CursorId cursorId, const BSONArray& docs); + + /** + * Creates a listCollections response with given array of index specs. + */ + static BSONObj createListCollectionsResponse(CursorId cursorId, + const BSONArray& colls, + const char* batchFieldName); - static const HostAndPort target; - static const NamespaceString nss; - static const BSONObj idIndexSpec; + static BSONObj createListCollectionsResponse(CursorId cursorId, const BSONArray& colls); - BaseClonerTest(); + /** + * Creates a listIndexes response with given array of index specs. + */ + static BSONObj createListIndexesResponse(CursorId cursorId, + const BSONArray& specs, + const char* batchFieldName); - virtual void clear(); + static BSONObj createListIndexesResponse(CursorId cursorId, const BSONArray& specs); - void setStatus(const Status& status); - const Status& getStatus() const; + static const HostAndPort target; + static const NamespaceString nss; + static const BSONObj idIndexSpec; - void scheduleNetworkResponse(NetworkOperationIterator noi, - const BSONObj& obj); - void scheduleNetworkResponse(NetworkOperationIterator noi, - ErrorCodes::Error code, const std::string& reason); - void scheduleNetworkResponse(const BSONObj& obj); - void scheduleNetworkResponse(ErrorCodes::Error code, const std::string& reason); - void processNetworkResponse(const BSONObj& obj); - void processNetworkResponse(ErrorCodes::Error code, const std::string& reason); - void finishProcessingNetworkResponse(); + BaseClonerTest(); - /** - * Tests life cycle functionality. - */ - virtual BaseCloner* getCloner() const = 0; - void testLifeCycle(); + virtual void clear(); - protected: + void setStatus(const Status& status); + const Status& getStatus() const; - void setUp() override; - void tearDown() override; + void scheduleNetworkResponse(NetworkOperationIterator noi, const BSONObj& obj); + void scheduleNetworkResponse(NetworkOperationIterator noi, + ErrorCodes::Error code, + const std::string& reason); + void scheduleNetworkResponse(const BSONObj& obj); + void scheduleNetworkResponse(ErrorCodes::Error code, const std::string& reason); + void processNetworkResponse(const BSONObj& obj); + void processNetworkResponse(ErrorCodes::Error code, const std::string& reason); + void finishProcessingNetworkResponse(); - std::unique_ptr<ClonerStorageInterfaceMock> storageInterface; + /** + * Tests life cycle functionality. + */ + virtual BaseCloner* getCloner() const = 0; + void testLifeCycle(); - private: +protected: + void setUp() override; + void tearDown() override; - // Protects member data of this base cloner fixture. - mutable stdx::mutex _mutex; + std::unique_ptr<ClonerStorageInterfaceMock> storageInterface; - stdx::condition_variable _setStatusCondition; +private: + // Protects member data of this base cloner fixture. + mutable stdx::mutex _mutex; - Status _status; + stdx::condition_variable _setStatusCondition; - }; + Status _status; +}; - class ClonerStorageInterfaceMock : public CollectionCloner::StorageInterface { - public: - using InsertCollectionFn = stdx::function<Status (OperationContext*, - const NamespaceString&, - const std::vector<BSONObj>&)>; - using BeginCollectionFn = stdx::function<Status (OperationContext*, - const NamespaceString&, - const CollectionOptions&, - const std::vector<BSONObj>&)>; - using InsertMissingDocFn = stdx::function<Status (OperationContext*, - const NamespaceString&, - const BSONObj&)>; - using DropUserDatabases = stdx::function<Status (OperationContext*)>; +class ClonerStorageInterfaceMock : public CollectionCloner::StorageInterface { +public: + using InsertCollectionFn = stdx::function<Status( + OperationContext*, const NamespaceString&, const std::vector<BSONObj>&)>; + using BeginCollectionFn = stdx::function<Status(OperationContext*, + const NamespaceString&, + const CollectionOptions&, + const std::vector<BSONObj>&)>; + using InsertMissingDocFn = + stdx::function<Status(OperationContext*, const NamespaceString&, const BSONObj&)>; + using DropUserDatabases = stdx::function<Status(OperationContext*)>; - Status beginCollection(OperationContext* txn, - const NamespaceString& nss, - const CollectionOptions& options, - const std::vector<BSONObj>& specs) override; + Status beginCollection(OperationContext* txn, + const NamespaceString& nss, + const CollectionOptions& options, + const std::vector<BSONObj>& specs) override; - Status insertDocuments(OperationContext* txn, - const NamespaceString& nss, - const std::vector<BSONObj>& docs) override; + Status insertDocuments(OperationContext* txn, + const NamespaceString& nss, + const std::vector<BSONObj>& docs) override; - Status commitCollection(OperationContext* txn, - const NamespaceString& nss) override; + Status commitCollection(OperationContext* txn, const NamespaceString& nss) override; - Status insertMissingDoc(OperationContext* txn, - const NamespaceString& nss, - const BSONObj& doc) override; + Status insertMissingDoc(OperationContext* txn, + const NamespaceString& nss, + const BSONObj& doc) override; - Status dropUserDatabases(OperationContext* txn); + Status dropUserDatabases(OperationContext* txn); - BeginCollectionFn beginCollectionFn; - InsertCollectionFn insertDocumentsFn; - InsertMissingDocFn insertMissingDocFn; - DropUserDatabases dropUserDatabasesFn; - }; + BeginCollectionFn beginCollectionFn; + InsertCollectionFn insertDocumentsFn; + InsertMissingDocFn insertMissingDocFn; + DropUserDatabases dropUserDatabasesFn; +}; -} // namespace repl -} // namespace mongo +} // namespace repl +} // namespace mongo |