diff options
author | Eliot Horowitz <eliot@10gen.com> | 2009-05-15 13:10:55 -0400 |
---|---|---|
committer | Eliot Horowitz <eliot@10gen.com> | 2009-05-15 13:10:55 -0400 |
commit | 2db1e0ca72753543cbb468e95442396149169f08 (patch) | |
tree | 23056e1570d0262b5b0c40c6b30951ee3ea4abf4 /jstests | |
parent | 6b8c0c1555eddf8d86e05d37e19b0c7e789c00f1 (diff) | |
parent | 0516fad382e363191b627d18b0421bed9166cfd6 (diff) | |
download | mongo-2db1e0ca72753543cbb468e95442396149169f08.tar.gz |
Merge branch 'smshell'
Conflicts:
jstests/count.js
scripting/engine_spidermonkey.cpp
Diffstat (limited to 'jstests')
-rw-r--r-- | jstests/apitest_dbcollection.js | 25 | ||||
-rw-r--r-- | jstests/count.js | 21 | ||||
-rw-r--r-- | jstests/date1.js | 8 | ||||
-rw-r--r-- | jstests/drop.js | 16 | ||||
-rw-r--r-- | jstests/hint1.js | 2 | ||||
-rw-r--r-- | jstests/index3.js | 4 | ||||
-rw-r--r-- | jstests/objid1.js | 10 | ||||
-rw-r--r-- | jstests/objid3.js | 2 | ||||
-rw-r--r-- | jstests/query1.js | 20 | ||||
-rw-r--r-- | jstests/repl/pair1.js | 8 | ||||
-rw-r--r-- | jstests/sub1.js | 14 | ||||
-rw-r--r-- | jstests/update3.js | 8 | ||||
-rw-r--r-- | jstests/where1.js | 5 |
13 files changed, 98 insertions, 45 deletions
diff --git a/jstests/apitest_dbcollection.js b/jstests/apitest_dbcollection.js index 775912b1fc5..f6e74dad3ba 100644 --- a/jstests/apitest_dbcollection.js +++ b/jstests/apitest_dbcollection.js @@ -64,51 +64,52 @@ assert(v.result.toString().match(/nrecords\?:(\d+)/)[1] == 100,11); db.getCollection( "test_db" ).drop(); assert(db.getCollection( "test_db" ).count() == 0,12); db.getCollection( "test_db" ).dropIndexes(); -assert(db.getCollection( "test_db" ).getIndexes().length() == 0,13); +assert(db.getCollection( "test_db" ).getIndexes().length == 0,13); db.getCollection( "test_db" ).save({a:10}); -assert(db.getCollection( "test_db" ).getIndexes().length() == 1,14); +assert(db.getCollection( "test_db" ).getIndexes().length == 1,14); db.getCollection( "test_db" ).ensureIndex({a:1}); db.getCollection( "test_db" ).save({a:10}); -assert(db.getCollection( "test_db" ).getIndexes().length() == 2,15); +print( tojson( db.getCollection( "test_db" ).getIndexes() ) ); +assert.eq(db.getCollection( "test_db" ).getIndexes().length , 2,15); db.getCollection( "test_db" ).dropIndex({a:1}); -assert(db.getCollection( "test_db" ).getIndexes().length() == 1,16); +assert(db.getCollection( "test_db" ).getIndexes().length == 1,16); db.getCollection( "test_db" ).save({a:10}); db.getCollection( "test_db" ).ensureIndex({a:1}); db.getCollection( "test_db" ).save({a:10}); -assert(db.getCollection( "test_db" ).getIndexes().length() == 2,17); +assert(db.getCollection( "test_db" ).getIndexes().length == 2,17); db.getCollection( "test_db" ).dropIndex("a_1"); -assert.eq( db.getCollection( "test_db" ).getIndexes().length() , 1,18); +assert.eq( db.getCollection( "test_db" ).getIndexes().length , 1,18); db.getCollection( "test_db" ).save({a:10, b:11}); db.getCollection( "test_db" ).ensureIndex({a:1}); db.getCollection( "test_db" ).ensureIndex({b:1}); db.getCollection( "test_db" ).save({a:10, b:12}); -assert(db.getCollection( "test_db" ).getIndexes().length() == 3,19); +assert(db.getCollection( "test_db" ).getIndexes().length == 3,19); db.getCollection( "test_db" ).dropIndex({b:1}); -assert(db.getCollection( "test_db" ).getIndexes().length() == 2,20); +assert(db.getCollection( "test_db" ).getIndexes().length == 2,20); db.getCollection( "test_db" ).dropIndex({a:1}); -assert(db.getCollection( "test_db" ).getIndexes().length() == 1,21); +assert(db.getCollection( "test_db" ).getIndexes().length == 1,21); db.getCollection( "test_db" ).save({a:10, b:11}); db.getCollection( "test_db" ).ensureIndex({a:1}); db.getCollection( "test_db" ).ensureIndex({b:1}); db.getCollection( "test_db" ).save({a:10, b:12}); -assert(db.getCollection( "test_db" ).getIndexes().length() == 3,22); +assert(db.getCollection( "test_db" ).getIndexes().length == 3,22); db.getCollection( "test_db" ).dropIndexes(); -assert(db.getCollection( "test_db" ).getIndexes().length() == 1,23); +assert(db.getCollection( "test_db" ).getIndexes().length == 1,23); db.getCollection( "test_db" ).find(); db.getCollection( "test_db" ).drop(); -assert(db.getCollection( "test_db" ).getIndexes().length() == 0,24); +assert(db.getCollection( "test_db" ).getIndexes().length == 0,24); diff --git a/jstests/count.js b/jstests/count.js index f862aec2c84..5502d7176c1 100644 --- a/jstests/count.js +++ b/jstests/count.js @@ -3,22 +3,23 @@ t = db.jstests_count; t.drop(); t.save( { i: 1 } ); t.save( { i: 2 } ); -assert.eq( 1, t.find( { i: 1 } ).count() ); -assert.eq( 1, t.count( { i: 1 } ) ); -assert.eq( 2, t.find().count() ); -assert.eq( 2, t.find( undefined ).count() ); -assert.eq( 2, t.find( null ).count() ); -assert.eq( 2, t.count() ); +assert.eq( 1, t.find( { i: 1 } ).count(), "A" ); +assert.eq( 1, t.count( { i: 1 } ) , "B" ); +assert.eq( 2, t.find().count() , "C" ); +assert.eq( 2, t.find( undefined ).count() , "D" ); +assert.eq( 2, t.find( null ).count() , "E" ); +assert.eq( 2, t.count() , "F" ); t.drop(); t.save( {a:true,b:false} ); t.ensureIndex( {b:1,a:1} ); -assert.eq( 1, t.find( {a:true,b:false} ).count() ); -assert.eq( 1, t.find( {b:false,a:true} ).count() ); +assert.eq( 1, t.find( {a:true,b:false} ).count() , "G" ); +assert.eq( 1, t.find( {b:false,a:true} ).count() , "H" ); t.drop(); t.save( {a:true,b:false} ); t.ensureIndex( {b:1,a:1,c:1} ); -assert.eq( 1, t.find( {a:true,b:false} ).count() ); -assert.eq( 1, t.find( {b:false,a:true} ).count() ); + +assert.eq( 1, t.find( {a:true,b:false} ).count() , "I" ); +assert.eq( 1, t.find( {b:false,a:true} ).count() , "J" ); diff --git a/jstests/date1.js b/jstests/date1.js new file mode 100644 index 00000000000..a0b8dced730 --- /dev/null +++ b/jstests/date1.js @@ -0,0 +1,8 @@ + +t = db.date1; +t.drop(); + +d = new Date() +t.save( { a : 1 , d : d } ); + +assert.eq( d , t.findOne().d , "A" ) diff --git a/jstests/drop.js b/jstests/drop.js index f700f988a69..b233409ca3e 100644 --- a/jstests/drop.js +++ b/jstests/drop.js @@ -2,20 +2,20 @@ f = db.jstests_drop; f.drop(); -assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() ); +assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "A" ); f.save( {} ); -assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() ); +assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "B" ); f.ensureIndex( {a:1} ); -assert.eq( 2, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() ); +assert.eq( 2, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "C" ); assert.commandWorked( db.runCommand( {drop:"jstests_drop"} ) ); -assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() ); +assert.eq( 0, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "D" ); -f = db.jstests_drop; +f.resetIndexCache(); f.ensureIndex( {a:1} ); -assert.eq( 2, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() ); +assert.eq( 2, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "E" ); assert.commandWorked( db.runCommand( {deleteIndexes:"jstests_drop",index:"*"} ) ); -assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() ); +assert.eq( 1, db.system.indexes.find( {ns:"test.jstests_drop"} ).count() , "G" ); // make sure we can still use it f.save( {} ); -assert.eq( 1, f.find().hint( {_id:ObjectId( "000000000000000000000000" )} ).toArray().length ); +assert.eq( 1, f.find().hint( {_id:new ObjectId( "000000000000000000000000" )} ).toArray().length , "H" ); diff --git a/jstests/hint1.js b/jstests/hint1.js index 19d1dd40cb7..999f4f49597 100644 --- a/jstests/hint1.js +++ b/jstests/hint1.js @@ -5,4 +5,4 @@ p.ensureIndex( { ts: 1 } ); e = p.find( { live: true, ts: { $lt: new Date( 1234119308272 ) }, cls: "entry", verticals: " alleyinsider" } ).sort( { ts: -1 } ).hint( { ts: 1 } ).explain(); assert.eq( e.startKey.ts.getTime(), new Date( 1234119308272 ).getTime() ); -assert.eq( 1, e.endKey.ts.$minElement );
\ No newline at end of file +assert.eq( 1, e.endKey.ts.$minElement ); diff --git a/jstests/index3.js b/jstests/index3.js index 84e7efe7477..80139460cb4 100644 --- a/jstests/index3.js +++ b/jstests/index3.js @@ -3,7 +3,7 @@ t = db.index3; t.drop(); -assert( t.getIndexes().length() == 0 ); +assert( t.getIndexes().length == 0 ); t.ensureIndex( { name : 1 } ); @@ -11,6 +11,6 @@ t.save( { name : "a" } ); t.ensureIndex( { name : 1 } ); -assert( t.getIndexes().length() == 2 ); +assert( t.getIndexes().length == 2 ); assert(t.validate().valid); diff --git a/jstests/objid1.js b/jstests/objid1.js index 99a7aeb1a6f..f0b62ef5d0c 100644 --- a/jstests/objid1.js +++ b/jstests/objid1.js @@ -2,12 +2,12 @@ t = db.objid1; t.drop(); b = new ObjectId(); -assert( b.str , "objid1 test1" ); +assert( b.str , "A" ); -a = ObjectId( b.str ); -assert.eq( a.str , b.str ); +a = new ObjectId( b.str ); +assert.eq( a.str , b.str , "B" ); t.save( { a : a } ) -assert( t.findOne().a.isObjectId ); -assert.eq( a.str , t.findOne().a.str ); +assert( t.findOne().a.isObjectId , "C" ); +assert.eq( a.str , t.findOne().a.str , "D" ); diff --git a/jstests/objid3.js b/jstests/objid3.js index 02702e60b5c..ddf20d9af27 100644 --- a/jstests/objid3.js +++ b/jstests/objid3.js @@ -3,7 +3,7 @@ t.drop(); t.save( { a : "bob" , _id : 517 } ); for ( var k in t.findOne() ){ - assert.eq( k , "_id" ); + assert.eq( k , "_id" , "keys out of order" ); break; } diff --git a/jstests/query1.js b/jstests/query1.js new file mode 100644 index 00000000000..9b40054c203 --- /dev/null +++ b/jstests/query1.js @@ -0,0 +1,20 @@ + +t = db.query1; +t.drop(); + +t.save( { num : 1 } ); +t.save( { num : 3 } ) +t.save( { num : 4 } ); + +num = 0; +total = 0; + +t.find().forEach( + function(z){ + num++; + total += z.num; + } +); + +assert.eq( num , 3 , "num" ) +assert.eq( total , 8 , "total" ) diff --git a/jstests/repl/pair1.js b/jstests/repl/pair1.js index f23d28adf31..70040487674 100644 --- a/jstests/repl/pair1.js +++ b/jstests/repl/pair1.js @@ -2,6 +2,10 @@ var baseName = "jstests_pair1test"; +debug = function( p ) { +// print( p ); +} + ismaster = function( n ) { var im = n.getDB( "admin" ).runCommand( { "ismaster" : 1 } ); // print( "ismaster: " + tojson( im ) ); @@ -67,18 +71,22 @@ doTest = function( signal ) { checkWrite( rp.master(), rp.slave() ); + debug( "kill first" ); rp.killNode( rp.master(), signal ); rp.waitForSteadyState( [ 1, null ], rp.slave().host ); writeOne( rp.master() ); + debug( "restart first" ); rp.start( true ); rp.waitForSteadyState(); check( rp.slave() ); checkWrite( rp.master(), rp.slave() ); + debug( "kill second" ); rp.killNode( rp.master(), signal ); rp.waitForSteadyState( [ 1, null ], rp.slave().host ); + debug( "restart second" ); rp.start( true ); rp.waitForSteadyState( [ 1, 0 ], rp.master().host ); checkWrite( rp.master(), rp.slave() ); diff --git a/jstests/sub1.js b/jstests/sub1.js new file mode 100644 index 00000000000..9e643f811fd --- /dev/null +++ b/jstests/sub1.js @@ -0,0 +1,14 @@ +// sub1.js + +t = db.sub1; +t.drop(); + +x = { a : 1 , b : { c : { d : 2 } } } + +t.save( x ); + +y = t.findOne(); + +assert.eq( 1 , y.a ); +assert.eq( 2 , y.b.c.d ); +print( tojson( y ) ); diff --git a/jstests/update3.js b/jstests/update3.js index 26a21669659..4dfeb900a10 100644 --- a/jstests/update3.js +++ b/jstests/update3.js @@ -5,19 +5,19 @@ f = db.jstests_update3; f.drop(); f.save( { a:1 } ); f.update( {}, {$inc:{ a:1 }} ); -assert.eq( 2, f.findOne().a ); +assert.eq( 2, f.findOne().a , "A" ); f.drop(); f.save( { a:{ b: 1 } } ); f.update( {}, {$inc:{ "a.b":1 }} ); -assert.eq( 2, f.findOne().a.b ); +assert.eq( 2, f.findOne().a.b , "B" ); f.drop(); f.save( { a:{ b: 1 } } ); f.update( {}, {$set:{ "a.b":5 }} ); -assert.eq( 5, f.findOne().a.b ); +assert.eq( 5, f.findOne().a.b , "C" ); f.drop(); f.save( {'_id':0} ); f.update( {}, {$set:{'_id':5}} ); -assert.eq( 0, f.findOne()._id );
\ No newline at end of file +assert.eq( 0, f.findOne()._id , "D" ); diff --git a/jstests/where1.js b/jstests/where1.js index 831e9f59e22..017d1f3c1de 100644 --- a/jstests/where1.js +++ b/jstests/where1.js @@ -8,6 +8,7 @@ t.save( { a : 3 } ); assert.eq( 1 , t.find( function(){ return this.a == 2; } ).length() , "A" ); -assert.eq( 1 , t.find( { $where : "this.a == 2" } ).toArray().length , "B" ); +assert.eq( 1 , t.find( { $where : "return this.a == 2" } ).toArray().length , "B" ); +assert.eq( 1 , t.find( { $where : "this.a == 2" } ).toArray().length , "C" ); -assert.eq( 1 , t.find( "this.a == 2" ).toArray().length , "C" ); +assert.eq( 1 , t.find( "this.a == 2" ).toArray().length , "D" ); |