summaryrefslogtreecommitdiff
path: root/jstests/capped2.js
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2009-01-27 14:18:33 -0500
committerAaron <aaron@10gen.com>2009-01-27 14:18:33 -0500
commit66768ae3f7e286b697205bfc1ba8c947bbb1871b (patch)
tree8e4306c109980eaf0b83c2573ea8cde0bb5eb047 /jstests/capped2.js
parent5622e758fa9adb8d677f4048db9d170c91ca098f (diff)
downloadmongo-66768ae3f7e286b697205bfc1ba8c947bbb1871b.tar.gz
Move over some more js tests
Diffstat (limited to 'jstests/capped2.js')
-rw-r--r--jstests/capped2.js52
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 );
+}