diff options
author | Aaron <aaron@10gen.com> | 2009-01-27 14:18:33 -0500 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2009-01-27 14:18:33 -0500 |
commit | 66768ae3f7e286b697205bfc1ba8c947bbb1871b (patch) | |
tree | 8e4306c109980eaf0b83c2573ea8cde0bb5eb047 /jstests/capped2.js | |
parent | 5622e758fa9adb8d677f4048db9d170c91ca098f (diff) | |
download | mongo-66768ae3f7e286b697205bfc1ba8c947bbb1871b.tar.gz |
Move over some more js tests
Diffstat (limited to 'jstests/capped2.js')
-rw-r--r-- | jstests/capped2.js | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/jstests/capped2.js b/jstests/capped2.js new file mode 100644 index 00000000000..be9b1e1d5f1 --- /dev/null +++ b/jstests/capped2.js @@ -0,0 +1,52 @@ +db=connect("test"); +db.capped2.drop(); +db._dbCommand( { create: "capped2", capped: true, size: 1000, $nExtents: 11 } ); +t = db.capped2; + +var val = new Array( 1000 ); +var c = ""; +for( i = 0; i < 1000; ++i, c += "-" ) { + val[ i ] = { a: c }; +} + +function checkIncreasing( i ) { + res = t.find().sort( { $natural: -1 } ); + assert( res.hasNext() ); + var j = i; + while( res.hasNext() ) { + assert.eq( val[ j-- ].a, res.next().a ); + } + res = t.find().sort( { $natural: 1 } ); + assert( res.hasNext() ); + while( res.hasNext() ) + assert.eq( val[ ++j ].a, res.next().a ); + assert.eq( j, i ); +} + +function checkDecreasing( i ) { + res = t.find().sort( { $natural: -1 } ); + assert( res.hasNext() ); + var j = i; + while( res.hasNext() ) { + assert.eq( val[ j++ ].a, res.next().a ); + } + res = t.find().sort( { $natural: 1 } ); + assert( res.hasNext() ); + while( res.hasNext() ) + assert.eq( val[ --j ].a, res.next().a ); + assert.eq( j, i ); +} + +for( i = 0 ;; ++i ) { + t.save( val[ i ] ); + if ( t.count() == 0 ) { + assert( i > 100 ); + break; + } + checkIncreasing( i ); +} + +for( i = 600 ; i >= 0 ; --i ) { + t.save( val[ i ] ); + checkDecreasing( i ); +} |