diff options
author | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 00:22:50 -0400 |
---|---|---|
committer | Mark Benvenuto <mark.benvenuto@mongodb.com> | 2015-06-20 10:56:02 -0400 |
commit | 9c2ed42daa8fbbef4a919c21ec564e2db55e8d60 (patch) | |
tree | 3814f79c10d7b490948d8cb7b112ac1dd41ceff1 /src/mongo/rpc/reply_builder_test.cpp | |
parent | 01965cf52bce6976637ecb8f4a622aeb05ab256a (diff) | |
download | mongo-9c2ed42daa8fbbef4a919c21ec564e2db55e8d60.tar.gz |
SERVER-18579: Clang-Format - reformat code, no comment reflow
Diffstat (limited to 'src/mongo/rpc/reply_builder_test.cpp')
-rw-r--r-- | src/mongo/rpc/reply_builder_test.cpp | 354 |
1 files changed, 174 insertions, 180 deletions
diff --git a/src/mongo/rpc/reply_builder_test.cpp b/src/mongo/rpc/reply_builder_test.cpp index 906f51f4bc0..218e8b24caa 100644 --- a/src/mongo/rpc/reply_builder_test.cpp +++ b/src/mongo/rpc/reply_builder_test.cpp @@ -38,232 +38,226 @@ namespace { - using namespace mongo; +using namespace mongo; - static void _testMaxCommandReply(rpc::ReplyBuilderInterface& replyBuilder); - - TEST(CommandReplyBuilder, RoundTrip) { +static void _testMaxCommandReply(rpc::ReplyBuilderInterface& replyBuilder); - BSONObjBuilder metadataBob{}; - metadataBob.append("foo", "bar"); - auto metadata = metadataBob.done(); +TEST(CommandReplyBuilder, RoundTrip) { + BSONObjBuilder metadataBob{}; + metadataBob.append("foo", "bar"); + auto metadata = metadataBob.done(); - BSONObjBuilder commandReplyBob{}; - commandReplyBob.append("bar", "baz").append("ok", 1.0); - auto commandReply = commandReplyBob.done(); + BSONObjBuilder commandReplyBob{}; + commandReplyBob.append("bar", "baz").append("ok", 1.0); + auto commandReply = commandReplyBob.done(); - BSONObjBuilder outputDoc1Bob{}; - outputDoc1Bob.append("z", "t"); - auto outputDoc1 = outputDoc1Bob.done(); + BSONObjBuilder outputDoc1Bob{}; + outputDoc1Bob.append("z", "t"); + auto outputDoc1 = outputDoc1Bob.done(); - BSONObjBuilder outputDoc2Bob{}; - outputDoc2Bob.append("h", "j"); - auto outputDoc2 = outputDoc2Bob.done(); + BSONObjBuilder outputDoc2Bob{}; + outputDoc2Bob.append("h", "j"); + auto outputDoc2 = outputDoc2Bob.done(); - BSONObjBuilder outputDoc3Bob{}; - outputDoc3Bob.append("g", "p"); - auto outputDoc3 = outputDoc3Bob.done(); + BSONObjBuilder outputDoc3Bob{}; + outputDoc3Bob.append("g", "p"); + auto outputDoc3 = outputDoc3Bob.done(); - BufBuilder outputDocs; - outputDoc1.appendSelfToBufBuilder(outputDocs); - outputDoc2.appendSelfToBufBuilder(outputDocs); - outputDoc3.appendSelfToBufBuilder(outputDocs); + BufBuilder outputDocs; + outputDoc1.appendSelfToBufBuilder(outputDocs); + outputDoc2.appendSelfToBufBuilder(outputDocs); + outputDoc3.appendSelfToBufBuilder(outputDocs); - rpc::DocumentRange outputDocRange{outputDocs.buf(), outputDocs.buf() + outputDocs.len()}; + rpc::DocumentRange outputDocRange{outputDocs.buf(), outputDocs.buf() + outputDocs.len()}; - rpc::CommandReplyBuilder r; + rpc::CommandReplyBuilder r; - auto msg = r.setMetadata(metadata) - .setCommandReply(commandReply) - .addOutputDocs(outputDocRange) - .done(); + auto msg = + r.setMetadata(metadata).setCommandReply(commandReply).addOutputDocs(outputDocRange).done(); - rpc::CommandReply parsed(msg.get()); + rpc::CommandReply parsed(msg.get()); - ASSERT_EQUALS(parsed.getMetadata(), metadata); - ASSERT_EQUALS(parsed.getCommandReply(), commandReply); - // need ostream overloads for ASSERT_EQUALS - ASSERT_TRUE(parsed.getOutputDocs() == outputDocRange); - } + ASSERT_EQUALS(parsed.getMetadata(), metadata); + ASSERT_EQUALS(parsed.getCommandReply(), commandReply); + // need ostream overloads for ASSERT_EQUALS + ASSERT_TRUE(parsed.getOutputDocs() == outputDocRange); +} - TEST(CommandReplyBuilder, MaxCommandReply) { - rpc::CommandReplyBuilder replyBuilder; - _testMaxCommandReply(replyBuilder); - } +TEST(CommandReplyBuilder, MaxCommandReply) { + rpc::CommandReplyBuilder replyBuilder; + _testMaxCommandReply(replyBuilder); +} - TEST(LegacyReplyBuilder, MaxCommandReply) { - rpc::LegacyReplyBuilder replyBuilder; - _testMaxCommandReply(replyBuilder); - } +TEST(LegacyReplyBuilder, MaxCommandReply) { + rpc::LegacyReplyBuilder replyBuilder; + _testMaxCommandReply(replyBuilder); +} - // verify current functionality - later will need to change - TEST(LegacyReplyBuilderSpaceTest, DocSize) { - rpc::LegacyReplyBuilder replyBuilder; - replyBuilder.setMetadata(BSONObj()).setCommandReply(BSONObj()); +// verify current functionality - later will need to change +TEST(LegacyReplyBuilderSpaceTest, DocSize) { + rpc::LegacyReplyBuilder replyBuilder; + replyBuilder.setMetadata(BSONObj()).setCommandReply(BSONObj()); - std::size_t spaceBefore = replyBuilder.availableSpaceForOutputDocs(); - ASSERT_EQUALS(spaceBefore, 0u); + std::size_t spaceBefore = replyBuilder.availableSpaceForOutputDocs(); + ASSERT_EQUALS(spaceBefore, 0u); - BSONObjBuilder docBuilder{}; - docBuilder.append("foo", "bar"); - auto doc = docBuilder.done(); + BSONObjBuilder docBuilder{}; + docBuilder.append("foo", "bar"); + auto doc = docBuilder.done(); - replyBuilder.addOutputDoc(doc); //no-op - std::size_t spaceAfter = replyBuilder.availableSpaceForOutputDocs(); - ASSERT_EQUALS(spaceAfter, 0u); + replyBuilder.addOutputDoc(doc); // no-op + std::size_t spaceAfter = replyBuilder.availableSpaceForOutputDocs(); + ASSERT_EQUALS(spaceAfter, 0u); +} + +class CommandReplyBuilderSpaceTest : public mongo::unittest::Test { +protected: + // compute an empty doc size to use in follow up tests for payload size computation + virtual void setUp() override { + BSONObjBuilder docBuilder1{}; + docBuilder1.append("x", ""); + auto emptyDoc = docBuilder1.done(); + emptyDocSize = emptyDoc.objsize(); } - class CommandReplyBuilderSpaceTest : public mongo::unittest::Test { - protected: + virtual void tearDown() override {} - // compute an empty doc size to use in follow up tests for payload size computation - virtual void setUp() override { - BSONObjBuilder docBuilder1{}; - docBuilder1.append("x", ""); - auto emptyDoc = docBuilder1.done(); - emptyDocSize = emptyDoc.objsize(); - } + std::size_t emptyDocSize = 0u; +}; - virtual void tearDown() override { - } +TEST_F(CommandReplyBuilderSpaceTest, DocSizeEq) { + rpc::CommandReplyBuilder replyBuilder; + replyBuilder.setMetadata(BSONObj()).setCommandReply(BSONObj()); - std::size_t emptyDocSize = 0u; - }; + std::size_t spaceBefore = replyBuilder.availableSpaceForOutputDocs(); - TEST_F(CommandReplyBuilderSpaceTest, DocSizeEq) { - rpc::CommandReplyBuilder replyBuilder; - replyBuilder.setMetadata(BSONObj()).setCommandReply(BSONObj()); + BSONObjBuilder docBuilder{}; + docBuilder.append("foo", "bar"); + auto doc = docBuilder.done(); + std::size_t docSize = doc.objsize(); - std::size_t spaceBefore = replyBuilder.availableSpaceForOutputDocs(); + replyBuilder.addOutputDoc(doc); + std::size_t spaceAfter = replyBuilder.availableSpaceForOutputDocs(); + ASSERT_EQUALS(spaceBefore - docSize, spaceAfter); +} +// multiple calls to addOutputDoc, no metadata +TEST_F(CommandReplyBuilderSpaceTest, MaxDocSize1) { + rpc::CommandReplyBuilder replyBuilder; + + replyBuilder.setMetadata(BSONObj()).setCommandReply(BSONObj()); + + std::size_t availSpace = replyBuilder.availableSpaceForOutputDocs(); + + while (availSpace > 0u) { + std::size_t payloadSz = + std::min(availSpace, static_cast<std::size_t>(mongo::BSONObjMaxUserSize)) - + emptyDocSize; BSONObjBuilder docBuilder{}; - docBuilder.append("foo", "bar"); + std::string payload = std::string(payloadSz, 'y'); + docBuilder.append("x", payload); auto doc = docBuilder.done(); - std::size_t docSize = doc.objsize(); - replyBuilder.addOutputDoc(doc); - std::size_t spaceAfter = replyBuilder.availableSpaceForOutputDocs(); - ASSERT_EQUALS(spaceBefore - docSize, spaceAfter); + availSpace = replyBuilder.availableSpaceForOutputDocs(); } + auto msg = replyBuilder.done(); + auto sizeUInt = static_cast<std::size_t>(msg->size()); - // multiple calls to addOutputDoc, no metadata - TEST_F(CommandReplyBuilderSpaceTest, MaxDocSize1) { - rpc::CommandReplyBuilder replyBuilder; - - replyBuilder.setMetadata(BSONObj()).setCommandReply(BSONObj()); - - std::size_t availSpace = replyBuilder.availableSpaceForOutputDocs(); - - while (availSpace > 0u) { - std::size_t payloadSz = - std::min(availSpace, static_cast<std::size_t>(mongo::BSONObjMaxUserSize)) - - emptyDocSize; - BSONObjBuilder docBuilder{}; - std::string payload = std::string(payloadSz, 'y' ); - docBuilder.append("x", payload); - auto doc = docBuilder.done(); - replyBuilder.addOutputDoc(doc); - availSpace = replyBuilder.availableSpaceForOutputDocs(); - } - auto msg = replyBuilder.done(); - auto sizeUInt = static_cast<std::size_t>(msg->size()); - - ASSERT_EQUALS(sizeUInt, mongo::MaxMessageSizeBytes); - } + ASSERT_EQUALS(sizeUInt, mongo::MaxMessageSizeBytes); +} - // multiple calls to addOutputDoc, some metadata - TEST_F(CommandReplyBuilderSpaceTest, MaxDocSize2) { - rpc::CommandReplyBuilder replyBuilder; - - BSONObjBuilder metadataBuilder{}; - metadataBuilder.append("foo", "bar"); - auto metadata = metadataBuilder.done(); - - BSONObjBuilder commandReplyBuilder{}; - commandReplyBuilder.append("oof", "rab"); - auto commandReply = commandReplyBuilder.done(); - - replyBuilder.setMetadata(metadata).setCommandReply(commandReply); - - std::size_t availSpace = replyBuilder.availableSpaceForOutputDocs(); - - while (availSpace > 0u) { - std::size_t payloadSz = - std::min(availSpace, static_cast<std::size_t>(mongo::BSONObjMaxUserSize)) - - emptyDocSize; - BSONObjBuilder docBuilder{}; - std::string payload = std::string(payloadSz, 'y' ); - docBuilder.append("x", payload); - auto doc = docBuilder.done(); - replyBuilder.addOutputDoc(doc); - availSpace = replyBuilder.availableSpaceForOutputDocs(); - } - auto msg = replyBuilder.done(); - auto sizeUInt = static_cast<std::size_t>(msg->size()); - - ASSERT_EQUALS(sizeUInt, mongo::MaxMessageSizeBytes); - } +// multiple calls to addOutputDoc, some metadata +TEST_F(CommandReplyBuilderSpaceTest, MaxDocSize2) { + rpc::CommandReplyBuilder replyBuilder; + BSONObjBuilder metadataBuilder{}; + metadataBuilder.append("foo", "bar"); + auto metadata = metadataBuilder.done(); - // single call to addOutputDocs - TEST_F(CommandReplyBuilderSpaceTest, MaxDocSize3) { - rpc::CommandReplyBuilder replyBuilder; + BSONObjBuilder commandReplyBuilder{}; + commandReplyBuilder.append("oof", "rab"); + auto commandReply = commandReplyBuilder.done(); - BSONObjBuilder metadataBuilder{}; - metadataBuilder.append("foo", "bar"); - auto metadata = metadataBuilder.done(); + replyBuilder.setMetadata(metadata).setCommandReply(commandReply); - BSONObjBuilder commandReplyBuilder{}; - commandReplyBuilder.append("oof", "rab"); - auto commandReply = commandReplyBuilder.done(); + std::size_t availSpace = replyBuilder.availableSpaceForOutputDocs(); - replyBuilder.setMetadata(metadata).setCommandReply(commandReply); + while (availSpace > 0u) { + std::size_t payloadSz = + std::min(availSpace, static_cast<std::size_t>(mongo::BSONObjMaxUserSize)) - + emptyDocSize; + BSONObjBuilder docBuilder{}; + std::string payload = std::string(payloadSz, 'y'); + docBuilder.append("x", payload); + auto doc = docBuilder.done(); + replyBuilder.addOutputDoc(doc); + availSpace = replyBuilder.availableSpaceForOutputDocs(); + } + auto msg = replyBuilder.done(); + auto sizeUInt = static_cast<std::size_t>(msg->size()); - std::size_t availSpace = replyBuilder.availableSpaceForOutputDocs(); + ASSERT_EQUALS(sizeUInt, mongo::MaxMessageSizeBytes); +} - BufBuilder docs; - while (availSpace > 0u) { - std::size_t payloadSz = - std::min(availSpace, static_cast<std::size_t>(mongo::BSONObjMaxUserSize)) - - emptyDocSize; - BSONObjBuilder docBuilder{}; - std::string payload = std::string(payloadSz, 'y' ); - docBuilder.append("x", payload); - auto doc = docBuilder.done(); - availSpace -= doc.objsize(); - doc.appendSelfToBufBuilder(docs); - } - rpc::DocumentRange docRange{docs.buf(), docs.buf() + docs.len()}; - replyBuilder.addOutputDocs(docRange); - auto msg = replyBuilder.done(); - auto sizeUInt = static_cast<std::size_t>(msg->size()); +// single call to addOutputDocs +TEST_F(CommandReplyBuilderSpaceTest, MaxDocSize3) { + rpc::CommandReplyBuilder replyBuilder; - ASSERT_EQUALS(sizeUInt, mongo::MaxMessageSizeBytes); - } + BSONObjBuilder metadataBuilder{}; + metadataBuilder.append("foo", "bar"); + auto metadata = metadataBuilder.done(); - // call to addCommandReply - void _testMaxCommandReply(rpc::ReplyBuilderInterface& replyBuilder) { - BSONObjBuilder docBuilder1{}; - docBuilder1.append("x", ""); - auto emptyDoc = docBuilder1.done(); - std::size_t emptyDocSize = emptyDoc.objsize(); + BSONObjBuilder commandReplyBuilder{}; + commandReplyBuilder.append("oof", "rab"); + auto commandReply = commandReplyBuilder.done(); - BSONObjBuilder metadataBuilder{}; - metadataBuilder.append("foo", "bar"); - auto metadata = metadataBuilder.done(); - replyBuilder.setMetadata(metadata); + replyBuilder.setMetadata(metadata).setCommandReply(commandReply); - auto payloadSz = static_cast<std::size_t>(mongo::BSONObjMaxUserSize) - + std::size_t availSpace = replyBuilder.availableSpaceForOutputDocs(); + + BufBuilder docs; + while (availSpace > 0u) { + std::size_t payloadSz = + std::min(availSpace, static_cast<std::size_t>(mongo::BSONObjMaxUserSize)) - emptyDocSize; + BSONObjBuilder docBuilder{}; + std::string payload = std::string(payloadSz, 'y'); + docBuilder.append("x", payload); + auto doc = docBuilder.done(); + availSpace -= doc.objsize(); + doc.appendSelfToBufBuilder(docs); + } + rpc::DocumentRange docRange{docs.buf(), docs.buf() + docs.len()}; + replyBuilder.addOutputDocs(docRange); - BSONObjBuilder commandReplyBuilder{}; - std::string payload = std::string(payloadSz, 'y' ); - commandReplyBuilder.append("x", payload); - auto commandReply = commandReplyBuilder.done(); - ASSERT_EQUALS(commandReply.objsize(), mongo::BSONObjMaxUserSize); + auto msg = replyBuilder.done(); + auto sizeUInt = static_cast<std::size_t>(msg->size()); - replyBuilder.setCommandReply(commandReply); - } + ASSERT_EQUALS(sizeUInt, mongo::MaxMessageSizeBytes); +} + +// call to addCommandReply +void _testMaxCommandReply(rpc::ReplyBuilderInterface& replyBuilder) { + BSONObjBuilder docBuilder1{}; + docBuilder1.append("x", ""); + auto emptyDoc = docBuilder1.done(); + std::size_t emptyDocSize = emptyDoc.objsize(); + + BSONObjBuilder metadataBuilder{}; + metadataBuilder.append("foo", "bar"); + auto metadata = metadataBuilder.done(); + replyBuilder.setMetadata(metadata); + + auto payloadSz = static_cast<std::size_t>(mongo::BSONObjMaxUserSize) - emptyDocSize; + + BSONObjBuilder commandReplyBuilder{}; + std::string payload = std::string(payloadSz, 'y'); + commandReplyBuilder.append("x", payload); + auto commandReply = commandReplyBuilder.done(); + ASSERT_EQUALS(commandReply.objsize(), mongo::BSONObjMaxUserSize); + + replyBuilder.setCommandReply(commandReply); +} } // namespace |