summaryrefslogtreecommitdiff
path: root/jstests
diff options
context:
space:
mode:
authorScott Hernandez <scotthernandez@gmail.com>2014-02-14 17:45:54 -0500
committerScott Hernandez <scotthernandez@gmail.com>2014-02-17 21:51:24 -0500
commitcddc7d0b797cbba7ee02481396414f003fd2c962 (patch)
tree339b7eecdcec41e07a22d54659cdfe01eb146558 /jstests
parent2850cc7253344c639bc9a01bc6dff3ffd2cca422 (diff)
downloadmongo-cddc7d0b797cbba7ee02481396414f003fd2c962.tar.gz
SERVER-12702: add writeconcern operation option
Diffstat (limited to 'jstests')
-rw-r--r--jstests/shell_writeconcern.js70
1 files changed, 70 insertions, 0 deletions
diff --git a/jstests/shell_writeconcern.js b/jstests/shell_writeconcern.js
new file mode 100644
index 00000000000..bd2d86dd2c6
--- /dev/null
+++ b/jstests/shell_writeconcern.js
@@ -0,0 +1,70 @@
+"use strict"
+// check that shell writeconcern work correctly
+// 1.) tests that it can be set on each level and is inherited
+// 2.) tests that each operation (update/insert/remove/save) take and ensure a write concern
+
+var collA = db.shell_wc_a;
+var collB = db.shell_wc_b;
+
+// test inheritance
+db.setWriteConcern({w:1})
+assert.eq(1, db.getWriteConcern().toJSON().w)
+assert.eq(1, collB.getWriteConcern().toJSON().w)
+
+collA.setWriteConcern({w:2})
+assert.eq(2, collA.getWriteConcern().toJSON().w)
+collA.unsetWriteConcern()
+assert.eq(1, collA.getWriteConcern().toJSON().w)
+
+db.unsetWriteConcern()
+assert.eq(undefined, collA.getWriteConcern())
+assert.eq(undefined, collB.getWriteConcern())
+assert.eq(undefined, db.getWriteConcern())
+
+// test methods, by generating an error
+var res = assert.writeOK(collA.save({_id:1}, {writeConcern:{w:1}}));
+if (!db.getMongo().useWriteCommands() ) {
+ assert.eq(1, res.n, tojson(res));
+ assert.eq(1, res.upserted, tojson(res));
+} else {
+ assert.eq(1, res.nUpserted, tojson(res));
+}
+
+var res = assert.writeOK(collA.update({_id:1}, {_id:1}, {writeConcern:{w:1}}));
+if (!db.getMongo().useWriteCommands() ) {
+ assert.eq(1, res.n, tojson(res));
+} else {
+ assert.eq(1, res.nMatched, tojson(res));
+}
+var res = assert.writeOK(collA.update({_id:1}, {_id:1}, {writeConcern:{w:1}}));
+if (!db.getMongo().useWriteCommands() ) {
+ assert.eq(1, res.n, tojson(res));
+} else {
+ assert.eq(1, res.nMatched, tojson(res));
+}
+
+var res = assert.writeOK(collA.insert({_id:2}, {writeConcern:{w:1}}));
+if (!db.getMongo().useWriteCommands() ) {
+ assert.eq(0, res.n, tojson(res));
+} else {
+ assert.eq(1, res.nInserted, tojson(res));
+}
+
+var res = assert.writeOK(collA.remove({_id:3}, {writeConcern:{w:1}}));
+if (!db.getMongo().useWriteCommands() ) {
+ assert.eq(0, res.n, tojson(res));
+} else {
+ assert.eq(0, res.nRemoved, tojson(res));
+}
+
+var res = assert.writeOK(collA.remove({}, {justOne:true, writeConcern:{w:1}}));
+if (!db.getMongo().useWriteCommands() ) {
+ assert.eq(1, res.n, tojson(res));
+} else {
+ assert.eq(1, res.nRemoved, tojson(res));
+}
+
+assert.writeError(collA.insert([{_id:1}, {_id:1}], {ordered:true, writeConcern:{w:1}}));
+assert.writeError(collA.insert([{_id:1}, {_id:1}], {ordered:false, writeConcern:{w:1}}));
+
+