diff options
author | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-06-10 16:54:56 -0400 |
---|---|---|
committer | Kaloian Manassiev <kaloian.manassiev@mongodb.com> | 2016-06-13 15:19:43 -0400 |
commit | 97ad19ed5bc71835e9783b932411b0ea9f83d572 (patch) | |
tree | 2e58cfdd0f5f17b567aec956d7d2e69bbf3fbeb0 /src/mongo/client | |
parent | 6b6cd6727d262d5db5e4f226e4da0d2bc410a4d8 (diff) | |
download | mongo-97ad19ed5bc71835e9783b932411b0ea9f83d572.tar.gz |
SERVER-24467 Make MoveChunkRequest and dependencies comparable
This change implements the '==' operator on MoveChunkRequest and any
dependent classes which do not have it.
Diffstat (limited to 'src/mongo/client')
-rw-r--r-- | src/mongo/client/connection_string.cpp | 9 | ||||
-rw-r--r-- | src/mongo/client/connection_string.h | 10 | ||||
-rw-r--r-- | src/mongo/client/connection_string_test.cpp | 29 |
3 files changed, 29 insertions, 19 deletions
diff --git a/src/mongo/client/connection_string.cpp b/src/mongo/client/connection_string.cpp index 5b7f87c8e02..16a6e78440d 100644 --- a/src/mongo/client/connection_string.cpp +++ b/src/mongo/client/connection_string.cpp @@ -164,8 +164,7 @@ void ConnectionString::_finishInit() { _string = ss.str(); } -// TODO: SERVER-23014 -bool ConnectionString::sameLogicalEndpoint(const ConnectionString& other) const { +bool ConnectionString::operator==(const ConnectionString& other) const { if (_type != other._type) { return false; } @@ -176,7 +175,7 @@ bool ConnectionString::sameLogicalEndpoint(const ConnectionString& other) const case MASTER: return _servers[0] == other._servers[0]; case SET: - return _setName == other._setName; + return _setName == other._setName && _servers == other._servers; case CUSTOM: return _string == other._string; case LOCAL: @@ -186,6 +185,10 @@ bool ConnectionString::sameLogicalEndpoint(const ConnectionString& other) const MONGO_UNREACHABLE; } +bool ConnectionString::operator!=(const ConnectionString& other) const { + return !(*this == other); +} + StatusWith<ConnectionString> ConnectionString::parse(const std::string& url) { const std::string::size_type i = url.find('/'); diff --git a/src/mongo/client/connection_string.h b/src/mongo/client/connection_string.h index f6b5ef419ec..91836e36812 100644 --- a/src/mongo/client/connection_string.h +++ b/src/mongo/client/connection_string.h @@ -110,12 +110,11 @@ public: } /** - * This returns true if this and other point to the same logical entity. - * For single nodes, thats the same address. - * For replica sets, thats just the same replica set name. - * For pair (deprecated) or sync cluster connections, that's the same hosts in any ordering. + * Returns true if two connection strings match in terms of their type and the exact order of + * their hosts. */ - bool sameLogicalEndpoint(const ConnectionString& other) const; + bool operator==(const ConnectionString& other) const; + bool operator!=(const ConnectionString& other) const; DBClientBase* connect(std::string& errmsg, double socketTimeout = 0) const; @@ -165,7 +164,6 @@ private: */ explicit ConnectionString(ConnectionType connType); - void _fillServers(std::string s); void _finishInit(); diff --git a/src/mongo/client/connection_string_test.cpp b/src/mongo/client/connection_string_test.cpp index 655ff17c207..7592cc2c115 100644 --- a/src/mongo/client/connection_string_test.cpp +++ b/src/mongo/client/connection_string_test.cpp @@ -32,19 +32,28 @@ #include "mongo/unittest/unittest.h" +namespace mongo { namespace { -using namespace mongo; -/* - TODO: SERVER-23014 SYNC is gone but this can be a good check for equality -TEST(ConnectionString, EqualitySync) { - ConnectionString cs(ConnectionString::SYNC, "a,b,c", ""); +using unittest::assertGet; - ASSERT(cs.sameLogicalEndpoint(ConnectionString(ConnectionString::SYNC, "a,b,c", ""))); - ASSERT(cs.sameLogicalEndpoint(ConnectionString(ConnectionString::SYNC, "c,b,a", ""))); - ASSERT(cs.sameLogicalEndpoint(ConnectionString(ConnectionString::SYNC, "c,a,b", ""))); +TEST(ConnectionString, EqualityOperatorMaster) { + const auto cs = assertGet(ConnectionString::parse("TestHostA:12345")); + ASSERT(cs == assertGet(ConnectionString::parse("TestHostA:12345"))); + ASSERT_FALSE(cs != assertGet(ConnectionString::parse("TestHostA:12345"))); + ASSERT(cs != assertGet(ConnectionString::parse("TestHostB:12345"))); + ASSERT_FALSE(cs == assertGet(ConnectionString::parse("TestHostB:12345"))); +} - ASSERT(!cs.sameLogicalEndpoint(ConnectionString(ConnectionString::SYNC, "d,a,b", ""))); +TEST(ConnectionString, EqualityOperatorReplicaSet) { + const auto cs = assertGet(ConnectionString::parse("TestRS/TestHostA:12345,TestHostB:12345")); + ASSERT(cs == assertGet(ConnectionString::parse("TestRS/TestHostA:12345,TestHostB:12345"))); + ASSERT_FALSE(cs == assertGet(ConnectionString::parse("TestHostA:12345"))); + ASSERT_FALSE(cs == + assertGet(ConnectionString::parse("TestRS/TestHostB:12345,TestHostA:12345"))); + ASSERT_FALSE(cs == + assertGet(ConnectionString::parse("TestRS1/TestHostA:12345,TestHostB:12345"))); } -*/ + } // namespace +} // namespace mongo |