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-28 12:46:44 -0400 |
commit | f2e8a05f846678c32575883f765151b36225a6a6 (patch) | |
tree | 124227106bb1dc0fd1d6dda381db83fe1b23fe9c | |
parent | 1cfdc9f9e8571d529b6cc2681d89567835946911 (diff) | |
download | mongo-f2e8a05f846678c32575883f765151b36225a6a6.tar.gz |
SERVER-13386 Move tests with getPrevError to gle test suite
Ignore getPrevError in gle sharding test
Migrate geo_oob_sphere.js
(cherry picked from commit ec89a420a86c3c918f4bd634fc2134db0a9eb154)
-rw-r--r-- | jstests/core/geo_oob_sphere.js | 31 | ||||
-rw-r--r-- | jstests/gle/1_sharding_gle_basics_passthrough.js | 5 | ||||
-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 |
5 files changed, 204 insertions, 1 deletions
diff --git a/jstests/core/geo_oob_sphere.js b/jstests/core/geo_oob_sphere.js new file mode 100644 index 00000000000..59343e7d7ac --- /dev/null +++ b/jstests/core/geo_oob_sphere.js @@ -0,0 +1,31 @@ +// +// Ensures spherical queries report invalid latitude values in points and center positions +// + +t = db.geooobsphere +t.drop(); + +t.insert({ loc : { x : 30, y : 89 } }) +t.insert({ loc : { x : 30, y : 89 } }) +t.insert({ loc : { x : 30, y : 89 } }) +t.insert({ loc : { x : 30, y : 89 } }) +t.insert({ loc : { x : 30, y : 89 } }) +t.insert({ loc : { x : 30, y : 89 } }) +t.insert({ loc : { x : 30, y : 91 } }) + +assert.commandWorked(t.ensureIndex({ loc : "2d" })) + +assert.throws( function() { t.find({ loc : { $nearSphere : [ 30, 91 ], $maxDistance : 0.25 } }).count() } ); + +assert.throws( function() { t.find({ loc : { $nearSphere : [ 30, 89 ], $maxDistance : 0.25 } }).count() } ); + +assert.throws( function() { t.find({ loc : { $within : { $centerSphere : [[ -180, -91 ], 0.25] } } }).count() } ); + +var res; +res = db.runCommand({ geoNear : "geooobsphere", near : [179, -91], maxDistance : 0.25, spherical : true }) +assert.commandFailed( res ) +printjson( res ) + +res = db.runCommand({ geoNear : "geooobsphere", near : [30, 89], maxDistance : 0.25, spherical : true }) +assert.commandFailed( res ) +printjson( res ) diff --git a/jstests/gle/1_sharding_gle_basics_passthrough.js b/jstests/gle/1_sharding_gle_basics_passthrough.js index 097b281c87f..109fd3776c2 100644 --- a/jstests/gle/1_sharding_gle_basics_passthrough.js +++ b/jstests/gle/1_sharding_gle_basics_passthrough.js @@ -12,7 +12,10 @@ var lastDB = db; var coreTests = listFiles("jstests/gle/core"); var testsToSkip = new RegExp('[\\/\\\\](' + - 'error1' + // getPrevError not supported in sharding + 'error1|' + // getPrevError not supported in sharding + 'remove5|' + + 'unique2|' + + 'update4' + ')\.js$'); coreTests.forEach( function(file) { 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" ); |