summaryrefslogtreecommitdiff
path: root/src/mongo/dbtests/querytests.cpp
diff options
context:
space:
mode:
authorMathias Stearn <mathias@10gen.com>2017-07-13 09:27:56 -0400
committerMathias Stearn <mathias@10gen.com>2017-07-26 15:13:34 -0400
commit84ef4754b61003c63a480ac009fe2302970b00c9 (patch)
treea04948da01af49265a4ab366d79dc146b1e398a4 /src/mongo/dbtests/querytests.cpp
parent8b36e1d65f4b1730e7fc6086a0e1f429e48ba695 (diff)
downloadmongo-84ef4754b61003c63a480ac009fe2302970b00c9.tar.gz
SERVER-28509 DBClientCursor now uses read commands
Diffstat (limited to 'src/mongo/dbtests/querytests.cpp')
-rw-r--r--src/mongo/dbtests/querytests.cpp56
1 files changed, 24 insertions, 32 deletions
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp
index 772cd354c0b..841086a01f2 100644
--- a/src/mongo/dbtests/querytests.cpp
+++ b/src/mongo/dbtests/querytests.cpp
@@ -295,8 +295,7 @@ public:
};
/**
- * An exception triggered during a get more request destroys the ClientCursor used by the get
- * more, preventing further iteration of the cursor in subsequent get mores.
+ * Setting killAllOperations causes further getmores to fail.
*/
class GetMoreKillOp : public ClientBase {
public:
@@ -313,7 +312,6 @@ public:
// Create a cursor on the collection, with a batch size of 200.
unique_ptr<DBClientCursor> cursor = _client.query(ns, "", 0, 0, 0, 0, 200);
- CursorId cursorId = cursor->getCursorId();
// Count 500 results, spanning a few batches of documents.
for (int i = 0; i < 500; ++i) {
@@ -324,23 +322,16 @@ public:
// Set the killop kill all flag, forcing the next get more to fail with a kill op
// exception.
getGlobalServiceContext()->setKillAllOperations();
- while (cursor->more()) {
- cursor->next();
- }
+ ASSERT_THROWS_CODE(([&] {
+ while (cursor->more()) {
+ cursor->next();
+ }
+ }()),
+ UserException,
+ ErrorCodes::InterruptedAtShutdown);
// Revert the killop kill all flag.
getGlobalServiceContext()->unsetKillAllOperations();
-
- // Check that the cursor has been removed.
- {
- AutoGetCollectionForReadCommand ctx(&_opCtx, NamespaceString(ns));
- ASSERT(0 == ctx.getCollection()->getCursorManager()->numCursors());
- }
-
- ASSERT_FALSE(CursorManager::eraseCursorGlobal(&_opCtx, cursorId));
-
- // Check that a subsequent get more fails with the cursor removed.
- ASSERT_THROWS(_client.getMore(ns, cursorId), UserException);
}
};
@@ -376,8 +367,10 @@ public:
// Send a get more with a namespace that is incorrect ('spoofed') for this cursor id.
// This is the invalaid get more request described in the comment preceding this class.
- _client.getMore("unittests.querytests.GetMoreInvalidRequest_WRONG_NAMESPACE_FOR_CURSOR",
- cursor->getCursorId());
+ ASSERT_THROWS(
+ _client.getMore("unittests.querytests.GetMoreInvalidRequest_WRONG_NAMESPACE_FOR_CURSOR",
+ cursor->getCursorId()),
+ UserException);
// Check that the cursor still exists
{
@@ -486,9 +479,7 @@ public:
insert(ns, BSON("a" << 3));
// We have overwritten the previous cursor position and should encounter a dead cursor.
- if (c->more()) {
- ASSERT_THROWS(c->nextSafe(), AssertionException);
- }
+ ASSERT_THROWS(c->more() ? c->nextSafe() : BSONObj(), AssertionException);
}
};
@@ -512,9 +503,7 @@ public:
insert(ns, BSON("a" << 4));
// We have overwritten the previous cursor position and should encounter a dead cursor.
- if (c->more()) {
- ASSERT_THROWS(c->nextSafe(), AssertionException);
- }
+ ASSERT_THROWS(c->more() ? c->nextSafe() : BSONObj(), AssertionException);
}
};
@@ -550,9 +539,8 @@ public:
void run() {
const char* ns = "unittests.querytests.TailCappedOnly";
_client.insert(ns, BSONObj());
- unique_ptr<DBClientCursor> c =
- _client.query(ns, BSONObj(), 0, 0, 0, QueryOption_CursorTailable);
- ASSERT(c->isDead());
+ ASSERT_THROWS(_client.query(ns, BSONObj(), 0, 0, 0, QueryOption_CursorTailable),
+ UserException);
}
};
@@ -687,7 +675,8 @@ public:
0,
0,
0,
- QueryOption_OplogReplay | QueryOption_CursorTailable);
+ QueryOption_OplogReplay | QueryOption_CursorTailable |
+ DBClientCursor::QueryOptionLocal_forceOpQuery);
ASSERT(c->more());
ASSERT_EQUALS(two, c->next()["ts"].Date());
long long cursorId = c->getCursorId();
@@ -1348,9 +1337,12 @@ public:
insertNext();
}
- while (c->more()) {
- c->next();
- }
+ ASSERT_THROWS(([&] {
+ while (c->more()) {
+ c->nextSafe();
+ }
+ }()),
+ UserException);
}
void insertNext() {