diff options
author | may <may.hoque@mongodb.com> | 2017-08-03 19:55:36 -0400 |
---|---|---|
committer | may <may.hoque@mongodb.com> | 2017-08-03 19:55:36 -0400 |
commit | 4f173c14a1f5c6608f0f114a52d776975690572d (patch) | |
tree | f4bee25d5deedb20191f41828a2ea1b97893c1f4 /src/mongo/db/repl/idempotency_document_structure_test.cpp | |
parent | 5ab64bbe07e98b7cc0b8a88b6adb3b348e174651 (diff) | |
download | mongo-4f173c14a1f5c6608f0f114a52d776975690572d.tar.gz |
SERVER-30301 Add explicit configuration object for DocumentStructureEnumerator
Diffstat (limited to 'src/mongo/db/repl/idempotency_document_structure_test.cpp')
-rw-r--r-- | src/mongo/db/repl/idempotency_document_structure_test.cpp | 148 |
1 files changed, 130 insertions, 18 deletions
diff --git a/src/mongo/db/repl/idempotency_document_structure_test.cpp b/src/mongo/db/repl/idempotency_document_structure_test.cpp index 3b0aa85f2bf..9a024d2032a 100644 --- a/src/mongo/db/repl/idempotency_document_structure_test.cpp +++ b/src/mongo/db/repl/idempotency_document_structure_test.cpp @@ -28,27 +28,32 @@ #include "mongo/platform/basic.h" -#include "mongo/bson/bsonmisc.h" -#include "mongo/bson/bsonobjbuilder.h" #include "mongo/bson/json.h" +#include "mongo/db/jsobj.h" #include "mongo/db/repl/idempotency_document_structure.h" #include "mongo/unittest/unittest.h" namespace mongo { namespace { -std::vector<BSONObj> getEnumeratedDocs(std::set<StringData> fields, size_t depth, size_t length) { - DocumentStructureEnumerator enumerator(fields, depth, length); +std::vector<BSONObj> getEnumeratedDocs(DocumentStructureEnumeratorConfig config) { + DocumentStructureEnumerator enumerator(config); return enumerator.getDocs(); } TEST(DocGenTest, NumDocsIsCorrect) { - std::vector<BSONObj> docs = getEnumeratedDocs({"a", "b"}, 2, 1); + std::vector<BSONObj> docs = getEnumeratedDocs({{"a", "b"}, 2, 1, false, false}); ASSERT_EQUALS(docs.size(), 104U); + docs = getEnumeratedDocs({{"a", "b"}, 2, 1, true, false}); + ASSERT_EQUALS(docs.size(), 36U); + docs = getEnumeratedDocs({{"a", "b"}, 2, 1, false, true}); + ASSERT_EQUALS(docs.size(), 15U); + docs = getEnumeratedDocs({{"a", "b"}, 2, 1, true, true}); + ASSERT_EQUALS(docs.size(), 4U); } TEST(DocGenTest, NoDuplicateDocs) { - std::vector<BSONObj> docs = getEnumeratedDocs({"a", "b"}, 2, 1); + std::vector<BSONObj> docs = getEnumeratedDocs({{"a", "b"}, 2, 1}); for (size_t i = 0; i < docs.size(); i++) { for (size_t j = i + 1; j < docs.size(); j++) { if (docs[i].binaryEqual(docs[j])) { @@ -66,7 +71,7 @@ TEST(DocGenTest, SomePreChosenDocExists) { std::set<StringData> fields{"a", "b"}; size_t depth = 2; size_t length = 1; - DocumentStructureEnumerator enumerator(fields, depth, length); + DocumentStructureEnumerator enumerator({fields, depth, length}); BSONObj start; bool docFound = false; for (auto doc : enumerator) { @@ -108,8 +113,6 @@ void testEnumeratedDocsAreCorrect(const std::vector<BSONObj>& enumeratedDocs, } TEST(DocGenTest, EntireCollectionExistsABDepth2Length0) { - // Although I could re-use some of these BSONObj (e.g. doc2 inside doc1), I think maintaining - // the order demonstrates something about our enumeration path that is valuable. std::vector<BSONObj> expectedDocs; expectedDocs.push_back(fromjson("{'a' : 0, 'b' : 0}")); expectedDocs.push_back(fromjson("{'a' : 0 }")); @@ -140,13 +143,60 @@ TEST(DocGenTest, EntireCollectionExistsABDepth2Length0) { expectedDocs.push_back(fromjson("{'a' : {'b' : {}}, 'b' : []}")); expectedDocs.push_back(fromjson("{'a' : {'b' : {}}, 'b' : {}}")); - auto enumeratedDocs = getEnumeratedDocs({"a", "b"}, 2, 0); - testEnumeratedDocsAreCorrect(expectedDocs, enumeratedDocs); + auto enumeratedDocs = getEnumeratedDocs({{"a", "b"}, 2, 0}); + testEnumeratedDocsAreCorrect(enumeratedDocs, expectedDocs); +} + +TEST(DocGenTest, EntireCollectionExistsABDepth2Length0ArrsDisabled) { + std::vector<BSONObj> expectedDocs; + expectedDocs.push_back(fromjson("{'a' : 0, 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : 0 }")); + expectedDocs.push_back(fromjson("{'a' : 0, 'b' : {}}")); + expectedDocs.push_back(fromjson("{'b' : 0}")); + expectedDocs.push_back(fromjson("{}")); + expectedDocs.push_back(fromjson("{'b' : {} }")); + expectedDocs.push_back(fromjson("{'a' : {'b' : 0}, 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : {'b' : 0}}")); + expectedDocs.push_back(fromjson("{'a' : {'b' : 0}, 'b' : {}}")); + expectedDocs.push_back(fromjson("{'a' : {}, 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : {}}")); + expectedDocs.push_back(fromjson("{'a' : {}, 'b' : {}}")); + expectedDocs.push_back(fromjson("{'a' : {'b' : {}}, 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : {'b' : {}}}")); + expectedDocs.push_back(fromjson("{'a' : {'b' : {}}, 'b' : {}}")); + + auto enumeratedDocs = getEnumeratedDocs({{"a", "b"}, 2, 0, false, true}); + testEnumeratedDocsAreCorrect(enumeratedDocs, expectedDocs); +} + +TEST(DocGenTest, EntireCollectionExistsABDepth2Length0DocsDisabled) { + std::vector<BSONObj> expectedDocs; + expectedDocs.push_back(fromjson("{'a' : 0, 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : 0 }")); + expectedDocs.push_back(fromjson("{'a' : 0, 'b' : []}")); + expectedDocs.push_back(fromjson("{'b' : 0}")); + expectedDocs.push_back(fromjson("{}")); + expectedDocs.push_back(fromjson("{'b' : [] }")); + expectedDocs.push_back(fromjson("{'a' : [], 'b' : 0 }")); + expectedDocs.push_back(fromjson("{'a' : []}")); + expectedDocs.push_back(fromjson("{'a' : [], 'b' : []}")); + + auto enumeratedDocs = getEnumeratedDocs({{"a", "b"}, 2, 0, true, false}); + testEnumeratedDocsAreCorrect(enumeratedDocs, expectedDocs); +} + +TEST(DocGenTest, EntireCollectionExistsABDepth2Length0BothDisabled) { + std::vector<BSONObj> expectedDocs; + expectedDocs.push_back(fromjson("{'a' : 0, 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : 0 }")); + expectedDocs.push_back(fromjson("{'b' : 0}")); + expectedDocs.push_back(fromjson("{}")); + + auto enumeratedDocs = getEnumeratedDocs({{"a", "b"}, 2, 0, true, true}); + testEnumeratedDocsAreCorrect(enumeratedDocs, expectedDocs); } TEST(DocGenTest, EntireCollectionExistsABDepth1Length2) { - // Although we could re-use some of these BSONObj (e.g. doc2 inside doc1), we think maintaining - // the order demonstrates something about our enumeration order that is valuable. std::vector<BSONObj> expectedDocs; expectedDocs.push_back(fromjson("{'a' : 0, 'b' : 0}")); expectedDocs.push_back(fromjson("{'a' : 0}")); @@ -191,24 +241,86 @@ TEST(DocGenTest, EntireCollectionExistsABDepth1Length2) { expectedDocs.push_back(fromjson("{'a' : {}, 'b' : [0, 0]}")); expectedDocs.push_back(fromjson("{'a' : {}, 'b' : {}}")); - auto enumeratedDocs = getEnumeratedDocs({"a", "b"}, 1, 2); - testEnumeratedDocsAreCorrect(expectedDocs, enumeratedDocs); + auto enumeratedDocs = getEnumeratedDocs({{"a", "b"}, 1, 2}); + testEnumeratedDocsAreCorrect(enumeratedDocs, expectedDocs); +} + +TEST(DocGenTest, EntireCollectionExistsABDepth1Length2ArrsDisabled) { + std::vector<BSONObj> expectedDocs; + expectedDocs.push_back(fromjson("{'a' : 0, 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : 0}")); + expectedDocs.push_back(fromjson("{'a' : 0, 'b' : {}}")); + expectedDocs.push_back(fromjson("{'b' : 0}")); + expectedDocs.push_back(fromjson("{}")); + expectedDocs.push_back(fromjson("{'b' : {}}")); + expectedDocs.push_back(fromjson("{'a' : {'b' : 0}, 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : {'b' : 0}}")); + expectedDocs.push_back(fromjson("{'a' : {'b' : 0}, 'b' : {}}")); + expectedDocs.push_back(fromjson("{'a' : {}, 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : {}}")); + expectedDocs.push_back(fromjson("{'a' : {}, 'b' : {}}")); + + auto enumeratedDocs = getEnumeratedDocs({{"a", "b"}, 1, 2, false, true}); + testEnumeratedDocsAreCorrect(enumeratedDocs, expectedDocs); +} + +TEST(DocGenTest, EntireCollectionExistsABDepth1Length2DocsDisabled) { + std::vector<BSONObj> expectedDocs; + expectedDocs.push_back(fromjson("{'a' : 0, 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : 0}")); + expectedDocs.push_back(fromjson("{'a' : 0, 'b' : []}")); + expectedDocs.push_back(fromjson("{'a' : 0, 'b' : [0]}")); + expectedDocs.push_back(fromjson("{'a' : 0, 'b' : [0, 0]}")); + expectedDocs.push_back(fromjson("{'b' : 0}")); + expectedDocs.push_back(fromjson("{}")); + expectedDocs.push_back(fromjson("{'b' : []}")); + expectedDocs.push_back(fromjson("{'b' : [0]}")); + expectedDocs.push_back(fromjson("{'b' : [0, 0]}")); + expectedDocs.push_back(fromjson("{'a' : [], 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : []}")); + expectedDocs.push_back(fromjson("{'a' : [], 'b' : []}")); + expectedDocs.push_back(fromjson("{'a' : [], 'b' : [0]}")); + expectedDocs.push_back(fromjson("{'a' : [], 'b' : [0, 0]}")); + expectedDocs.push_back(fromjson("{'a' : [0], 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : [0]}")); + expectedDocs.push_back(fromjson("{'a' : [0], 'b' : []}")); + expectedDocs.push_back(fromjson("{'a' : [0], 'b' : [0]}")); + expectedDocs.push_back(fromjson("{'a' : [0], 'b' : [0, 0]}")); + expectedDocs.push_back(fromjson("{'a' : [0, 0], 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : [0, 0]}")); + expectedDocs.push_back(fromjson("{'a' : [0, 0], 'b' : []}")); + expectedDocs.push_back(fromjson("{'a' : [0, 0], 'b' : [0]}")); + expectedDocs.push_back(fromjson("{'a' : [0, 0], 'b' : [0, 0]}")); + + auto enumeratedDocs = getEnumeratedDocs({{"a", "b"}, 1, 2, true, false}); + testEnumeratedDocsAreCorrect(enumeratedDocs, expectedDocs); +} + +TEST(DocGenTest, EntireCollectionExistsABDepth1Length2BothDisabled) { + std::vector<BSONObj> expectedDocs; + expectedDocs.push_back(fromjson("{'a' : 0, 'b' : 0}")); + expectedDocs.push_back(fromjson("{'a' : 0}")); + expectedDocs.push_back(fromjson("{'b' : 0}")); + expectedDocs.push_back(fromjson("{}")); + + DocumentStructureEnumerator enumerator({{"a", "b"}, 1, 2, true, true}); + testEnumeratedDocsAreCorrect(enumerator.getDocs(), expectedDocs); } TEST(EnumerateArrsTest, NumArrsIsCorrect) { std::set<StringData> fields{"a"}; size_t depth = 2; size_t length = 2; - DocumentStructureEnumerator enumerator(fields, depth, length); + DocumentStructureEnumerator enumerator({fields, depth, length}); std::vector<BSONArray> arrs = enumerator.enumerateArrs(); - ASSERT_EQUALS(arrs.size(), 2365U); + ASSERT_EQUALS(arrs.size(), 2414U); } TEST(EnumerateArrsTest, NoDuplicateArrs) { std::set<StringData> fields{"a", "b"}; size_t depth = 2; size_t length = 2; - DocumentStructureEnumerator enumerator(fields, depth, length); + DocumentStructureEnumerator enumerator({fields, depth, length}); BSONObj start; std::vector<BSONArray> arrs = enumerator.enumerateArrs(); for (size_t i = 0; i < arrs.size(); i++) { |