0
0
mirror of https://github.com/mongodb/mongo.git synced 2024-12-01 09:32:32 +01:00

SERVER-19111 Add insert op checking to catalog manager test fixture

This change adds a shortcut method to declare expectation that a
particular set of insertions are about to happen.
This commit is contained in:
Kaloian Manassiev 2015-07-07 10:21:59 -04:00
parent 932e768dc2
commit 317047bc0e
2 changed files with 36 additions and 0 deletions

View File

@ -47,6 +47,8 @@
#include "mongo/s/catalog/type_shard.h"
#include "mongo/s/client/shard_registry.h"
#include "mongo/s/grid.h"
#include "mongo/s/write_ops/batched_command_request.h"
#include "mongo/s/write_ops/batched_command_response.h"
#include "mongo/stdx/memory.h"
namespace mongo {
@ -197,4 +199,32 @@ void CatalogManagerReplSetTestFixture::setupShards(const std::vector<ShardType>&
future.timed_get(kFutureTimeout);
}
void CatalogManagerReplSetTestFixture::expectInserts(const NamespaceString nss,
std::vector<BSONObj> expected) {
onCommand([&nss, &expected](const RemoteCommandRequest& request) {
ASSERT_EQUALS(nss.db(), request.dbname);
BatchedInsertRequest actualBatchedInsert;
std::string errmsg;
ASSERT_TRUE(actualBatchedInsert.parseBSON(request.dbname, request.cmdObj, &errmsg));
ASSERT_EQUALS(nss.toString(), actualBatchedInsert.getNS().toString());
auto inserted = actualBatchedInsert.getDocuments();
ASSERT_EQUALS(expected.size(), inserted.size());
auto itInserted = inserted.begin();
auto itExpected = expected.begin();
for (; itInserted != inserted.end(); itInserted++, itExpected++) {
ASSERT_EQ(*itExpected, *itInserted);
}
BatchedCommandResponse response;
response.setOk(true);
return response.toBSON();
});
}
} // namespace mongo

View File

@ -98,6 +98,12 @@ protected:
*/
void setupShards(const std::vector<ShardType>& shards);
/**
* Wait for a single insert request and ensures that the items being inserted exactly match the
* expected items. Responds with a success status.
*/
void expectInserts(const NamespaceString nss, std::vector<BSONObj> expected);
void setUp() override;
void tearDown() override;