diff options
Diffstat (limited to 'jstests/sharding/array_shard_key.js')
-rw-r--r-- | jstests/sharding/array_shard_key.js | 65 |
1 files changed, 15 insertions, 50 deletions
diff --git a/jstests/sharding/array_shard_key.js b/jstests/sharding/array_shard_key.js index 309f6191414..0c8d7e3a3dc 100644 --- a/jstests/sharding/array_shard_key.js +++ b/jstests/sharding/array_shard_key.js @@ -14,98 +14,65 @@ st.printShardingStatus() print( "1: insert some invalid data" ) -var value = null - -var checkError = function( shouldError ){ - var error = coll.getDB().getLastError() - - if( error != null ) printjson( error ) - - if( error == null && ! shouldError ) return - if( error != null && shouldError ) return - - if( error == null ) print( "No error detected!" ) - else print( "Unexpected error!" ) - - assert( false ) -} +var value = null; // Insert an object with invalid array key -coll.insert({ i : [ 1, 2 ] }) -checkError( true ) +assert.writeError(coll.insert({ i : [ 1, 2 ] })); // Insert an object with all the right fields, but an invalid array val for _id -coll.insert({ _id : [ 1, 2 ] , i : 3}) -checkError( true ) +assert.writeError(coll.insert({ _id : [ 1, 2 ] , i : 3})); // Insert an object with valid array key -coll.insert({ i : 1 }) -checkError( false ) +assert.writeOK(coll.insert({ i : 1 })); // Update the value with valid other field value = coll.findOne({ i : 1 }) -coll.update( value, { $set : { j : 2 } } ) -checkError( false ) +assert.writeOK(coll.update( value, { $set : { j : 2 } } )); // Update the value with invalid other fields value = coll.findOne({ i : 1 }) -coll.update( value, Object.merge( value, { i : [ 3 ] } ) ) -checkError( true ) +assert.writeError(coll.update( value, Object.merge( value, { i : [ 3 ] } ) )); // Multi-update the value with invalid other fields value = coll.findOne({ i : 1 }) -coll.update( value, Object.merge( value, { i : [ 3, 4 ] } ), false, true) -checkError( true ) +assert.writeError(coll.update( value, Object.merge( value, { i : [ 3, 4 ] } ), false, true)); // Multi-update the value with other fields (won't work, but no error) value = coll.findOne({ i : 1 }) -coll.update( Object.merge( value, { i : [ 1, 1 ] } ), { $set : { k : 4 } }, false, true) -checkError( false ) +assert.writeOK(coll.update( Object.merge( value, { i : [ 1, 1 ] } ), { $set : { k : 4 } }, false, true)); // Query the value with other fields (won't work, but no error) value = coll.findOne({ i : 1 }) coll.find( Object.merge( value, { i : [ 1, 1 ] } ) ).toArray() -checkError( false ) // Can't remove using multikey, but shouldn't error value = coll.findOne({ i : 1 }) coll.remove( Object.extend( value, { i : [ 1, 2, 3, 4 ] } ) ) -checkError( false ) // Can't remove using multikey, but shouldn't error value = coll.findOne({ i : 1 }) -coll.remove( Object.extend( value, { i : [ 1, 2, 3, 4, 5 ] } ) ) -error = coll.getDB().getLastError() -assert.eq( error, null ) +assert.writeOK(coll.remove( Object.extend( value, { i : [ 1, 2, 3, 4, 5 ] } ) )); assert.eq( coll.find().itcount(), 1 ) value = coll.findOne({ i : 1 }) -coll.remove( Object.extend( value, { i : 1 } ) ) -error = coll.getDB().getLastError() -assert.eq( error, null ) +assert.writeOK(coll.remove( Object.extend( value, { i : 1 } ) )); assert.eq( coll.find().itcount(), 0 ) coll.ensureIndex({ _id : 1, i : 1, j: 1 }); // Can insert document that will make index into a multi-key as long as it's not part of shard key. coll.remove({}); -coll.insert({ i: 1, j: [1, 2] }); -error = coll.getDB().getLastError(); -assert.eq( error, null ); +assert.writeOK(coll.insert({ i: 1, j: [1, 2] })); assert.eq( coll.find().itcount(), 1 ); // Same is true for updates. coll.remove({}); coll.insert({ _id: 1, i: 1 }); -coll.update({ _id: 1, i: 1 }, { _id: 1, i:1, j: [1, 2] }); -error = coll.getDB().getLastError(); -assert.eq( error, null ); +assert.writeOK(coll.update({ _id: 1, i: 1 }, { _id: 1, i:1, j: [1, 2] })); assert.eq( coll.find().itcount(), 1 ); // Same for upserts. coll.remove({}); -coll.update({ _id: 1, i: 1 }, { _id: 1, i:1, j: [1, 2] }, true); -error = coll.getDB().getLastError(); -assert.eq( error, null ); +assert.writeOK(coll.update({ _id: 1, i: 1 }, { _id: 1, i:1, j: [1, 2] }, true)); assert.eq( coll.find().itcount(), 1 ); printjson( "Sharding-then-inserting-multikey tested, now trying inserting-then-sharding-multikey" ) @@ -114,8 +81,7 @@ printjson( "Sharding-then-inserting-multikey tested, now trying inserting-then-s var coll = mongos.getCollection( "" + coll + "2" ) for( var i = 0; i < 10; i++ ){ // TODO : does not check weird cases like [ i, i ] - coll.insert({ i : [ i, i + 1 ] }) - checkError( false ) + assert.writeOK(coll.insert({ i : [ i, i + 1 ] })); } coll.ensureIndex({ _id : 1, i : 1 }) @@ -133,8 +99,7 @@ st.printShardingStatus() var coll = mongos.getCollection( "" + coll + "3" ) for( var i = 0; i < 10; i++ ){ // TODO : does not check weird cases like [ i, i ] - coll.insert({ i : i }) - checkError( false ) + assert.writeOK(coll.insert({ i : i })); } coll.ensureIndex({ _id : 1, i : 1 }) |