summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorScott Hernandez <scotthernandez@gmail.com>2013-01-22 13:53:52 -0500
committerDan Pasette <dan@10gen.com>2013-01-22 16:10:18 -0500
commitededb03f2104f37cdb376e0f17a4d53b87f05cdf (patch)
tree8797c3f19c5283b5a2ea5de8bb9b91fcd6447fee /jstests
parent5c2f3da947dc5e7c5fec9561d315f51101467a1d (diff)
downloadmongo-ededb03f2104f37cdb376e0f17a4d53b87f05cdf.tar.gz
SERVER-8117: listDatabases - config/admin db should come from config servers
Diffstat (limited to 'jstests')
-rw-r--r--jstests/sharding/listDatabases.js46
1 files changed, 46 insertions, 0 deletions
diff --git a/jstests/sharding/listDatabases.js b/jstests/sharding/listDatabases.js
new file mode 100644
index 00000000000..e32ab5ab82b
--- /dev/null
+++ b/jstests/sharding/listDatabases.js
@@ -0,0 +1,46 @@
+// tests that listDatabases doesn't show config db on a shard, even if it is there
+
+var test = new ShardingTest({shards: 1, mongos: 1, config: 1, other: {chunksize:1, separateConfig:true}})
+
+var mongos = test.s0
+var mongod = test.shard0;
+
+//grab the config db instance by name
+var getDBSection = function (dbsArray, dbToFind) {
+ for(var pos in dbsArray) {
+ if (dbsArray[pos].name && dbsArray[pos].name === dbToFind)
+ return dbsArray[pos];
+ }
+ return null;
+}
+
+mongos.getDB("blah").foo.insert({_id:1})
+mongos.getDB("foo").foo.insert({_id:1})
+mongos.getDB("raw").foo.insert({_id:1})
+//wait for writes to finish
+mongos.getDB("raw").getLastError()
+
+//verify that the config db is not on a shard
+var res = mongos.adminCommand("listDatabases");
+var dbArray = res.databases;
+assert(getDBSection(dbArray, "config"), "config db not found! 1")
+assert(!getDBSection(dbArray, "config").shards, "config db is on a shard! 1")
+
+//add doc in config/admin db on the shard
+mongod.getDB("config").foo.insert({_id:1})
+mongod.getDB("admin").foo.insert({_id:1})
+
+//add doc in admin db (via mongos)
+mongos.getDB("admin").foo.insert({_id:1})
+
+//verify that the config db is not on a shard
+var res = mongos.adminCommand("listDatabases");
+var dbArray = res.databases;
+//check config db
+assert(getDBSection(dbArray, "config"), "config db not found! 2")
+assert(!getDBSection(dbArray, "config").shards, "config db is on a shard! 2")
+//check admin db
+assert(getDBSection(dbArray, "admin"), "admin db not found! 2")
+assert(!getDBSection(dbArray, "admin").shards, "admin db is on a shard! 2")
+
+test.stop() \ No newline at end of file