summaryrefslogtreecommitdiff
path: root/src/mongo/s/query/router_stage_skip_test.cpp
diff options
context:
space:
mode:
authorDavid Storch <david.storch@10gen.com>2015-07-30 20:19:53 -0400
committerDavid Storch <david.storch@10gen.com>2015-07-30 20:19:53 -0400
commit0549805e713327519702856deeb66b16cb727b99 (patch)
tree0c72ee4e7b46b914e7119c3843d0446a21cf11b3 /src/mongo/s/query/router_stage_skip_test.cpp
parent3feccd233307a8a4fc81e312d072046f8cf2f499 (diff)
downloadmongo-0549805e713327519702856deeb66b16cb727b99.tar.gz
SERVER-19355 add skip support to the new find/getMore path in mongos
Diffstat (limited to 'src/mongo/s/query/router_stage_skip_test.cpp')
-rw-r--r--src/mongo/s/query/router_stage_skip_test.cpp153
1 files changed, 153 insertions, 0 deletions
diff --git a/src/mongo/s/query/router_stage_skip_test.cpp b/src/mongo/s/query/router_stage_skip_test.cpp
new file mode 100644
index 00000000000..e0116136c2f
--- /dev/null
+++ b/src/mongo/s/query/router_stage_skip_test.cpp
@@ -0,0 +1,153 @@
+/**
+ * Copyright 2015 MongoDB Inc.
+ *
+ * This program is free software: you can redistribute it and/or modify
+ * it under the terms of the GNU Affero General Public License, version 3,
+ * as published by the Free Software Foundation.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU Affero General Public License for more details.
+ *
+ * You should have received a copy of the GNU Affero General Public License
+ * along with this program. If not, see <http://www.gnu.org/licenses/>.
+ *
+ * As a special exception, the copyright holders give permission to link the
+ * code of portions of this program with the OpenSSL library under certain
+ * conditions as described in each individual source file and distribute
+ * linked combinations including the program with the OpenSSL library. You
+ * must comply with the GNU Affero General Public License in all respects for
+ * all of the code used other than as permitted herein. If you modify file(s)
+ * with this exception, you may extend this exception to your version of the
+ * file(s), but you are not obligated to do so. If you do not wish to do so,
+ * delete this exception statement from your version. If you delete this
+ * exception statement from all source files in the program, then also delete
+ * it in the license file.
+ */
+
+#include "mongo/platform/basic.h"
+
+#include "mongo/s/query/router_stage_skip.h"
+
+#include "mongo/bson/bsonobj.h"
+#include "mongo/bson/bsonobjbuilder.h"
+#include "mongo/s/query/router_stage_mock.h"
+#include "mongo/stdx/memory.h"
+#include "mongo/unittest/unittest.h"
+
+namespace mongo {
+
+namespace {
+
+TEST(RouterStageSkipTest, SkipIsOne) {
+ auto mockStage = stdx::make_unique<RouterStageMock>();
+ mockStage->queueResult(BSON("a" << 1));
+ mockStage->queueResult(BSON("a" << 2));
+ mockStage->queueResult(BSON("a" << 3));
+
+ auto skipStage = stdx::make_unique<RouterStageSkip>(std::move(mockStage), 1);
+
+ auto firstResult = skipStage->next();
+ ASSERT_OK(firstResult.getStatus());
+ ASSERT(firstResult.getValue());
+ ASSERT_EQ(*firstResult.getValue(), BSON("a" << 2));
+
+ auto secondResult = skipStage->next();
+ ASSERT_OK(secondResult.getStatus());
+ ASSERT(secondResult.getValue());
+ ASSERT_EQ(*secondResult.getValue(), BSON("a" << 3));
+
+ // Once end-of-stream is reached, the skip stage should keep returning boost::none.
+ auto thirdResult = skipStage->next();
+ ASSERT_OK(thirdResult.getStatus());
+ ASSERT(!thirdResult.getValue());
+
+ auto fourthResult = skipStage->next();
+ ASSERT_OK(thirdResult.getStatus());
+ ASSERT(!thirdResult.getValue());
+}
+
+TEST(RouterStageSkipTest, SkipIsThree) {
+ auto mockStage = stdx::make_unique<RouterStageMock>();
+ mockStage->queueResult(BSON("a" << 1));
+ mockStage->queueResult(BSON("a" << 2));
+ mockStage->queueResult(BSON("a" << 3));
+ mockStage->queueResult(BSON("a" << 4));
+
+ auto skipStage = stdx::make_unique<RouterStageSkip>(std::move(mockStage), 3);
+
+ auto firstResult = skipStage->next();
+ ASSERT_OK(firstResult.getStatus());
+ ASSERT(firstResult.getValue());
+ ASSERT_EQ(*firstResult.getValue(), BSON("a" << 4));
+
+ auto secondResult = skipStage->next();
+ ASSERT_OK(secondResult.getStatus());
+ ASSERT(!secondResult.getValue());
+}
+
+TEST(RouterStageSkipTest, SkipEqualToResultSetSize) {
+ auto mockStage = stdx::make_unique<RouterStageMock>();
+ mockStage->queueResult(BSON("a" << 1));
+ mockStage->queueResult(BSON("a" << 2));
+ mockStage->queueResult(BSON("a" << 3));
+
+ auto skipStage = stdx::make_unique<RouterStageSkip>(std::move(mockStage), 3);
+
+ auto firstResult = skipStage->next();
+ ASSERT_OK(firstResult.getStatus());
+ ASSERT(!firstResult.getValue());
+}
+
+TEST(RouterStageSkipTest, SkipExceedsResultSetSize) {
+ auto mockStage = stdx::make_unique<RouterStageMock>();
+ mockStage->queueResult(BSON("a" << 1));
+ mockStage->queueResult(BSON("a" << 2));
+ mockStage->queueResult(BSON("a" << 3));
+
+ auto skipStage = stdx::make_unique<RouterStageSkip>(std::move(mockStage), 100);
+
+ auto firstResult = skipStage->next();
+ ASSERT_OK(firstResult.getStatus());
+ ASSERT(!firstResult.getValue());
+}
+
+TEST(RouterStageSkipTest, ErrorWhileSkippingResults) {
+ auto mockStage = stdx::make_unique<RouterStageMock>();
+ mockStage->queueResult(BSON("a" << 1));
+ mockStage->queueError(Status(ErrorCodes::BadValue, "bad thing happened"));
+ mockStage->queueResult(BSON("a" << 2));
+ mockStage->queueResult(BSON("a" << 3));
+
+ auto skipStage = stdx::make_unique<RouterStageSkip>(std::move(mockStage), 2);
+
+ auto firstResult = skipStage->next();
+ ASSERT_NOT_OK(firstResult.getStatus());
+ ASSERT_EQ(firstResult.getStatus(), ErrorCodes::BadValue);
+ ASSERT_EQ(firstResult.getStatus().reason(), "bad thing happened");
+}
+
+TEST(RouterStageSkipTest, ErrorAfterSkippingResults) {
+ auto mockStage = stdx::make_unique<RouterStageMock>();
+ mockStage->queueResult(BSON("a" << 1));
+ mockStage->queueResult(BSON("a" << 2));
+ mockStage->queueResult(BSON("a" << 3));
+ mockStage->queueError(Status(ErrorCodes::BadValue, "bad thing happened"));
+
+ auto skipStage = stdx::make_unique<RouterStageSkip>(std::move(mockStage), 2);
+
+ auto firstResult = skipStage->next();
+ ASSERT_OK(firstResult.getStatus());
+ ASSERT(firstResult.getValue());
+ ASSERT_EQ(*firstResult.getValue(), BSON("a" << 3));
+
+ auto secondResult = skipStage->next();
+ ASSERT_NOT_OK(secondResult.getStatus());
+ ASSERT_EQ(secondResult.getStatus(), ErrorCodes::BadValue);
+ ASSERT_EQ(secondResult.getStatus().reason(), "bad thing happened");
+}
+
+} // namespace
+
+} // namespace mongo