diff options
Diffstat (limited to 'src/mongo/s/type_config_version_test.cpp')
-rw-r--r-- | src/mongo/s/type_config_version_test.cpp | 252 |
1 files changed, 124 insertions, 128 deletions
diff --git a/src/mongo/s/type_config_version_test.cpp b/src/mongo/s/type_config_version_test.cpp index 6c4c8ea6a3a..618238402b9 100644 --- a/src/mongo/s/type_config_version_test.cpp +++ b/src/mongo/s/type_config_version_test.cpp @@ -37,131 +37,127 @@ namespace { - using std::string; - using mongo::VersionType; - using mongo::BSONObj; - using mongo::BSONArray; - using mongo::BSONObjBuilder; - using mongo::BSONArrayBuilder; - using mongo::OID; - - TEST(Validity, Empty) { - - // - // Tests parsing of empty document - // - - VersionType versionInfo; - BSONObj emptyObj = BSONObj(); - - // parses ok - string errMsg; - bool result = versionInfo.parseBSON(emptyObj, &errMsg); - ASSERT_EQUALS(errMsg, ""); - ASSERT(result); - - // not valid - result = versionInfo.isValid(&errMsg); - ASSERT_NOT_EQUALS(errMsg, ""); - ASSERT(!result); - } - - TEST(Validity, NewVersion) { - - // - // Tests parsing a new-style config version - // - - VersionType versionInfo; - - OID clusterId = OID::gen(); - - BSONObjBuilder bob; - bob << VersionType::minCompatibleVersion(3); - bob << VersionType::currentVersion(4); - bob << VersionType::clusterId(clusterId); - - BSONObj versionDoc = bob.obj(); - - string errMsg; - bool result = versionInfo.parseBSON(versionDoc, &errMsg); - ASSERT_EQUALS(errMsg, ""); - ASSERT(result); - ASSERT_EQUALS(versionInfo.getMinCompatibleVersion(), 3); - ASSERT_EQUALS(versionInfo.getCurrentVersion(), 4); - ASSERT_EQUALS(versionInfo.getClusterId(), clusterId); - - // Valid - result = versionInfo.isValid(&errMsg); - ASSERT_EQUALS(errMsg, ""); - ASSERT(result); - } - - TEST(Validity, NewVersionRoundTrip) { - - // - // Round-trip - // - - VersionType versionInfo; - - OID clusterId = OID::gen(); - OID upgradeId = OID::gen(); - BSONObj upgradeState = BSON("a" << 1); - - BSONObjBuilder bob; - bob << VersionType::minCompatibleVersion(3); - bob << VersionType::currentVersion(4); - bob << VersionType::clusterId(clusterId); - bob << VersionType::upgradeId(upgradeId); - bob << VersionType::upgradeState(upgradeState); - - BSONObj versionDoc = bob.obj(); - - string errMsg; - bool result = versionInfo.parseBSON(versionDoc, &errMsg); - ASSERT_EQUALS(errMsg, ""); - ASSERT(result); - - result = versionInfo.parseBSON(versionInfo.toBSON(), &errMsg); - ASSERT_EQUALS(errMsg, ""); - ASSERT(result); - ASSERT_EQUALS(versionInfo.getMinCompatibleVersion(), 3); - ASSERT_EQUALS(versionInfo.getCurrentVersion(), 4); - ASSERT_EQUALS(versionInfo.getClusterId(), clusterId); - ASSERT_EQUALS(versionInfo.getUpgradeId(), upgradeId); - ASSERT_EQUALS(versionInfo.getUpgradeState(), upgradeState); - - // Valid - result = versionInfo.isValid(&errMsg); - ASSERT_EQUALS(errMsg, ""); - ASSERT(result); - } - - TEST(Validity, NewVersionNoClusterId) { - - // - // Tests error on parsing new format with no clusterId - // - - VersionType versionInfo; - - BSONObjBuilder bob; - bob << VersionType::minCompatibleVersion(3); - bob << VersionType::currentVersion(4); - - BSONObj versionDoc = bob.obj(); - - // Parses ok - string errMsg; - bool result = versionInfo.parseBSON(versionDoc, &errMsg); - ASSERT_EQUALS(errMsg, ""); - ASSERT(result); - - // Not valid - result = versionInfo.isValid(&errMsg); - ASSERT_NOT_EQUALS(errMsg, ""); - ASSERT(!result); - } - -} // unnamed namespace +using std::string; +using mongo::VersionType; +using mongo::BSONObj; +using mongo::BSONArray; +using mongo::BSONObjBuilder; +using mongo::BSONArrayBuilder; +using mongo::OID; + +TEST(Validity, Empty) { + // + // Tests parsing of empty document + // + + VersionType versionInfo; + BSONObj emptyObj = BSONObj(); + + // parses ok + string errMsg; + bool result = versionInfo.parseBSON(emptyObj, &errMsg); + ASSERT_EQUALS(errMsg, ""); + ASSERT(result); + + // not valid + result = versionInfo.isValid(&errMsg); + ASSERT_NOT_EQUALS(errMsg, ""); + ASSERT(!result); +} + +TEST(Validity, NewVersion) { + // + // Tests parsing a new-style config version + // + + VersionType versionInfo; + + OID clusterId = OID::gen(); + + BSONObjBuilder bob; + bob << VersionType::minCompatibleVersion(3); + bob << VersionType::currentVersion(4); + bob << VersionType::clusterId(clusterId); + + BSONObj versionDoc = bob.obj(); + + string errMsg; + bool result = versionInfo.parseBSON(versionDoc, &errMsg); + ASSERT_EQUALS(errMsg, ""); + ASSERT(result); + ASSERT_EQUALS(versionInfo.getMinCompatibleVersion(), 3); + ASSERT_EQUALS(versionInfo.getCurrentVersion(), 4); + ASSERT_EQUALS(versionInfo.getClusterId(), clusterId); + + // Valid + result = versionInfo.isValid(&errMsg); + ASSERT_EQUALS(errMsg, ""); + ASSERT(result); +} + +TEST(Validity, NewVersionRoundTrip) { + // + // Round-trip + // + + VersionType versionInfo; + + OID clusterId = OID::gen(); + OID upgradeId = OID::gen(); + BSONObj upgradeState = BSON("a" << 1); + + BSONObjBuilder bob; + bob << VersionType::minCompatibleVersion(3); + bob << VersionType::currentVersion(4); + bob << VersionType::clusterId(clusterId); + bob << VersionType::upgradeId(upgradeId); + bob << VersionType::upgradeState(upgradeState); + + BSONObj versionDoc = bob.obj(); + + string errMsg; + bool result = versionInfo.parseBSON(versionDoc, &errMsg); + ASSERT_EQUALS(errMsg, ""); + ASSERT(result); + + result = versionInfo.parseBSON(versionInfo.toBSON(), &errMsg); + ASSERT_EQUALS(errMsg, ""); + ASSERT(result); + ASSERT_EQUALS(versionInfo.getMinCompatibleVersion(), 3); + ASSERT_EQUALS(versionInfo.getCurrentVersion(), 4); + ASSERT_EQUALS(versionInfo.getClusterId(), clusterId); + ASSERT_EQUALS(versionInfo.getUpgradeId(), upgradeId); + ASSERT_EQUALS(versionInfo.getUpgradeState(), upgradeState); + + // Valid + result = versionInfo.isValid(&errMsg); + ASSERT_EQUALS(errMsg, ""); + ASSERT(result); +} + +TEST(Validity, NewVersionNoClusterId) { + // + // Tests error on parsing new format with no clusterId + // + + VersionType versionInfo; + + BSONObjBuilder bob; + bob << VersionType::minCompatibleVersion(3); + bob << VersionType::currentVersion(4); + + BSONObj versionDoc = bob.obj(); + + // Parses ok + string errMsg; + bool result = versionInfo.parseBSON(versionDoc, &errMsg); + ASSERT_EQUALS(errMsg, ""); + ASSERT(result); + + // Not valid + result = versionInfo.isValid(&errMsg); + ASSERT_NOT_EQUALS(errMsg, ""); + ASSERT(!result); +} + +} // unnamed namespace |