diff options
Diffstat (limited to 'src/mongo/db/storage/mmap_v1/btree/btree_test_help.h')
-rw-r--r-- | src/mongo/db/storage/mmap_v1/btree/btree_test_help.h | 196 |
1 files changed, 96 insertions, 100 deletions
diff --git a/src/mongo/db/storage/mmap_v1/btree/btree_test_help.h b/src/mongo/db/storage/mmap_v1/btree/btree_test_help.h index b282e72d827..5aeec516528 100644 --- a/src/mongo/db/storage/mmap_v1/btree/btree_test_help.h +++ b/src/mongo/db/storage/mmap_v1/btree/btree_test_help.h @@ -37,118 +37,114 @@ namespace mongo { +/** + * Generates a string of the specified length containing repeated concatenation of the + * hexadecimal representation of the input value. + */ +std::string bigNumString(long long n, int len); + +/** + * Generates key on a field 'a', with the specified number of repetitions of the character. + */ +BSONObj simpleKey(char c, int n = 1); + +/** + * Simple head manager, which performs no validity checking or persistence. + */ +class TestHeadManager : public HeadManager { +public: + virtual const RecordId getHead(OperationContext* txn) const { + return _head; + } + + virtual void setHead(OperationContext* txn, const RecordId newHead) { + _head = newHead; + } + +private: + RecordId _head; +}; + + +/** + * This structure encapsulates a Btree and all the infrastructure needed by it (head manager, + * record store and a valid disk location to use by the tests). + */ +template <class OnDiskFormat> +struct BtreeLogicTestHelper { + BtreeLogicTestHelper(const BSONObj& order); + + // Everything needed for a fully-functional Btree logic + TestHeadManager headManager; + HeapRecordStoreBtree recordStore; + SavedCursorRegistry cursorRegistry; + BtreeLogic<OnDiskFormat> btree; + DiskLoc dummyDiskLoc; +}; + + +/** + * Tool to construct custom tree shapes for tests. + */ +template <class OnDiskFormat> +class ArtificialTreeBuilder { +public: + typedef typename BtreeLogic<OnDiskFormat>::BucketType BucketType; + typedef typename BtreeLogic<OnDiskFormat>::KeyDataOwnedType KeyDataOwnedType; + typedef typename BtreeLogic<OnDiskFormat>::KeyHeaderType KeyHeaderType; + + typedef typename OnDiskFormat::FixedWidthKeyType FixedWidthKeyType; + /** - * Generates a string of the specified length containing repeated concatenation of the - * hexadecimal representation of the input value. + * The tree builder wraps around the passed-in helper and will invoke methods on it. It + * does not do any cleanup, so constructing multiple trees over the same helper will + * cause leaked records. */ - std::string bigNumString(long long n, int len); + ArtificialTreeBuilder(OperationContext* txn, BtreeLogicTestHelper<OnDiskFormat>* helper) + : _txn(txn), _helper(helper) {} /** - * Generates key on a field 'a', with the specified number of repetitions of the character. + * Causes the specified tree shape to be built on the associated helper and the tree's + * root installed as the head. Uses a custom JSON-based language with the following + * syntax: + * + * Btree := BTreeBucket + * BtreeBucket := { Child_1_Key: <BtreeBucket | null>, + * Child_2_Key: <BtreeBucket | null>, + * ..., + * _: <BtreeBucket | null> } + * + * The _ key name specifies the content of the nextChild pointer. The value null means + * use a fixed disk loc. */ - BSONObj simpleKey(char c, int n = 1); + void makeTree(const std::string& spec); /** - * Simple head manager, which performs no validity checking or persistence. + * Validates that the structure of the Btree in the helper matches the specification. */ - class TestHeadManager : public HeadManager { - public: - virtual const RecordId getHead( OperationContext* txn ) const { - return _head; - } - - virtual void setHead(OperationContext* txn, const RecordId newHead) { - _head = newHead; - } - - private: - RecordId _head; - }; + void checkStructure(const std::string& spec) const; + /** + * Adds the following key to the bucket and fixes up the child pointers. + */ + void push(const DiskLoc bucketLoc, const BSONObj& key, const DiskLoc child); /** - * This structure encapsulates a Btree and all the infrastructure needed by it (head manager, - * record store and a valid disk location to use by the tests). + * @return The number of keys inserted. */ - template <class OnDiskFormat> - struct BtreeLogicTestHelper { - BtreeLogicTestHelper(const BSONObj& order); + int fillBucketToExactSize(const DiskLoc bucketLoc, int targetSize, char startKey); - // Everything needed for a fully-functional Btree logic - TestHeadManager headManager; - HeapRecordStoreBtree recordStore; - SavedCursorRegistry cursorRegistry; - BtreeLogic<OnDiskFormat> btree; - DiskLoc dummyDiskLoc; - }; +private: + DiskLoc makeTree(const BSONObj& spec); + void checkStructure(const BSONObj& spec, const DiskLoc node) const; - /** - * Tool to construct custom tree shapes for tests. - */ - template <class OnDiskFormat> - class ArtificialTreeBuilder { - public: - - typedef typename BtreeLogic<OnDiskFormat>::BucketType BucketType; - typedef typename BtreeLogic<OnDiskFormat>::KeyDataOwnedType KeyDataOwnedType; - typedef typename BtreeLogic<OnDiskFormat>::KeyHeaderType KeyHeaderType; - - typedef typename OnDiskFormat::FixedWidthKeyType FixedWidthKeyType; - - /** - * The tree builder wraps around the passed-in helper and will invoke methods on it. It - * does not do any cleanup, so constructing multiple trees over the same helper will - * cause leaked records. - */ - ArtificialTreeBuilder(OperationContext* txn, - BtreeLogicTestHelper<OnDiskFormat>* helper) - : _txn(txn), _helper(helper) { - - } - - /** - * Causes the specified tree shape to be built on the associated helper and the tree's - * root installed as the head. Uses a custom JSON-based language with the following - * syntax: - * - * Btree := BTreeBucket - * BtreeBucket := { Child_1_Key: <BtreeBucket | null>, - * Child_2_Key: <BtreeBucket | null>, - * ..., - * _: <BtreeBucket | null> } - * - * The _ key name specifies the content of the nextChild pointer. The value null means - * use a fixed disk loc. - */ - void makeTree(const std::string& spec); - - /** - * Validates that the structure of the Btree in the helper matches the specification. - */ - void checkStructure(const std::string& spec) const; - - /** - * Adds the following key to the bucket and fixes up the child pointers. - */ - void push(const DiskLoc bucketLoc, const BSONObj& key, const DiskLoc child); - - /** - * @return The number of keys inserted. - */ - int fillBucketToExactSize(const DiskLoc bucketLoc, int targetSize, char startKey); - - private: - DiskLoc makeTree(const BSONObj& spec); - - void checkStructure(const BSONObj& spec, const DiskLoc node) const; - - bool isPresent(const BSONObj& key, int direction) const; - - static std::string expectedKey(const char* spec); - - OperationContext* _txn; - BtreeLogicTestHelper<OnDiskFormat>* _helper; - }; - -} // namespace mongo + bool isPresent(const BSONObj& key, int direction) const; + + static std::string expectedKey(const char* spec); + + OperationContext* _txn; + BtreeLogicTestHelper<OnDiskFormat>* _helper; +}; + +} // namespace mongo |