diff options
author | Pol Pinol Castuera <pol.castuera@mongodb.com> | 2022-09-08 13:38:31 +0000 |
---|---|---|
committer | Evergreen Agent <no-reply@evergreen.mongodb.com> | 2022-09-08 15:08:01 +0000 |
commit | a1e564b5da7107c5a21f53bbb2cae838709f0977 (patch) | |
tree | 6fc326b6d18d53d76e32e25f04995496f6153547 /jstests/sharding/all_collection_stats.js | |
parent | ad4a7ae485fd0189542e59b3350e798b42b42d1b (diff) | |
download | mongo-a1e564b5da7107c5a21f53bbb2cae838709f0977.tar.gz |
SERVER-67891 New design with $lookup
Diffstat (limited to 'jstests/sharding/all_collection_stats.js')
-rw-r--r-- | jstests/sharding/all_collection_stats.js | 73 |
1 files changed, 73 insertions, 0 deletions
diff --git a/jstests/sharding/all_collection_stats.js b/jstests/sharding/all_collection_stats.js new file mode 100644 index 00000000000..76018cb4b58 --- /dev/null +++ b/jstests/sharding/all_collection_stats.js @@ -0,0 +1,73 @@ +/* + * Test to validate the $_internalAllCollectionStats stage. + * + * @tags: [ + * requires_fcv_62, + * ] + */ + +(function() { +'use strict'; + +// Configure initial sharding cluster +const st = new ShardingTest({shards: 2}); +const mongos = st.s; + +const dbName = "test"; +const testDb = mongos.getDB(dbName); +const adminDb = mongos.getDB("admin"); + +// Insert sharded collections to validate the aggregation stage +for (let i = 0; i < 10; i++) { + const coll = "coll" + i; + assert(st.adminCommand({shardcollection: dbName + "." + coll, key: {skey: 1}})); + assert.commandWorked(testDb.getCollection(coll).insert({skey: i})); +} + +// Insert some unsharded collections to validate the aggregation stage +for (let i = 10; i < 20; i++) { + const coll = "coll" + i; + assert.commandWorked(testDb.getCollection(coll).insert({skey: i})); +} + +// Get output data +const outputData = adminDb.aggregate([{$_internalAllCollectionStats: {}}]).toArray(); +assert.gte(outputData.length, 20); + +// Testing for comparing each collection returned from $_internalAllCollectionStats to $collStats +for (let i = 0; i < 20; i++) { + const coll = "coll" + i; + const expectedResults = + testDb.getCollection(coll).aggregate([{$collStats: {storageStats: {}}}]).toArray(); + assert.neq(null, expectedResults); + assert.eq(expectedResults.length, 1); + + let exists = false; + for (const data of outputData) { + const ns = data.ns; + if (dbName + "." + coll === ns) { + assert.eq(data.host, expectedResults[0].host); + assert.eq(data.shard, expectedResults[0].shard); + assert.eq(tojson(data.storageStats), tojson(expectedResults[0].storageStats)); + exists = true; + break; + } + } + + assert(exists); +} + +// Test invalid queries/values. +assert.commandFailedWithCode( + adminDb.runCommand({aggregate: 1, pipeline: [{$_internalAllCollectionStats: 3}], cursor: {}}), + 6789103); + +const response = assert.commandFailedWithCode( + testDb.runCommand( + {aggregate: "foo", pipeline: [{$_internalAllCollectionStats: {}}], cursor: {}}), + 6789104); +assert.neq(-1, response.errmsg.indexOf("$_internalAllCollectionStats"), response.errmsg); +assert.neq(-1, response.errmsg.indexOf("admin database"), response.errmsg); + +st.stop(); +})(); |