summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorDan Pasette <dan@10gen.com>2015-03-09 17:34:54 -0400
committerDan Pasette <dan@mongodb.com>2015-03-09 23:58:33 -0400
commitaa0d74203b5fcc43425e08af12cf27542be7c10a (patch)
tree31e53fdb03c4dd2e3175b055810b71686ece7c75 /jstests
parent95d9052efa2111bd1dc902122ff8d2817c08f0e8 (diff)
downloadmongo-aa0d74203b5fcc43425e08af12cf27542be7c10a.tar.gz
SERVER-17515 fixed namespace in oplog entry when using the cloner to copy indexes
(cherry picked from commit 8e6d7dc39c51c58d0158071a717113314c26b0a0)
Diffstat (limited to 'jstests')
-rw-r--r--jstests/replsets/copydb.js68
1 files changed, 68 insertions, 0 deletions
diff --git a/jstests/replsets/copydb.js b/jstests/replsets/copydb.js
new file mode 100644
index 00000000000..d3df7de08c2
--- /dev/null
+++ b/jstests/replsets/copydb.js
@@ -0,0 +1,68 @@
+// Tests the copydb command in a replica set.
+// Ensures that documents and indexes are replicated to secondary.
+
+(function() {
+ 'use strict';
+
+ var replTest = new ReplSetTest({name: 'copydbTest', nodes: 3});
+
+ replTest.startSet();
+ replTest.initiate();
+ var primary = replTest.getMaster();
+ var secondary = replTest.liveNodes.slaves[0];
+
+ var sourceDBName = 'copydb-repl-test-source';
+ var targetDBName = 'copydb-repl-test-target';
+
+ var primarySourceDB = primary.getDB(sourceDBName);
+ assert.commandWorked(primarySourceDB.dropDatabase(),
+ 'failed to drop source database ' + sourceDBName + ' on primary');
+
+ var primaryTargetDB = primary.getDB(targetDBName);
+ assert.commandWorked(primaryTargetDB.dropDatabase(),
+ 'failed to drop target database ' + targetDBName + ' on primary');
+
+ assert.writeOK(primarySourceDB.foo.save({a: 1}),
+ 'failed to insert document in source collection');
+ assert.commandWorked(primarySourceDB.foo.ensureIndex({a: 1}),
+ 'failed to create index in source collection on primary');
+
+ assert.eq(1, primarySourceDB.foo.find().itcount(),
+ 'incorrect number of documents in source collection on primary before copy');
+ assert.eq(0, primaryTargetDB.foo.find().itcount(),
+ 'target collection on primary should be empty before copy');
+
+ assert.commandWorked(primarySourceDB.copyDatabase(primarySourceDB.getName(),
+ primaryTargetDB.getName()),
+ 'failed to copy database');
+
+ assert.eq(primarySourceDB.foo.find().itcount(),
+ primaryTargetDB.foo.find().itcount(),
+ 'incorrect number of documents in target collection on primary after copy');
+
+ assert.eq(primarySourceDB.foo.getIndexes().length,
+ primaryTargetDB.foo.getIndexes().length,
+ 'incorrect number of indexes in target collection on primary after copy');
+
+ replTest.awaitReplication();
+
+ var secondarySourceDB = secondary.getDB(sourceDBName);
+
+ assert.eq(primarySourceDB.foo.find().itcount(),
+ secondarySourceDB.foo.find().itcount(),
+ 'incorrect number of documents in source collection on secondary after copy');
+
+ assert.eq(primarySourceDB.foo.getIndexes().length,
+ secondarySourceDB.foo.getIndexes().length,
+ 'incorrect number of indexes in source collection on secondary after copy');
+
+ var secondaryTargetDB = secondary.getDB(targetDBName);
+
+ assert.eq(primaryTargetDB.foo.find().itcount(),
+ secondaryTargetDB.foo.find().itcount(),
+ 'incorrect number of documents in target collection on secondary after copy');
+
+ assert.eq(primaryTargetDB.foo.getIndexes().length,
+ secondaryTargetDB.foo.getIndexes().length,
+ 'incorrect number of indexes in target collection on secondary after copy');
+}()); \ No newline at end of file