summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorSpencer T Brody <spencer@10gen.com>2013-02-27 19:49:28 -0500
committerSpencer T Brody <spencer@10gen.com>2013-03-01 11:55:07 -0500
commite3eb91bedca694eda23c911ab860d803bf042bc0 (patch)
tree3fe191b740398739f8e1a2fbc5405d8292f7a757 /jstests
parent7e5a331e53569c1c4a239cf3a972bef3eef67afa (diff)
downloadmongo-e3eb91bedca694eda23c911ab860d803bf042bc0.tar.gz
SERVER-8769 Track inserts on mongos for serverStatus().opcounters
Diffstat (limited to 'jstests')
-rw-r--r--jstests/opcounters.js45
1 files changed, 45 insertions, 0 deletions
diff --git a/jstests/opcounters.js b/jstests/opcounters.js
new file mode 100644
index 00000000000..297fc0b79b5
--- /dev/null
+++ b/jstests/opcounters.js
@@ -0,0 +1,45 @@
+// Test that opcounters get incremented properly.
+
+db.dropDatabase();
+
+var original = db.serverStatus().opcounters;
+var current;
+
+printjson(original);
+
+// Command
+db.foo.count();
+current = db.serverStatus().opcounters;
+assert.eq(current.command, original.command + 2); // One for count one for serverStatus
+
+// Insert
+db.foo.insert({a:1});
+current = db.serverStatus().opcounters;
+assert.eq(current.insert, original.insert + 1);
+db.foo.insert([{a:2}, {a:3}]);
+current = db.serverStatus().opcounters;
+assert.eq(current.insert, original.insert + 3); // Batch-inserts should be counted as multiple inserts
+
+// Update
+db.foo.update({a:1}, {$set : {b:1}});
+current = db.serverStatus().opcounters;
+assert.eq(current.update, original.update + 1);
+db.foo.update({}, {$inc : {b:1}}, false, true);
+current = db.serverStatus().opcounters;
+assert.eq(current.update, original.update + 2); // Multi-updates are counted as 1 update
+
+// Query
+db.foo.findOne({a:1});
+current = db.serverStatus().opcounters;
+assert.eq(current.query, original.query + 1);
+db.foo.find().toArray();
+current = db.serverStatus().opcounters;
+assert.eq(current.query, original.query + 2);
+
+// Delete
+db.foo.remove({a:1});
+current = db.serverStatus().opcounters;
+assert.eq(current.delete, original.delete + 1);
+db.foo.remove({});
+current = db.serverStatus().opcounters;
+assert.eq(current.delete, original.delete + 2); // Multi-removes are counted as 1 remove