diff options
Diffstat (limited to 'src/mongo/s/catalog/type_chunk_test.cpp')
-rw-r--r-- | src/mongo/s/catalog/type_chunk_test.cpp | 123 |
1 files changed, 48 insertions, 75 deletions
diff --git a/src/mongo/s/catalog/type_chunk_test.cpp b/src/mongo/s/catalog/type_chunk_test.cpp index 5bc960179e1..49ae676b153 100644 --- a/src/mongo/s/catalog/type_chunk_test.cpp +++ b/src/mongo/s/catalog/type_chunk_test.cpp @@ -50,41 +50,32 @@ TEST(ChunkType, MissingConfigRequiredFields) { ChunkVersion chunkVersion(1, 2, OID::gen()); BSONObj objModNS = - BSON(ChunkType::name("test.mycol-a_MinKey") << ChunkType::min(BSON("a" << 10 << "b" << 10)) - << ChunkType::max(BSON("a" << 20)) - << "lastmod" - << Timestamp(chunkVersion.toLong()) - << "lastmodEpoch" - << chunkVersion.epoch() - << ChunkType::shard("shard0001")); + BSON(ChunkType::name("test.mycol-a_MinKey") + << ChunkType::min(BSON("a" << 10 << "b" << 10)) << ChunkType::max(BSON("a" << 20)) + << "lastmod" << Timestamp(chunkVersion.toLong()) << "lastmodEpoch" + << chunkVersion.epoch() << ChunkType::shard("shard0001")); StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(objModNS); ASSERT_FALSE(chunkRes.isOK()); BSONObj objModKeys = - BSON(ChunkType::name("test.mycol-a_MinKey") << ChunkType::ns("test.mycol") << "lastmod" - << Timestamp(chunkVersion.toLong()) - << "lastmodEpoch" - << chunkVersion.epoch() - << ChunkType::shard("shard0001")); + BSON(ChunkType::name("test.mycol-a_MinKey") + << ChunkType::ns("test.mycol") << "lastmod" << Timestamp(chunkVersion.toLong()) + << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001")); chunkRes = ChunkType::fromConfigBSON(objModKeys); ASSERT_FALSE(chunkRes.isOK()); BSONObj objModShard = - BSON(ChunkType::name("test.mycol-a_MinKey") << ChunkType::ns("test.mycol") - << ChunkType::min(BSON("a" << 10 << "b" << 10)) - << ChunkType::max(BSON("a" << 20)) - << "lastmod" - << Timestamp(chunkVersion.toLong()) - << "lastmodEpoch" - << chunkVersion.epoch()); + BSON(ChunkType::name("test.mycol-a_MinKey") + << ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 10 << "b" << 10)) + << ChunkType::max(BSON("a" << 20)) << "lastmod" << Timestamp(chunkVersion.toLong()) + << "lastmodEpoch" << chunkVersion.epoch()); chunkRes = ChunkType::fromConfigBSON(objModShard); ASSERT_FALSE(chunkRes.isOK()); BSONObj objModVersion = - BSON(ChunkType::name("test.mycol-a_MinKey") << ChunkType::ns("test.mycol") - << ChunkType::min(BSON("a" << 10 << "b" << 10)) - << ChunkType::max(BSON("a" << 20)) - << ChunkType::shard("shard0001")); + BSON(ChunkType::name("test.mycol-a_MinKey") + << ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 10 << "b" << 10)) + << ChunkType::max(BSON("a" << 20)) << ChunkType::shard("shard0001")); chunkRes = ChunkType::fromConfigBSON(objModVersion); ASSERT_FALSE(chunkRes.isOK()); } @@ -100,8 +91,8 @@ TEST(ChunkType, MissingShardRequiredFields) { ASSERT_EQUALS(chunkRes.getStatus(), ErrorCodes::NoSuchKey); ASSERT_STRING_CONTAINS(chunkRes.getStatus().reason(), ChunkType::minShardID.name()); - BSONObj objModMax = BSON( - ChunkType::minShardID(kMin) << ChunkType::shard(kShard.toString()) << "lastmod" << lastmod); + BSONObj objModMax = BSON(ChunkType::minShardID(kMin) + << ChunkType::shard(kShard.toString()) << "lastmod" << lastmod); chunkRes = ChunkType::fromShardBSON(objModMax, epoch); ASSERT_EQUALS(chunkRes.getStatus(), ErrorCodes::NoSuchKey); ASSERT_STRING_CONTAINS(chunkRes.getStatus().reason(), ChunkType::max.name()); @@ -112,8 +103,8 @@ TEST(ChunkType, MissingShardRequiredFields) { ASSERT_EQUALS(chunkRes.getStatus(), ErrorCodes::NoSuchKey); ASSERT_STRING_CONTAINS(chunkRes.getStatus().reason(), ChunkType::shard.name()); - BSONObj objModLastmod = BSON( - ChunkType::minShardID(kMin) << ChunkType::max(kMax) << ChunkType::shard(kShard.toString())); + BSONObj objModLastmod = BSON(ChunkType::minShardID(kMin) + << ChunkType::max(kMax) << ChunkType::shard(kShard.toString())); chunkRes = ChunkType::fromShardBSON(objModLastmod, epoch); ASSERT_EQUALS(chunkRes.getStatus(), ErrorCodes::NoSuchKey); } @@ -123,10 +114,9 @@ TEST(ChunkType, ToFromShardBSON) { ChunkVersion chunkVersion(1, 2, epoch); auto lastmod = Timestamp(chunkVersion.toLong()); - BSONObj obj = BSON(ChunkType::minShardID(kMin) << ChunkType::max(kMax) - << ChunkType::shard(kShard.toString()) - << "lastmod" - << lastmod); + BSONObj obj = BSON(ChunkType::minShardID(kMin) + << ChunkType::max(kMax) << ChunkType::shard(kShard.toString()) << "lastmod" + << lastmod); ChunkType shardChunk = assertGet(ChunkType::fromShardBSON(obj, epoch)); ASSERT_BSONOBJ_EQ(obj, shardChunk.toShardBSON()); @@ -140,14 +130,10 @@ TEST(ChunkType, ToFromShardBSON) { TEST(ChunkType, MinAndMaxShardKeysDifferInNumberOfKeys) { ChunkVersion chunkVersion(1, 2, OID::gen()); BSONObj obj = - BSON(ChunkType::name("test.mycol-a_MinKey") << ChunkType::ns("test.mycol") - << ChunkType::min(BSON("a" << 10 << "b" << 10)) - << ChunkType::max(BSON("a" << 20)) - << "lastmod" - << Timestamp(chunkVersion.toLong()) - << "lastmodEpoch" - << chunkVersion.epoch() - << ChunkType::shard("shard0001")); + BSON(ChunkType::name("test.mycol-a_MinKey") + << ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 10 << "b" << 10)) + << ChunkType::max(BSON("a" << 20)) << "lastmod" << Timestamp(chunkVersion.toLong()) + << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001")); StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj); ASSERT_OK(chunkRes.getStatus()); ASSERT_FALSE(chunkRes.getValue().validate().isOK()); @@ -155,14 +141,11 @@ TEST(ChunkType, MinAndMaxShardKeysDifferInNumberOfKeys) { TEST(ChunkType, MinAndMaxShardKeysDifferInKeyNames) { ChunkVersion chunkVersion(1, 2, OID::gen()); - BSONObj obj = BSON(ChunkType::name("test.mycol-a_MinKey") << ChunkType::ns("test.mycol") - << ChunkType::min(BSON("a" << 10)) - << ChunkType::max(BSON("b" << 20)) - << "lastmod" - << Timestamp(chunkVersion.toLong()) - << "lastmodEpoch" - << chunkVersion.epoch() - << ChunkType::shard("shard0001")); + BSONObj obj = + BSON(ChunkType::name("test.mycol-a_MinKey") + << ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 10)) + << ChunkType::max(BSON("b" << 20)) << "lastmod" << Timestamp(chunkVersion.toLong()) + << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001")); StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj); ASSERT_OK(chunkRes.getStatus()); ASSERT_FALSE(chunkRes.getValue().validate().isOK()); @@ -170,28 +153,22 @@ TEST(ChunkType, MinAndMaxShardKeysDifferInKeyNames) { TEST(ChunkType, MinToMaxNotAscending) { ChunkVersion chunkVersion(1, 2, OID::gen()); - BSONObj obj = BSON(ChunkType::name("test.mycol-a_MinKey") << ChunkType::ns("test.mycol") - << ChunkType::min(BSON("a" << 20)) - << ChunkType::max(BSON("a" << 10)) - << "lastmod" - << Timestamp(chunkVersion.toLong()) - << "lastmodEpoch" - << chunkVersion.epoch() - << ChunkType::shard("shard0001")); + BSONObj obj = + BSON(ChunkType::name("test.mycol-a_MinKey") + << ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 20)) + << ChunkType::max(BSON("a" << 10)) << "lastmod" << Timestamp(chunkVersion.toLong()) + << "lastmodEpoch" << chunkVersion.epoch() << ChunkType::shard("shard0001")); StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj); ASSERT_EQ(ErrorCodes::FailedToParse, chunkRes.getStatus()); } TEST(ChunkType, ToFromConfigBSON) { ChunkVersion chunkVersion(1, 2, OID::gen()); - BSONObj obj = BSON(ChunkType::name("test.mycol-a_10") << ChunkType::ns("test.mycol") - << ChunkType::min(BSON("a" << 10)) - << ChunkType::max(BSON("a" << 20)) - << ChunkType::shard("shard0001") - << "lastmod" - << Timestamp(chunkVersion.toLong()) - << "lastmodEpoch" - << chunkVersion.epoch()); + BSONObj obj = + BSON(ChunkType::name("test.mycol-a_10") + << ChunkType::ns("test.mycol") << ChunkType::min(BSON("a" << 10)) + << ChunkType::max(BSON("a" << 20)) << ChunkType::shard("shard0001") << "lastmod" + << Timestamp(chunkVersion.toLong()) << "lastmodEpoch" << chunkVersion.epoch()); StatusWith<ChunkType> chunkRes = ChunkType::fromConfigBSON(obj); ASSERT_OK(chunkRes.getStatus()); ChunkType chunk = chunkRes.getValue(); @@ -208,18 +185,14 @@ TEST(ChunkType, ToFromConfigBSON) { } TEST(ChunkType, Pre22Format) { - ChunkType chunk = assertGet(ChunkType::fromConfigBSON(BSON("_id" - << "test.mycol-a_MinKey" - << "lastmod" - << Date_t::fromMillisSinceEpoch(1) - << "ns" - << "test.mycol" - << "min" - << BSON("a" << 10) - << "max" - << BSON("a" << 20) - << "shard" - << "shard0001"))); + ChunkType chunk = assertGet( + ChunkType::fromConfigBSON(BSON("_id" + << "test.mycol-a_MinKey" + << "lastmod" << Date_t::fromMillisSinceEpoch(1) << "ns" + << "test.mycol" + << "min" << BSON("a" << 10) << "max" << BSON("a" << 20) + << "shard" + << "shard0001"))); ASSERT_OK(chunk.validate()); ASSERT_EQUALS(chunk.getNS().ns(), "test.mycol"); |