summaryrefslogtreecommitdiff
path: root/src/mongo/s
diff options
context:
space:
mode:
Diffstat (limited to 'src/mongo/s')
-rw-r--r--src/mongo/s/SConscript4
-rw-r--r--src/mongo/s/async_requests_sender.cpp2
-rw-r--r--src/mongo/s/catalog_cache_test_fixture.cpp6
-rw-r--r--src/mongo/s/client/shard_registry.cpp2
-rw-r--r--src/mongo/s/client/sharding_network_connection_hook.cpp3
-rw-r--r--src/mongo/s/cluster_cursor_stats.cpp5
-rw-r--r--src/mongo/s/cluster_identity_loader_test.cpp13
-rw-r--r--src/mongo/s/commands/SConscript3
-rw-r--r--src/mongo/s/commands/cluster_aggregate_test.cpp8
-rw-r--r--src/mongo/s/commands/compute_at_cluster_time_test.cpp8
-rw-r--r--src/mongo/s/grid.cpp6
-rw-r--r--src/mongo/s/grid.h4
-rw-r--r--src/mongo/s/metadata_filtering_test.cpp2
-rw-r--r--src/mongo/s/query/SConscript8
-rw-r--r--src/mongo/s/query/async_results_merger_test.cpp8
-rw-r--r--src/mongo/s/query/cluster_client_cursor_impl_test.cpp26
-rw-r--r--src/mongo/s/query/cluster_cursor_manager_test.cpp55
-rw-r--r--src/mongo/s/query/cluster_find_test.cpp4
-rw-r--r--src/mongo/s/server.cpp12
-rw-r--r--src/mongo/s/sharding_mongod_test_fixture.cpp16
-rw-r--r--src/mongo/s/sharding_mongod_test_fixture.h1
-rw-r--r--src/mongo/s/sharding_router_test_fixture.cpp27
-rw-r--r--src/mongo/s/sharding_router_test_fixture.h8
23 files changed, 62 insertions, 169 deletions
diff --git a/src/mongo/s/SConscript b/src/mongo/s/SConscript
index bda3163ced7..553f2211387 100644
--- a/src/mongo/s/SConscript
+++ b/src/mongo/s/SConscript
@@ -180,7 +180,7 @@ env.Library(
],
LIBDEPS=[
'$BUILD_DIR/mongo/db/query/collation/collator_factory_mock',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
+ '$BUILD_DIR/mongo/db/service_context_test_fixture',
'$BUILD_DIR/mongo/executor/task_executor_pool',
'$BUILD_DIR/mongo/s/catalog/dist_lock_manager_mock',
'$BUILD_DIR/mongo/s/catalog/sharding_catalog_client_impl',
@@ -485,9 +485,7 @@ env.CppUnitTest(
'client/shard_connection_test.cpp',
],
LIBDEPS=[
- '$BUILD_DIR/mongo/db/service_context_noop_init',
'$BUILD_DIR/mongo/dbtests/mocklib',
- '$BUILD_DIR/mongo/transport/transport_layer_egress_init',
'$BUILD_DIR/mongo/util/net/network',
'client/sharding_connection_hook',
'sharding_legacy_api',
diff --git a/src/mongo/s/async_requests_sender.cpp b/src/mongo/s/async_requests_sender.cpp
index b944ac0bb8d..61efb9ae468 100644
--- a/src/mongo/s/async_requests_sender.cpp
+++ b/src/mongo/s/async_requests_sender.cpp
@@ -392,7 +392,7 @@ Status AsyncRequestsSender::RemoteData::resolveShardIdToHostAndPort(
std::shared_ptr<Shard> AsyncRequestsSender::RemoteData::getShard() {
// TODO: Pass down an OperationContext* to use here.
- return grid.shardRegistry()->getShardNoReload(shardId);
+ return Grid::get(getGlobalServiceContext())->shardRegistry()->getShardNoReload(shardId);
}
AsyncRequestsSender::BatonDetacher::BatonDetacher(OperationContext* opCtx)
diff --git a/src/mongo/s/catalog_cache_test_fixture.cpp b/src/mongo/s/catalog_cache_test_fixture.cpp
index a1ab2acbba7..835aedebf2f 100644
--- a/src/mongo/s/catalog_cache_test_fixture.cpp
+++ b/src/mongo/s/catalog_cache_test_fixture.cpp
@@ -57,15 +57,15 @@ void CatalogCacheTestFixture::setUp() {
setRemote(HostAndPort("FakeRemoteClient:34567"));
configTargeter()->setFindHostReturnValue(kConfigHostAndPort);
- CollatorFactoryInterface::set(serviceContext(), stdx::make_unique<CollatorFactoryMock>());
+ CollatorFactoryInterface::set(getServiceContext(), stdx::make_unique<CollatorFactoryMock>());
}
executor::NetworkTestEnv::FutureHandle<boost::optional<CachedCollectionRoutingInfo>>
CatalogCacheTestFixture::scheduleRoutingInfoRefresh(const NamespaceString& nss) {
return launchAsync([this, nss] {
- auto client = serviceContext()->makeClient("Test");
+ auto client = getServiceContext()->makeClient("Test");
auto opCtx = client->makeOperationContext();
- auto const catalogCache = Grid::get(serviceContext())->catalogCache();
+ auto const catalogCache = Grid::get(getServiceContext())->catalogCache();
catalogCache->invalidateShardedCollection(nss);
return boost::make_optional(
diff --git a/src/mongo/s/client/shard_registry.cpp b/src/mongo/s/client/shard_registry.cpp
index ddc749edcd9..e450fa9e54e 100644
--- a/src/mongo/s/client/shard_registry.cpp
+++ b/src/mongo/s/client/shard_registry.cpp
@@ -345,7 +345,7 @@ void ShardRegistry::replicaSetChangeShardRegistryUpdateHook(
// Inform the ShardRegsitry of the new connection string for the shard.
auto connString = fassert(28805, ConnectionString::parse(newConnectionString));
invariant(setName == connString.getSetName());
- grid.shardRegistry()->updateReplSetHosts(connString);
+ Grid::get(getGlobalServiceContext())->shardRegistry()->updateReplSetHosts(connString);
}
void ShardRegistry::replicaSetChangeConfigServerUpdateHook(const std::string& setName,
diff --git a/src/mongo/s/client/sharding_network_connection_hook.cpp b/src/mongo/s/client/sharding_network_connection_hook.cpp
index 88ed8882b60..7bc307e4ab7 100644
--- a/src/mongo/s/client/sharding_network_connection_hook.cpp
+++ b/src/mongo/s/client/sharding_network_connection_hook.cpp
@@ -53,7 +53,8 @@ Status ShardingNetworkConnectionHook::validateHost(
Status ShardingNetworkConnectionHook::validateHostImpl(
const HostAndPort& remoteHost, const executor::RemoteCommandResponse& isMasterReply) {
- auto shard = grid.shardRegistry()->getShardForHostNoReload(remoteHost);
+ auto shard =
+ Grid::get(getGlobalServiceContext())->shardRegistry()->getShardForHostNoReload(remoteHost);
if (!shard) {
return {ErrorCodes::ShardNotFound,
str::stream() << "No shard found for host: " << remoteHost.toString()};
diff --git a/src/mongo/s/cluster_cursor_stats.cpp b/src/mongo/s/cluster_cursor_stats.cpp
index 4aa5ca97891..2906fbfc8df 100644
--- a/src/mongo/s/cluster_cursor_stats.cpp
+++ b/src/mongo/s/cluster_cursor_stats.cpp
@@ -44,12 +44,13 @@ public:
ClusterCursorStats() : ServerStatusMetric("cursor") {}
void appendAtLeaf(BSONObjBuilder& b) const final {
+ auto grid = Grid::get(getGlobalServiceContext());
BSONObjBuilder cursorBob(b.subobjStart(_leafName));
cursorBob.append("timedOut",
- static_cast<long long>(grid.getCursorManager()->cursorsTimedOut()));
+ static_cast<long long>(grid->getCursorManager()->cursorsTimedOut()));
{
BSONObjBuilder openBob(cursorBob.subobjStart("open"));
- auto stats = grid.getCursorManager()->stats();
+ auto stats = grid->getCursorManager()->stats();
openBob.append("multiTarget", static_cast<long long>(stats.cursorsMultiTarget));
openBob.append("singleTarget", static_cast<long long>(stats.cursorsSingleTarget));
openBob.append("pinned", static_cast<long long>(stats.cursorsPinned));
diff --git a/src/mongo/s/cluster_identity_loader_test.cpp b/src/mongo/s/cluster_identity_loader_test.cpp
index 98817150d6b..18685da1086 100644
--- a/src/mongo/s/cluster_identity_loader_test.cpp
+++ b/src/mongo/s/cluster_identity_loader_test.cpp
@@ -35,7 +35,7 @@
#include "mongo/client/remote_command_targeter_mock.h"
#include "mongo/db/commands.h"
#include "mongo/db/query/query_request.h"
-#include "mongo/db/service_context_noop.h"
+#include "mongo/db/service_context.h"
#include "mongo/executor/network_interface_mock.h"
#include "mongo/executor/task_executor.h"
#include "mongo/rpc/metadata/repl_set_metadata.h"
@@ -67,19 +67,10 @@ BSONObj getReplSecondaryOkMetadata() {
class ClusterIdentityTest : public ShardingTestFixture {
public:
- void setUp() override {
- ShardingTestFixture::setUp();
-
+ ClusterIdentityTest() {
configTargeter()->setFindHostReturnValue(configHost);
}
- void tearDown() override {
- ShardingTestFixture::tearDown();
-
- // Reset the global service context so that the cluster identity gets cleared
- setGlobalServiceContext(std::make_unique<ServiceContextNoop>());
- }
-
void expectConfigVersionLoad(StatusWith<OID> result) {
onFindCommand([&](const RemoteCommandRequest& request) {
ASSERT_EQUALS(configHost, request.target);
diff --git a/src/mongo/s/commands/SConscript b/src/mongo/s/commands/SConscript
index cfb4aca929c..c1e7a9d1092 100644
--- a/src/mongo/s/commands/SConscript
+++ b/src/mongo/s/commands/SConscript
@@ -129,7 +129,6 @@ env.CppUnitTest(
LIBDEPS=[
'shared_cluster_commands',
'$BUILD_DIR/mongo/db/auth/authmocks',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
'$BUILD_DIR/mongo/db/logical_time',
'$BUILD_DIR/mongo/unittest/unittest',
]
@@ -144,7 +143,6 @@ env.CppUnitTest(
'shared_cluster_commands',
'$BUILD_DIR/mongo/s/catalog_cache_test_fixture',
'$BUILD_DIR/mongo/db/auth/authmocks',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
'$BUILD_DIR/mongo/db/logical_clock',
'$BUILD_DIR/mongo/unittest/unittest',
]
@@ -159,7 +157,6 @@ env.CppUnitTest(
'cluster_commands',
'$BUILD_DIR/mongo/db/auth/authmocks',
'$BUILD_DIR/mongo/db/auth/saslauth',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
'$BUILD_DIR/mongo/s/catalog_cache_test_fixture',
],
)
diff --git a/src/mongo/s/commands/cluster_aggregate_test.cpp b/src/mongo/s/commands/cluster_aggregate_test.cpp
index 37a94a57c5a..4f11447faac 100644
--- a/src/mongo/s/commands/cluster_aggregate_test.cpp
+++ b/src/mongo/s/commands/cluster_aggregate_test.cpp
@@ -69,10 +69,10 @@ protected:
CatalogCacheTestFixture::setupNShards(numShards);
// Set up a logical clock with an initial time.
- auto logicalClock = stdx::make_unique<LogicalClock>(serviceContext());
+ auto logicalClock = stdx::make_unique<LogicalClock>(getServiceContext());
LogicalTime initialTime(Timestamp(10, 1));
logicalClock->setClusterTimeFromTrustedSource(initialTime);
- LogicalClock::set(serviceContext(), std::move(logicalClock));
+ LogicalClock::set(getServiceContext(), std::move(logicalClock));
auto keysCollectionClient = stdx::make_unique<KeysCollectionClientSharded>(
Grid::get(operationContext())->catalogClient());
@@ -81,7 +81,7 @@ protected:
"dummy", std::move(keysCollectionClient), Seconds(KeysRotationIntervalSec));
auto validator = stdx::make_unique<LogicalTimeValidator>(keyManager);
- LogicalTimeValidator::set(serviceContext(), std::move(validator));
+ LogicalTimeValidator::set(getServiceContext(), std::move(validator));
// ReadConcern 'snapshot' is only supported with test commands enabled.
setTestCommandsEnabled(true);
@@ -123,7 +123,7 @@ protected:
DbResponse runAggregateCommand(BSONObj aggCmd) {
// Create a new client/operation context per command, and setup a test session ID and
// transaction number.
- auto client = serviceContext()->makeClient("ClusterAggClient");
+ auto client = getServiceContext()->makeClient("ClusterAggClient");
auto opCtx = client->makeOperationContext();
opCtx->setLogicalSessionId(makeLogicalSessionIdForTest());
opCtx->setTxnNumber(1);
diff --git a/src/mongo/s/commands/compute_at_cluster_time_test.cpp b/src/mongo/s/commands/compute_at_cluster_time_test.cpp
index a4701547bbb..4d34d390326 100644
--- a/src/mongo/s/commands/compute_at_cluster_time_test.cpp
+++ b/src/mongo/s/commands/compute_at_cluster_time_test.cpp
@@ -71,9 +71,9 @@ protected:
repl::ReadConcernArgs(repl::ReadConcernLevel::kSnapshotReadConcern);
// Set up a logical clock with an initial time.
- auto logicalClock = stdx::make_unique<LogicalClock>(serviceContext());
+ auto logicalClock = stdx::make_unique<LogicalClock>(getServiceContext());
logicalClock->setClusterTimeFromTrustedSource(kInMemoryLogicalTime);
- LogicalClock::set(serviceContext(), std::move(logicalClock));
+ LogicalClock::set(getServiceContext(), std::move(logicalClock));
}
};
@@ -131,9 +131,9 @@ protected:
CatalogCacheTestFixture::setupNShards(2);
// Set up a logical clock with an initial time.
- auto logicalClock = stdx::make_unique<LogicalClock>(serviceContext());
+ auto logicalClock = stdx::make_unique<LogicalClock>(getServiceContext());
logicalClock->setClusterTimeFromTrustedSource(kInMemoryLogicalTime);
- LogicalClock::set(serviceContext(), std::move(logicalClock));
+ LogicalClock::set(getServiceContext(), std::move(logicalClock));
}
};
diff --git a/src/mongo/s/grid.cpp b/src/mongo/s/grid.cpp
index 6570ca0c751..65d8b1c1f8c 100644
--- a/src/mongo/s/grid.cpp
+++ b/src/mongo/s/grid.cpp
@@ -44,15 +44,17 @@
namespace mongo {
+namespace {
// Global grid instance
-Grid grid;
+const auto grid = ServiceContext::declareDecoration<Grid>();
+}
Grid::Grid() = default;
Grid::~Grid() = default;
Grid* Grid::get(ServiceContext* serviceContext) {
- return &grid;
+ return &grid(serviceContext);
}
Grid* Grid::get(OperationContext* operationContext) {
diff --git a/src/mongo/s/grid.h b/src/mongo/s/grid.h
index 443c9b81304..02da388532b 100644
--- a/src/mongo/s/grid.h
+++ b/src/mongo/s/grid.h
@@ -200,8 +200,4 @@ private:
bool _allowLocalShard{true};
};
-// Reference to the global Grid instance. Do not use in new code. Use one of the Grid::get methods
-// instead.
-extern Grid grid;
-
} // namespace mongo
diff --git a/src/mongo/s/metadata_filtering_test.cpp b/src/mongo/s/metadata_filtering_test.cpp
index 826ac629429..42926b7e5e6 100644
--- a/src/mongo/s/metadata_filtering_test.cpp
+++ b/src/mongo/s/metadata_filtering_test.cpp
@@ -53,7 +53,7 @@ protected:
setupNShards(2);
- _manager = std::make_shared<MetadataManager>(serviceContext(), kNss, executor());
+ _manager = std::make_shared<MetadataManager>(getServiceContext(), kNss, executor());
}
void expectGetDatabase() {
diff --git a/src/mongo/s/query/SConscript b/src/mongo/s/query/SConscript
index cd9a6c903c4..07ace658aab 100644
--- a/src/mongo/s/query/SConscript
+++ b/src/mongo/s/query/SConscript
@@ -30,7 +30,6 @@ env.CppUnitTest(
LIBDEPS=[
'cluster_query',
'$BUILD_DIR/mongo/db/auth/authmocks',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
'$BUILD_DIR/mongo/s/catalog_cache_test_fixture',
],
)
@@ -77,7 +76,6 @@ env.CppUnitTest(
LIBDEPS=[
'router_exec_stage',
'$BUILD_DIR/mongo/db/auth/authmocks',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
],
)
@@ -117,7 +115,6 @@ env.CppUnitTest(
'cluster_client_cursor',
'$BUILD_DIR/mongo/db/auth/authmocks',
'$BUILD_DIR/mongo/db/query/query_request',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
'$BUILD_DIR/mongo/executor/thread_pool_task_executor_test_fixture',
'$BUILD_DIR/mongo/s/sharding_router_test_fixture',
],
@@ -132,7 +129,6 @@ env.CppUnitTest(
'async_results_merger',
'$BUILD_DIR/mongo/db/auth/authmocks',
'$BUILD_DIR/mongo/db/query/query_request',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
'$BUILD_DIR/mongo/s/sharding_router_test_fixture',
],
)
@@ -159,7 +155,6 @@ env.CppUnitTest(
'store_possible_cursor',
'$BUILD_DIR/mongo/db/auth/authmocks',
'$BUILD_DIR/mongo/db/query/query_test_service_context',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
'$BUILD_DIR/mongo/util/clock_source_mock',
],
)
@@ -187,6 +182,7 @@ env.CppUnitTest(
],
LIBDEPS=[
"$BUILD_DIR/mongo/db/logical_session_id",
+ "$BUILD_DIR/mongo/db/service_context_test_fixture",
"$BUILD_DIR/mongo/util/clock_source_mock",
"cluster_client_cursor_mock",
"cluster_cursor_manager",
@@ -213,6 +209,6 @@ env.CppUnitTest(
LIBDEPS=[
'cluster_client_cursor',
'$BUILD_DIR/mongo/db/auth/authmocks',
- '$BUILD_DIR/mongo/db/service_context_noop_init',
+ '$BUILD_DIR/mongo/db/service_context_test_fixture',
],
)
diff --git a/src/mongo/s/query/async_results_merger_test.cpp b/src/mongo/s/query/async_results_merger_test.cpp
index 662d78e6dd0..64428771bb0 100644
--- a/src/mongo/s/query/async_results_merger_test.cpp
+++ b/src/mongo/s/query/async_results_merger_test.cpp
@@ -74,7 +74,6 @@ public:
AsyncResultsMergerTest() {}
void setUp() override {
- ShardingTestFixture::setUp();
setRemote(HostAndPort("ClientHost", 12345));
configTargeter()->setFindHostReturnValue(kTestConfigShardHost);
@@ -100,10 +99,6 @@ public:
setupShards(shards);
}
- void tearDown() override {
- ShardingTestFixture::tearDown();
- }
-
protected:
/**
* Constructs an ARM with the given vector of existing cursors.
@@ -2072,7 +2067,8 @@ DEATH_TEST_F(AsyncResultsMergerTest,
params.setOperationSessionInfo(sessionInfo);
// This should trigger an invariant.
- stdx::make_unique<AsyncResultsMerger>(operationContext(), executor(), std::move(params));
+ ASSERT_FALSE(
+ stdx::make_unique<AsyncResultsMerger>(operationContext(), executor(), std::move(params)));
}
DEATH_TEST_F(AsyncResultsMergerTest,
diff --git a/src/mongo/s/query/cluster_client_cursor_impl_test.cpp b/src/mongo/s/query/cluster_client_cursor_impl_test.cpp
index c73b33a68e4..faf4d29dda1 100644
--- a/src/mongo/s/query/cluster_client_cursor_impl_test.cpp
+++ b/src/mongo/s/query/cluster_client_cursor_impl_test.cpp
@@ -32,7 +32,7 @@
#include "mongo/bson/bsonobj.h"
#include "mongo/bson/bsonobjbuilder.h"
-#include "mongo/db/service_context_noop.h"
+#include "mongo/db/service_context_test_fixture.h"
#include "mongo/s/query/router_stage_mock.h"
#include "mongo/stdx/memory.h"
#include "mongo/unittest/unittest.h"
@@ -41,27 +41,11 @@ namespace mongo {
namespace {
-class ClusterClientCursorImplTest : public unittest::Test {
+class ClusterClientCursorImplTest : public ServiceContextTest {
protected:
- ServiceContextNoop _serviceContext;
- ServiceContext::UniqueOperationContext _opCtx;
- Client* _client;
-
-private:
- void setUp() final {
- auto client = _serviceContext.makeClient("testClient");
- _opCtx = client->makeOperationContext();
- _client = client.get();
- Client::setCurrent(std::move(client));
- }
-
- void tearDown() final {
- if (_opCtx) {
- _opCtx.reset();
- }
+ ClusterClientCursorImplTest() : _opCtx(makeOperationContext()) {}
- Client::releaseCurrent();
- }
+ ServiceContext::UniqueOperationContext _opCtx;
};
TEST_F(ClusterClientCursorImplTest, NumReturnedSoFar) {
@@ -196,7 +180,7 @@ TEST_F(ClusterClientCursorImplTest, ChecksForInterrupt) {
// Now interrupt the opCtx which the cursor is running under.
{
- stdx::lock_guard<Client> lk(*_client);
+ stdx::lock_guard<Client> lk(*_opCtx->getClient());
_opCtx->markKilled(ErrorCodes::CursorKilled);
}
diff --git a/src/mongo/s/query/cluster_cursor_manager_test.cpp b/src/mongo/s/query/cluster_cursor_manager_test.cpp
index b5a2832cb1e..04a9d074ad7 100644
--- a/src/mongo/s/query/cluster_cursor_manager_test.cpp
+++ b/src/mongo/s/query/cluster_cursor_manager_test.cpp
@@ -34,8 +34,8 @@
#include "mongo/db/logical_session_cache.h"
#include "mongo/db/logical_session_cache_noop.h"
-#include "mongo/db/operation_context_noop.h"
-#include "mongo/db/service_context_noop.h"
+#include "mongo/db/operation_context.h"
+#include "mongo/db/service_context_test_fixture.h"
#include "mongo/s/query/cluster_client_cursor_mock.h"
#include "mongo/stdx/memory.h"
#include "mongo/unittest/unittest.h"
@@ -48,13 +48,17 @@ namespace {
using unittest::assertGet;
const NamespaceString nss("test.collection");
-class ClusterCursorManagerTest : public unittest::Test {
+class ClusterCursorManagerTest : public ServiceContextTest {
protected:
- ClusterCursorManagerTest() : _manager(&_clockSourceMock) {}
+ ClusterCursorManagerTest() : _opCtx(makeOperationContext()), _manager(&_clockSourceMock) {
+ LogicalSessionCache::set(getServiceContext(), stdx::make_unique<LogicalSessionCacheNoop>());
+ }
+
+ ~ClusterCursorManagerTest() {
+ _manager.shutdown(_opCtx.get());
+ }
- ServiceContextNoop serviceContext;
ServiceContext::UniqueOperationContext _opCtx;
- Client* _client;
static Status successAuthChecker(UserNameIterator userNames) {
return Status::OK();
@@ -106,49 +110,16 @@ protected:
}
void killCursorFromDifferentOpCtx(const NamespaceString& nss, CursorId cursorId) {
- // Set up another client to kill the cursor.
- auto killCursorClientOwned = serviceContext.makeClient("killCursorClient");
- // Keep around a raw pointer for when we transfer ownership of killingClientOwned to the
- // global current client.
- Client* killCursorClient = killCursorClientOwned.get();
-
- // Need to swap the current client in order to make an operation context.
- auto pinningClient = Client::releaseCurrent();
- Client::setCurrent(std::move(killCursorClientOwned));
+ // Set up another client to kill the cursor.
+ auto killCursorClient = getServiceContext()->makeClient("killCursorClient");
auto killCursorOpCtx = killCursorClient->makeOperationContext();
- invariant(killCursorOpCtx);
+ AlternativeClientRegion acr(killCursorClient);
ASSERT_OK(getManager()->killCursor(killCursorOpCtx.get(), nss, cursorId));
-
- // Restore the old client. We don't need 'killCursorClient' anymore.
- killCursorOpCtx.reset();
- Client::releaseCurrent();
-
- Client::setCurrent(std::move(pinningClient));
}
private:
- void setUp() final {
- auto client = serviceContext.makeClient("testClient");
- _opCtx = client->makeOperationContext();
- _client = client.get();
- Client::setCurrent(std::move(client));
-
- LogicalSessionCache::set(&serviceContext, stdx::make_unique<LogicalSessionCacheNoop>());
- }
-
- void tearDown() final {
- _manager.shutdown(_opCtx.get());
-
- if (_opCtx) {
- _opCtx.reset();
- }
-
- Client::releaseCurrent();
- LogicalSessionCache::set(&serviceContext, nullptr);
- }
-
// List of flags representing whether our allocated cursors have been killed yet. The value of
// the flag is true iff the cursor has been killed.
//
diff --git a/src/mongo/s/query/cluster_find_test.cpp b/src/mongo/s/query/cluster_find_test.cpp
index e588521c80b..ccba55977a6 100644
--- a/src/mongo/s/query/cluster_find_test.cpp
+++ b/src/mongo/s/query/cluster_find_test.cpp
@@ -65,9 +65,9 @@ protected:
CatalogCacheTestFixture::setupNShards(numShards);
// Set up a logical clock with an initial time.
- auto logicalClock = stdx::make_unique<LogicalClock>(serviceContext());
+ auto logicalClock = stdx::make_unique<LogicalClock>(getServiceContext());
logicalClock->setClusterTimeFromTrustedSource(kInMemoryLogicalTime);
- LogicalClock::set(serviceContext(), std::move(logicalClock));
+ LogicalClock::set(getServiceContext(), std::move(logicalClock));
}
// The index of the shard expected to receive the response is used to prevent different shards
diff --git a/src/mongo/s/server.cpp b/src/mongo/s/server.cpp
index 5978f4d4f4c..9e7358b2ca6 100644
--- a/src/mongo/s/server.cpp
+++ b/src/mongo/s/server.cpp
@@ -60,8 +60,6 @@
#include "mongo/db/operation_context.h"
#include "mongo/db/server_options.h"
#include "mongo/db/service_context.h"
-#include "mongo/db/service_context_noop.h"
-#include "mongo/db/service_context_registrar.h"
#include "mongo/db/session_killer.h"
#include "mongo/db/startup_warnings_common.h"
#include "mongo/db/wire_version.h"
@@ -112,8 +110,6 @@
#include "mongo/util/signal_handlers.h"
#include "mongo/util/stacktrace.h"
#include "mongo/util/stringutils.h"
-#include "mongo/util/system_clock_source.h"
-#include "mongo/util/system_tick_source.h"
#include "mongo/util/text.h"
#include "mongo/util/version.h"
@@ -547,14 +543,6 @@ MONGO_INITIALIZER_WITH_PREREQUISITES(SetFeatureCompatibilityVersion40, ("EndStar
return Status::OK();
}
-ServiceContextRegistrar serviceContextCreator([]() {
- auto service = std::make_unique<ServiceContextNoop>();
- service->setTickSource(std::make_unique<SystemTickSource>());
- service->setFastClockSource(std::make_unique<SystemClockSource>());
- service->setPreciseClockSource(std::make_unique<SystemClockSource>());
- return service;
-});
-
#ifdef MONGO_CONFIG_SSL
MONGO_INITIALIZER_GENERAL(setSSLManagerType, MONGO_NO_PREREQUISITES, ("SSLManager"))
(InitializerContext* context) {
diff --git a/src/mongo/s/sharding_mongod_test_fixture.cpp b/src/mongo/s/sharding_mongod_test_fixture.cpp
index f9a54847fd2..6fa3565cab9 100644
--- a/src/mongo/s/sharding_mongod_test_fixture.cpp
+++ b/src/mongo/s/sharding_mongod_test_fixture.cpp
@@ -33,6 +33,7 @@
#include <algorithm>
#include <vector>
+#include "mongo/base/checked_cast.h"
#include "mongo/base/status_with.h"
#include "mongo/client/remote_command_targeter_factory_mock.h"
#include "mongo/client/remote_command_targeter_mock.h"
@@ -55,7 +56,6 @@
#include "mongo/db/repl/storage_interface_mock.h"
#include "mongo/db/s/config_server_op_observer.h"
#include "mongo/db/s/shard_server_op_observer.h"
-#include "mongo/db/service_context_noop.h"
#include "mongo/executor/network_interface_mock.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/executor/thread_pool_task_executor_test_fixture.h"
@@ -135,14 +135,10 @@ void ShardingMongodTestFixture::setUp() {
repl::StorageInterface::set(service, std::move(storagePtr));
- auto makeOpObserver = [&] {
- auto opObserver = stdx::make_unique<OpObserverRegistry>();
- opObserver->addObserver(stdx::make_unique<OpObserverImpl>());
- opObserver->addObserver(stdx::make_unique<ConfigServerOpObserver>());
- opObserver->addObserver(stdx::make_unique<ShardServerOpObserver>());
- return opObserver;
- };
- service->setOpObserver(makeOpObserver());
+ auto opObserver = checked_cast<OpObserverRegistry*>(service->getOpObserver());
+ opObserver->addObserver(stdx::make_unique<OpObserverImpl>());
+ opObserver->addObserver(stdx::make_unique<ConfigServerOpObserver>());
+ opObserver->addObserver(stdx::make_unique<ShardServerOpObserver>());
repl::setOplogCollectionName(service);
repl::createOplog(_opCtx.get());
@@ -308,8 +304,6 @@ void ShardingMongodTestFixture::tearDown() {
Grid::get(operationContext())->clearForUnitTests();
_opCtx.reset();
- _client.reset();
-
ServiceContextMongoDTest::tearDown();
}
diff --git a/src/mongo/s/sharding_mongod_test_fixture.h b/src/mongo/s/sharding_mongod_test_fixture.h
index 222fbfd5184..02b41cfab5e 100644
--- a/src/mongo/s/sharding_mongod_test_fixture.h
+++ b/src/mongo/s/sharding_mongod_test_fixture.h
@@ -189,7 +189,6 @@ private:
const std::vector<HostAndPort> _servers{
_host, HostAndPort("node2:12345"), HostAndPort("node3:12345")};
- ServiceContext::UniqueClient _client;
ServiceContext::UniqueOperationContext _opCtx;
// Since the RemoteCommandTargeterFactory is currently a private member of ShardFactory, we
diff --git a/src/mongo/s/sharding_router_test_fixture.cpp b/src/mongo/s/sharding_router_test_fixture.cpp
index 132e375b160..e42c1e41316 100644
--- a/src/mongo/s/sharding_router_test_fixture.cpp
+++ b/src/mongo/s/sharding_router_test_fixture.cpp
@@ -44,7 +44,6 @@
#include "mongo/db/query/collation/collator_factory_mock.h"
#include "mongo/db/query/query_request.h"
#include "mongo/db/repl/read_concern_args.h"
-#include "mongo/db/service_context_noop.h"
#include "mongo/executor/network_interface_mock.h"
#include "mongo/executor/task_executor_pool.h"
#include "mongo/executor/thread_pool_task_executor_test_fixture.h"
@@ -94,12 +93,8 @@ std::unique_ptr<ShardingTaskExecutor> makeShardingTestExecutor(
} // namespace
-ShardingTestFixture::ShardingTestFixture() = default;
-
-ShardingTestFixture::~ShardingTestFixture() = default;
-
-void ShardingTestFixture::setUp() {
- auto const service = serviceContext();
+ShardingTestFixture::ShardingTestFixture() {
+ auto const service = getServiceContext();
// Configure the service context
service->setFastClockSource(stdx::make_unique<ClockSourceMock>());
@@ -108,8 +103,7 @@ void ShardingTestFixture::setUp() {
CollatorFactoryInterface::set(service, stdx::make_unique<CollatorFactoryMock>());
_transportSession = transport::MockSession::create(nullptr);
- _client = service->makeClient("ShardingTestFixture", _transportSession);
- _opCtx = _client->makeOperationContext();
+ _opCtx = makeOperationContext();
// Set up executor pool used for most operations.
auto makeMetadataHookList = [&] {
@@ -194,16 +188,9 @@ void ShardingTestFixture::setUp() {
_mockNetwork);
}
-void ShardingTestFixture::tearDown() {
- CatalogCacheLoader::clearForTests(serviceContext());
-
- Grid::get(operationContext())->getExecutorPool()->shutdownAndJoin();
- Grid::get(operationContext())->catalogClient()->shutDown(_opCtx.get());
- Grid::get(operationContext())->clearForUnitTests();
- _transportSession.reset();
- _opCtx.reset();
- _client.reset();
+ShardingTestFixture::~ShardingTestFixture() {
+ CatalogCacheLoader::clearForTests(getServiceContext());
}
void ShardingTestFixture::shutdownExecutor() {
@@ -243,10 +230,6 @@ DistLockManagerMock* ShardingTestFixture::distLock() const {
return _distLockManager;
}
-ServiceContext* ShardingTestFixture::serviceContext() const {
- return getGlobalServiceContext();
-}
-
OperationContext* ShardingTestFixture::operationContext() const {
invariant(_opCtx);
diff --git a/src/mongo/s/sharding_router_test_fixture.h b/src/mongo/s/sharding_router_test_fixture.h
index 05c1fa37a88..3eadf92a225 100644
--- a/src/mongo/s/sharding_router_test_fixture.h
+++ b/src/mongo/s/sharding_router_test_fixture.h
@@ -28,6 +28,7 @@
#pragma once
+#include "mongo/db/service_context_test_fixture.h"
#include "mongo/s/sharding_test_fixture_common.h"
namespace mongo {
@@ -50,7 +51,7 @@ class TransportLayerMock;
* Sets up the mocked out objects for testing the replica-set backed catalog manager and catalog
* client.
*/
-class ShardingTestFixture : public unittest::Test, public ShardingTestFixtureCommon {
+class ShardingTestFixture : public ServiceContextTest, public ShardingTestFixtureCommon {
public:
ShardingTestFixture();
~ShardingTestFixture();
@@ -64,7 +65,6 @@ public:
DistLockManagerMock* distLock() const;
RemoteCommandTargeterMock* configTargeter() const;
- ServiceContext* serviceContext() const;
OperationContext* operationContext() const;
/**
@@ -170,10 +170,6 @@ public:
const NamespaceString& expectedNs,
const ChunkVersion& expectedChunkVersion);
- void setUp() override;
-
- void tearDown() override;
-
void shutdownExecutor();
void setRemote(const HostAndPort& remote);