diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2014-03-27 16:31:25 -0400 |
---|---|---|
committer | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2014-03-27 17:06:37 -0400 |
commit | 2850ecc726d6ef33ff4284e1ce0378fb42d3b854 (patch) | |
tree | 9e67b011bed31553ea7460e3724d8faba7eb1cf4 /jstests/gle | |
parent | 39143d55a37ea77b37433b8951a259c30c10cfc9 (diff) | |
download | mongo-2850ecc726d6ef33ff4284e1ce0378fb42d3b854.tar.gz |
SERVER-13386 Move tests with getPrevError to gle test suite.
Also migrate geo_oob_sphere.js
Diffstat (limited to 'jstests/gle')
-rw-r--r-- | jstests/gle/core/remove5.js | 24 | ||||
-rw-r--r-- | jstests/gle/core/unique2.js | 112 | ||||
-rw-r--r-- | jstests/gle/core/update4.js | 33 |
3 files changed, 169 insertions, 0 deletions
diff --git a/jstests/gle/core/remove5.js b/jstests/gle/core/remove5.js new file mode 100644 index 00000000000..be4f0b49ec1 --- /dev/null +++ b/jstests/gle/core/remove5.js @@ -0,0 +1,24 @@ +f = db.jstests_remove5; +f.drop(); + +getLastError = function() { + return db.runCommand( { getlasterror : 1 } ); +} + +f.remove( {} ); +assert.eq( 0, getLastError().n ); +f.save( {a:1} ); +f.remove( {} ); +assert.eq( 1, getLastError().n ); +for( i = 0; i < 10; ++i ) { + f.save( {i:i} ); +} +f.remove( {} ); +assert.eq( 10, getLastError().n ); +assert.eq( 10, db.getPrevError().n ); +assert.eq( 1, db.getPrevError().nPrev ); + +f.findOne(); +assert.eq( 0, getLastError().n ); +assert.eq( 10, db.getPrevError().n ); +assert.eq( 2, db.getPrevError().nPrev ); diff --git a/jstests/gle/core/unique2.js b/jstests/gle/core/unique2.js new file mode 100644 index 00000000000..0d3993630c3 --- /dev/null +++ b/jstests/gle/core/unique2.js @@ -0,0 +1,112 @@ +// Test unique and dropDups index options. + +function checkNprev( np ) { + // getPrevError() is not available sharded. + if ( typeof( myShardingTest ) == 'undefined' ) { + assert.eq( np, db.getPrevError().nPrev ); + } +} + +t = db.jstests_unique2; + +t.drop(); + +/* test for good behavior when indexing multikeys */ + +t.insert({k:3}); +t.insert({k:[2,3]}); +t.insert({k:[4,3]}); +t.insert({k:[4,3]}); // tests SERVER-4770 + +t.ensureIndex({k:1}, {unique:true, dropDups:true}); + +assert( t.count() == 1 ) ; +assert( t.find().sort({k:1}).toArray().length == 1 ) ; +assert( t.find().sort({k:1}).count() == 1 ) ; + +t.drop(); + +/* same test wtih background:true*/ + +t.insert({k:3}); +t.insert({k:[2,3]}); +t.insert({k:[4,3]}); +t.insert({k:[4,3]}); + +t.ensureIndex({k:1}, {unique:true, dropDups:true, background:true}); + +assert( t.count() == 1 ) ; +assert( t.find().sort({k:1}).toArray().length == 1 ) ; +assert( t.find().sort({k:1}).count() == 1 ) ; + +t.drop(); + +/* */ + +t.ensureIndex({k:1}, {unique:true}); + +t.insert({k:3}); +t.insert({k:[2,3]}); +assert( db.getLastError() ); +t.insert({k:[4,3]}); +assert( db.getLastError() ); + +assert( t.count() == 1 ) ; +assert( t.find().sort({k:1}).toArray().length == 1 ) ; +assert( t.find().sort({k:1}).count() == 1 ) ; + +t.dropIndexes(); + +t.insert({k:[2,3]}); +t.insert({k:[4,3]}); +assert( t.count() == 3 ) ; + +// Trigger an error, so we can test n of getPrevError() later. +t.update({ x : 1 }, { $invalid : true }); +assert.neq(null, db.getLastError()); +checkNprev( 1 ); + +t.ensureIndex({k:1}, {unique:true, dropDups:true}); +// Check error flag was not set SERVER-2054. +assert.eq(null, db.getLastError() ); +// Check that offset of previous error is correct. +checkNprev( 2 ); + +// Check the dups were dropped. +assert( t.count() == 1 ) ; +assert( t.find().sort({k:1}).toArray().length == 1 ) ; +assert( t.find().sort({k:1}).count() == 1 ) ; + +// Check that a new conflicting insert will cause an error. +t.insert({k:[2,3]}); +assert( db.getLastError() ); + +t.drop(); + +t.insert({k:3}); +t.insert({k:[2,3]}); +t.insert({k:[4,3]}); +assert( t.count() == 3 ) ; + + +// Now try with a background index op. + +// Trigger an error, so we can test n of getPrevError() later. +t.update({ x : 1 }, { $invalid : true }); +assert( db.getLastError() ); +checkNprev( 1 ); + +t.ensureIndex({k:1}, {background:true, unique:true, dropDups:true}); +// Check error flag was not set SERVER-2054. +assert( !db.getLastError() ); +// Check that offset of pervious error is correct. +checkNprev( 2 ); + +// Check the dups were dropped. +assert( t.count() == 1 ) ; +assert( t.find().sort({k:1}).toArray().length == 1 ) ; +assert( t.find().sort({k:1}).count() == 1 ) ; + +// Check that a new conflicting insert will cause an error. +t.insert({k:[2,3]}); +assert( db.getLastError() ); diff --git a/jstests/gle/core/update4.js b/jstests/gle/core/update4.js new file mode 100644 index 00000000000..1502f672a50 --- /dev/null +++ b/jstests/gle/core/update4.js @@ -0,0 +1,33 @@ +f = db.jstests_update4; +f.drop(); + +getLastError = function() { + ret = db.runCommand( { getlasterror : 1 } ); +// printjson( ret ); + return ret; +} + +f.save( {a:1} ); +f.update( {a:1}, {a:2} ); +assert.eq( true, getLastError().updatedExisting , "A" ); +assert.eq( 1, getLastError().n , "B" ); +f.update( {a:1}, {a:2} ); +assert.eq( false, getLastError().updatedExisting , "C" ); +assert.eq( 0, getLastError().n , "D" ); + +f.update( {a:1}, {a:1}, true ); +assert.eq( false, getLastError().updatedExisting , "E" ); +assert.eq( 1, getLastError().n , "F" ); +f.update( {a:1}, {a:1}, true ); +assert.eq( true, getLastError().updatedExisting , "G" ); +assert.eq( 1, getLastError().n , "H" ); +assert.eq( true, db.getPrevError().updatedExisting , "I" ); +assert.eq( 1, db.getPrevError().nPrev , "J" ); + +f.findOne(); +assert.eq( undefined, getLastError().updatedExisting , "K" ); +assert.eq( true, db.getPrevError().updatedExisting , "L" ); +assert.eq( 2, db.getPrevError().nPrev , "M" ); + +db.forceError(); +assert.eq( undefined, getLastError().updatedExisting , "N" ); |