summaryrefslogtreecommitdiff
path: root/src/mongo/db/s/vector_clock_config_server_test.cpp
diff options
context:
space:
mode:
authorKevin Pulo <kevin.pulo@mongodb.com>2020-05-19 14:29:26 +1000
committerEvergreen Agent <no-reply@evergreen.mongodb.com>2020-06-05 12:48:36 +0000
commit7074dee1fbf6763c0d463c377c2e47d8ef2c4f6f (patch)
tree80d364f790c795d16b77fb1efa1cc5e3788e1d9c /src/mongo/db/s/vector_clock_config_server_test.cpp
parent5072922b32f94857098546366f17c93673154e72 (diff)
downloadmongo-7074dee1fbf6763c0d463c377c2e47d8ef2c4f6f.tar.gz
SERVER-47914 Move clusterTime from LogicalClock to VectorClock
Diffstat (limited to 'src/mongo/db/s/vector_clock_config_server_test.cpp')
-rw-r--r--src/mongo/db/s/vector_clock_config_server_test.cpp191
1 files changed, 171 insertions, 20 deletions
diff --git a/src/mongo/db/s/vector_clock_config_server_test.cpp b/src/mongo/db/s/vector_clock_config_server_test.cpp
index 30761daea07..6c62f4834ac 100644
--- a/src/mongo/db/s/vector_clock_config_server_test.cpp
+++ b/src/mongo/db/s/vector_clock_config_server_test.cpp
@@ -29,22 +29,63 @@
#include "mongo/platform/basic.h"
+#include "mongo/db/keys_collection_client_sharded.h"
+#include "mongo/db/keys_collection_manager.h"
+#include "mongo/db/logical_time_validator.h"
#include "mongo/db/vector_clock_mutable.h"
#include "mongo/s/config_server_test_fixture.h"
#include "mongo/unittest/death_test.h"
#include "mongo/unittest/unittest.h"
+#include "mongo/util/clock_source_mock.h"
namespace mongo {
namespace {
-using VectorClockConfigServerTest = ConfigServerTestFixture;
+class VectorClockConfigServerTest : public ConfigServerTestFixture {
+protected:
+ void setUp() override {
+ ConfigServerTestFixture::setUp();
+
+ auto clockSource = std::make_unique<ClockSourceMock>();
+ getServiceContext()->setFastClockSource(std::move(clockSource));
+
+ auto keysCollectionClient = std::make_unique<KeysCollectionClientSharded>(
+ Grid::get(operationContext())->catalogClient());
+
+ VectorClockMutable::get(getServiceContext())
+ ->tickTo(VectorClock::Component::ClusterTime, LogicalTime(Timestamp(1, 0)));
+
+ _keyManager = std::make_shared<KeysCollectionManager>(
+ "dummy", std::move(keysCollectionClient), Seconds(1000));
+ auto validator = std::make_unique<LogicalTimeValidator>(_keyManager);
+ validator->init(getServiceContext());
+ LogicalTimeValidator::set(getServiceContext(), std::move(validator));
+ }
+
+ void tearDown() override {
+ LogicalTimeValidator::get(getServiceContext())->shutDown();
+
+ ConfigServerTestFixture::tearDown();
+ }
+
+ /**
+ * Forces KeyManager to refresh cache and generate new keys.
+ */
+ void refreshKeyManager() {
+ _keyManager->refreshNow(operationContext());
+ }
+
+private:
+ std::shared_ptr<KeysCollectionManager> _keyManager;
+};
+
TEST_F(VectorClockConfigServerTest, TickClusterTime) {
auto sc = getGlobalServiceContext();
auto vc = VectorClockMutable::get(sc);
const auto t0 = vc->getTime();
- ASSERT_EQ(LogicalTime(), t0[VectorClock::Component::ClusterTime]);
+ ASSERT_EQ(LogicalTime(Timestamp(1, 0)), t0[VectorClock::Component::ClusterTime]);
const auto r1 = vc->tick(VectorClock::Component::ClusterTime, 1);
const auto t1 = vc->getTime();
@@ -57,6 +98,32 @@ TEST_F(VectorClockConfigServerTest, TickClusterTime) {
ASSERT_GT(t2[VectorClock::Component::ClusterTime], r1);
}
+TEST_F(VectorClockConfigServerTest, TickToClusterTime) {
+ auto sc = getGlobalServiceContext();
+ auto vc = VectorClockMutable::get(sc);
+
+ const auto t0 = vc->getTime();
+ ASSERT_EQ(LogicalTime(Timestamp(1, 0)), t0[VectorClock::Component::ClusterTime]);
+
+ vc->tickTo(VectorClock::Component::ClusterTime, LogicalTime(Timestamp(1, 1)));
+ const auto t1 = vc->getTime();
+ ASSERT_EQ(LogicalTime(Timestamp(1, 1)), t1[VectorClock::Component::ClusterTime]);
+
+ vc->tickTo(VectorClock::Component::ClusterTime, LogicalTime(Timestamp(3, 3)));
+ const auto t2 = vc->getTime();
+ ASSERT_EQ(LogicalTime(Timestamp(3, 3)), t2[VectorClock::Component::ClusterTime]);
+
+ vc->tickTo(VectorClock::Component::ClusterTime, LogicalTime(Timestamp(2, 2)));
+ const auto t3 = vc->getTime();
+ ASSERT_EQ(LogicalTime(Timestamp(3, 3)), t3[VectorClock::Component::ClusterTime]);
+}
+
+DEATH_TEST_F(VectorClockConfigServerTest, CannotTickConfigTime, "Hit a MONGO_UNREACHABLE") {
+ auto sc = getGlobalServiceContext();
+ auto vc = VectorClockMutable::get(sc);
+ vc->tick(VectorClock::Component::ConfigTime, 1);
+}
+
TEST_F(VectorClockConfigServerTest, TickToConfigTime) {
auto sc = getGlobalServiceContext();
auto vc = VectorClockMutable::get(sc);
@@ -77,38 +144,122 @@ TEST_F(VectorClockConfigServerTest, TickToConfigTime) {
ASSERT_EQ(LogicalTime(Timestamp(3, 3)), t3[VectorClock::Component::ConfigTime]);
}
-TEST_F(VectorClockConfigServerTest, GossipOutTest) {
- // TODO SERVER-47914: after ClusterTime gossiping has been re-enabled: get the gossipOut
- // internal and external, and for each check that $clusterTime and $configTime are there, with
- // the right format, and right value.
+TEST_F(VectorClockConfigServerTest, GossipOutInternal) {
+ auto sc = getGlobalServiceContext();
+ auto vc = VectorClockMutable::get(sc);
+
+ LogicalTimeValidator::get(getServiceContext())->enableKeyGenerator(operationContext(), true);
+ refreshKeyManager();
- // auto sc = getGlobalServiceContext();
- // auto vc = VectorClockMutable::get(sc);
+ const auto clusterTime = vc->tick(VectorClock::Component::ClusterTime, 1);
+ const auto configTime = LogicalTime(Timestamp(1, 0));
+ vc->tickTo(VectorClock::Component::ConfigTime, configTime);
- // const auto r1 = vc->tick(VectorClock::Component::ClusterTime, 1);
+ BSONObjBuilder bob;
+ vc->gossipOut(nullptr, &bob, transport::Session::kInternalClient);
+ auto obj = bob.obj();
+
+ // On config servers, gossip out to internal clients should have $clusterTime and $configTime.
+ ASSERT_TRUE(obj.hasField("$clusterTime"));
+ ASSERT_EQ(obj["$clusterTime"].Obj()["clusterTime"].timestamp(), clusterTime.asTimestamp());
+ ASSERT_TRUE(obj.hasField("$configTime"));
+ ASSERT_EQ(obj["$configTime"].timestamp(), configTime.asTimestamp());
}
-TEST_F(VectorClockConfigServerTest, GossipInTest) {
- // TODO SERVER-47914: after ClusterTime gossiping has been re-enabled: for each of gossipIn
- // internal and external, give it BSON in the correct format, and then check that ClusterTime
- // has been advanced (or not), ***and that ConfigTime has not***.
+TEST_F(VectorClockConfigServerTest, GossipOutExternal) {
+ auto sc = getGlobalServiceContext();
+ auto vc = VectorClockMutable::get(sc);
+
+ LogicalTimeValidator::get(getServiceContext())->enableKeyGenerator(operationContext(), true);
+ refreshKeyManager();
+
+ const auto clusterTime = vc->tick(VectorClock::Component::ClusterTime, 1);
+ const auto configTime = LogicalTime(Timestamp(1, 0));
+ vc->tickTo(VectorClock::Component::ConfigTime, configTime);
- // auto sc = getGlobalServiceContext();
- // auto vc = VectorClockMutable::get(sc);
+ BSONObjBuilder bob;
+ vc->gossipOut(nullptr, &bob);
+ auto obj = bob.obj();
- // const auto r1 = vc->tick(VectorClock::Component::ClusterTime, 1);
+ // On config servers, gossip out to external clients should have $clusterTime, but not
+ // $configTime.
+ ASSERT_TRUE(obj.hasField("$clusterTime"));
+ ASSERT_EQ(obj["$clusterTime"].Obj()["clusterTime"].timestamp(), clusterTime.asTimestamp());
+ ASSERT_FALSE(obj.hasField("$configTime"));
}
-DEATH_TEST_F(VectorClockConfigServerTest, CannotTickConfigTime, "Hit a MONGO_UNREACHABLE") {
+TEST_F(VectorClockConfigServerTest, GossipInInternal) {
auto sc = getGlobalServiceContext();
auto vc = VectorClockMutable::get(sc);
- vc->tick(VectorClock::Component::ConfigTime, 1);
+
+ vc->tick(VectorClock::Component::ClusterTime, 1);
+ const auto configTime = LogicalTime(Timestamp(1, 0));
+ vc->tickTo(VectorClock::Component::ConfigTime, configTime);
+
+ auto dummySignature =
+ BSON("hash" << BSONBinData("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1", 20, BinDataGeneral)
+ << "keyId" << 0);
+ vc->gossipIn(nullptr,
+ BSON("$clusterTime"
+ << BSON("clusterTime" << Timestamp(2, 2) << "signature" << dummySignature)
+ << "$configTime" << Timestamp(2, 2)),
+ false,
+ transport::Session::kInternalClient);
+
+ // On config servers, gossip in from internal clients should update $clusterTime, but not
+ // $configTime.
+ auto afterTime = vc->getTime();
+ ASSERT_EQ(afterTime[VectorClock::Component::ClusterTime].asTimestamp(), Timestamp(2, 2));
+ ASSERT_EQ(afterTime[VectorClock::Component::ConfigTime].asTimestamp(),
+ configTime.asTimestamp());
+
+ vc->gossipIn(nullptr,
+ BSON("$clusterTime"
+ << BSON("clusterTime" << Timestamp(1, 1) << "signature" << dummySignature)
+ << "$configTime" << Timestamp(1, 1)),
+ false,
+ transport::Session::kInternalClient);
+
+ auto afterTime2 = vc->getTime();
+ ASSERT_EQ(afterTime2[VectorClock::Component::ClusterTime].asTimestamp(), Timestamp(2, 2));
+ ASSERT_EQ(afterTime2[VectorClock::Component::ConfigTime].asTimestamp(),
+ configTime.asTimestamp());
}
-DEATH_TEST_F(VectorClockConfigServerTest, CannotTickToClusterTime, "Hit a MONGO_UNREACHABLE") {
+TEST_F(VectorClockConfigServerTest, GossipInExternal) {
auto sc = getGlobalServiceContext();
auto vc = VectorClockMutable::get(sc);
- vc->tickTo(VectorClock::Component::ClusterTime, LogicalTime());
+
+ vc->tick(VectorClock::Component::ClusterTime, 1);
+ const auto configTime = LogicalTime(Timestamp(1, 0));
+ vc->tickTo(VectorClock::Component::ConfigTime, configTime);
+
+ auto dummySignature =
+ BSON("hash" << BSONBinData("\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1\1", 20, BinDataGeneral)
+ << "keyId" << 0);
+ vc->gossipIn(nullptr,
+ BSON("$clusterTime"
+ << BSON("clusterTime" << Timestamp(2, 2) << "signature" << dummySignature)
+ << "$configTime" << Timestamp(2, 2)),
+ false);
+
+ // On config servers, gossip in from external clients should update $clusterTime, but not
+ // $configTime.
+ auto afterTime = vc->getTime();
+ ASSERT_EQ(afterTime[VectorClock::Component::ClusterTime].asTimestamp(), Timestamp(2, 2));
+ ASSERT_EQ(afterTime[VectorClock::Component::ConfigTime].asTimestamp(),
+ configTime.asTimestamp());
+
+ vc->gossipIn(nullptr,
+ BSON("$clusterTime"
+ << BSON("clusterTime" << Timestamp(1, 1) << "signature" << dummySignature)
+ << "$configTime" << Timestamp(1, 1)),
+ false);
+
+ auto afterTime2 = vc->getTime();
+ ASSERT_EQ(afterTime2[VectorClock::Component::ClusterTime].asTimestamp(), Timestamp(2, 2));
+ ASSERT_EQ(afterTime2[VectorClock::Component::ConfigTime].asTimestamp(),
+ configTime.asTimestamp());
}
} // namespace