/**
* Copyright (C) 2016 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 .
*
* 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.
*/
#pragma once
#include "mongo/s/sharding_mongod_test_fixture.h"
namespace mongo {
class BSONObj;
class ChunkType;
struct ChunkVersion;
class KeysCollectionDocument;
class NamespaceString;
class Shard;
class ShardId;
class ShardRegistry;
class ShardType;
template
class StatusWith;
/**
* Provides config-specific functionality in addition to the mock storage engine and mock network
* provided by ShardingMongodTestFixture.
*/
class ConfigServerTestFixture : public ShardingMongodTestFixture {
public:
ConfigServerTestFixture();
~ConfigServerTestFixture();
std::shared_ptr getConfigShard() const;
/**
* Insert a document to this config server to the specified namespace.
*/
Status insertToConfigCollection(OperationContext* opCtx,
const NamespaceString& ns,
const BSONObj& doc);
/**
* Updates a document to this config server to the specified namespace.
*/
Status updateToConfigCollection(OperationContext* opCtx,
const NamespaceString& ns,
const BSONObj& query,
const BSONObj& update,
const bool upsert);
/**
* Deletes a document to this config server to the specified namespace.
*/
Status deleteToConfigCollection(OperationContext* opCtx,
const NamespaceString& ns,
const BSONObj& doc,
const bool multi);
/**
* Reads a single document from a collection living on the config server.
*/
StatusWith findOneOnConfigCollection(OperationContext* opCtx,
const NamespaceString& ns,
const BSONObj& filter);
/**
* Setup the config.shards collection to contain the given shards.
*/
Status setupShards(const std::vector& shards);
/**
* Retrieves the shard document from the config server.
* Returns {ErrorCodes::ShardNotFound} if the given shard does not exists.
*/
StatusWith getShardDoc(OperationContext* opCtx, const std::string& shardId);
/**
* Setup the config.chunks collection to contain the given chunks.
*/
Status setupChunks(const std::vector& chunks);
/**
* Retrieves the chunk document from the config server.
*/
StatusWith getChunkDoc(OperationContext* opCtx, const BSONObj& minKey);
/**
* Inserts a document for the database into the config.databases collection.
*/
void setupDatabase(const std::string& dbName, const ShardId primaryShard, const bool sharded);
/**
* Returns the indexes definitions defined on a given collection.
*/
StatusWith> getIndexes(OperationContext* opCtx, const NamespaceString& ns);
/**
* Expects a setShardVersion command to be executed on the specified shard.
*
* The expectedChunkVersion is optional, because in some cases it may not be possible to know
* the OID of a ChunkVersion generated by some internal code. (See SERVER-29451).
*/
void expectSetShardVersion(const HostAndPort& expectedHost,
const ShardType& expectedShard,
const NamespaceString& expectedNs,
boost::optional expectedChunkVersion);
/**
* Returns the stored raw pointer to the addShard TaskExecutor's NetworkInterface.
*/
executor::NetworkInterfaceMock* networkForAddShard() const;
/**
* Returns the stored raw pointer to the addShard TaskExecutor.
*/
executor::TaskExecutor* executorForAddShard() const;
/**
* Same as ShardingMongodTestFixture::onCommand but run against _addShardNetworkTestEnv.
*/
void onCommandForAddShard(executor::NetworkTestEnv::OnCommandFunction func);
/**
* Returns all the keys in admin.system.keys
*/
std::vector getKeys(OperationContext* opCtx);
protected:
/**
* Sets this node up as a mongod with sharding components for ClusterRole::ConfigServer.
*/
void setUp() override;
void tearDown() override;
std::unique_ptr makeDistLockCatalog() override;
std::unique_ptr makeDistLockManager(
std::unique_ptr distLockCatalog) override;
std::unique_ptr makeShardingCatalogClient(
std::unique_ptr distLockManager) override;
std::unique_ptr makeClusterCursorManager() override;
std::unique_ptr makeBalancerConfiguration() override;
private:
// Since these are currently private members of the real ShardingCatalogManager, we store a raw
// pointer to them here.
executor::NetworkInterfaceMock* _mockNetworkForAddShard;
executor::TaskExecutor* _executorForAddShard;
// Allows for processing tasks through the NetworkInterfaceMock/ThreadPoolMock subsystem.
std::unique_ptr _addShardNetworkTestEnv;
};
} // namespace mongo