summaryrefslogtreecommitdiff
path: root/jstests/mmap_v1
diff options
context:
space:
mode:
authorEliot Horowitz <eliot@10gen.com>2014-08-04 12:33:52 -0400
committerEliot Horowitz <eliot@10gen.com>2014-08-05 08:51:41 -0400
commitaddfc302ecf617dfe46e4ce09d629e6bf8367f85 (patch)
tree2bfe6c2196492faf2052d46a2ea07c1ead623824 /jstests/mmap_v1
parent5d311d9f0583e3d74ce1aa47c66965cd0b39276f (diff)
downloadmongo-addfc302ecf617dfe46e4ce09d629e6bf8367f85.tar.gz
SERVER-13635: make all capped jstests generic
Diffstat (limited to 'jstests/mmap_v1')
-rw-r--r--jstests/mmap_v1/capped2.js62
-rw-r--r--jstests/mmap_v1/capped3.js45
-rw-r--r--jstests/mmap_v1/capped7.js89
3 files changed, 196 insertions, 0 deletions
diff --git a/jstests/mmap_v1/capped2.js b/jstests/mmap_v1/capped2.js
new file mode 100644
index 00000000000..65bb82f4c07
--- /dev/null
+++ b/jstests/mmap_v1/capped2.js
@@ -0,0 +1,62 @@
+db.capped2.drop();
+db._dbCommand( { create: "capped2", capped: true, size: 1000, $nExtents: 11, autoIndexId: false } );
+tzz = db.capped2;
+
+function debug( x ) {
+// print( x );
+}
+
+var val = new Array( 2000 );
+var c = "";
+for( i = 0; i < 2000; ++i, c += "---" ) { // bigger and bigger objects through the array...
+ val[ i ] = { a: c };
+}
+
+function checkIncreasing( i ) {
+ res = tzz.find().sort( { $natural: -1 } );
+ assert( res.hasNext(), "A" );
+ var j = i;
+ while( res.hasNext() ) {
+ try {
+ assert.eq( val[ j-- ].a, res.next().a, "B" );
+ } catch( e ) {
+ debug( "capped2 err " + j );
+ throw e;
+ }
+ }
+ res = tzz.find().sort( { $natural: 1 } );
+ assert( res.hasNext(), "C" );
+ while( res.hasNext() )
+ assert.eq( val[ ++j ].a, res.next().a, "D" );
+ assert.eq( j, i, "E" );
+}
+
+function checkDecreasing( i ) {
+ res = tzz.find().sort( { $natural: -1 } );
+ assert( res.hasNext(), "F" );
+ var j = i;
+ while( res.hasNext() ) {
+ assert.eq( val[ j++ ].a, res.next().a, "G" );
+ }
+ res = tzz.find().sort( { $natural: 1 } );
+ assert( res.hasNext(), "H" );
+ while( res.hasNext() )
+ assert.eq( val[ --j ].a, res.next().a, "I" );
+ assert.eq( j, i, "J" );
+}
+
+for( i = 0 ;; ++i ) {
+ debug( "capped 2: " + i );
+ tzz.insert( val[ i ] );
+ if ( tzz.count() == 0 ) {
+ assert( i > 100, "K" );
+ break;
+ }
+ checkIncreasing( i );
+}
+
+for( i = 600 ; i >= 0 ; --i ) {
+ debug( "capped 2: " + i );
+ tzz.insert( val[ i ] );
+ checkDecreasing( i );
+}
diff --git a/jstests/mmap_v1/capped3.js b/jstests/mmap_v1/capped3.js
new file mode 100644
index 00000000000..2e5e6790cb7
--- /dev/null
+++ b/jstests/mmap_v1/capped3.js
@@ -0,0 +1,45 @@
+t = db.jstests_capped3;
+t2 = db.jstests_capped3_clone;
+t.drop();
+t2.drop();
+for( i = 0; i < 1000; ++i ) {
+ t.save( {i:i} );
+}
+assert.commandWorked( db.runCommand( { cloneCollectionAsCapped:"jstests_capped3", toCollection:"jstests_capped3_clone", size:100000 } ), "A" );
+c = t2.find();
+for( i = 0; i < 1000; ++i ) {
+ assert.eq( i, c.next().i, "B" );
+}
+assert( !c.hasNext(), "C" );
+
+t.drop();
+t2.drop();
+
+for( i = 0; i < 1000; ++i ) {
+ t.save( {i:i} );
+}
+assert.commandWorked( db.runCommand( { cloneCollectionAsCapped:"jstests_capped3", toCollection:"jstests_capped3_clone", size:1000 } ), "D" );
+c = t2.find().sort( {$natural:-1} );
+i = 999;
+while( c.hasNext() ) {
+ assert.eq( i--, c.next().i, "E" );
+}
+//print( "i: " + i );
+var str = tojson( t2.stats() );
+//print( "stats: " + tojson( t2.stats() ) );
+assert( i < 990, "F" );
+
+t.drop();
+t2.drop();
+
+for( i = 0; i < 1000; ++i ) {
+ t.save( {i:i} );
+}
+assert.commandWorked( t.convertToCapped( 1000 ), "G" );
+c = t.find().sort( {$natural:-1} );
+i = 999;
+while( c.hasNext() ) {
+ assert.eq( i--, c.next().i, "H" );
+}
+assert( i < 990, "I" );
+assert( i > 900, "J" );
diff --git a/jstests/mmap_v1/capped7.js b/jstests/mmap_v1/capped7.js
new file mode 100644
index 00000000000..0405cefa5a0
--- /dev/null
+++ b/jstests/mmap_v1/capped7.js
@@ -0,0 +1,89 @@
+// Test capped collection truncate via 'emptycapped' command
+
+Random.setRandomSeed();
+
+db.capped7.drop();
+db._dbCommand( { create: "capped7", capped: true, size: 1000, $nExtents: 11, autoIndexId: false } );
+tzz = db.capped7;
+
+var ten = new Array( 11 ).toString().replace( /,/g, "-" );
+
+count = 0;
+
+/**
+ * Insert new documents until the capped collection loops and the document
+ * count doesn't increase on insert.
+ */
+function insertUntilFull() {
+count = tzz.count();
+ var j = 0;
+while( 1 ) {
+ tzz.save( {i:ten,j:j++} );
+ var newCount = tzz.count();
+ if ( count == newCount ) {
+ break;
+ }
+ count = newCount;
+}
+}
+
+insertUntilFull();
+
+// oldCount == count before empty
+oldCount = count;
+
+assert.eq.automsg( "11", "tzz.stats().numExtents" );
+
+// oldSize == size before empty
+var oldSize = tzz.stats().storageSize;
+
+assert.commandWorked( db._dbCommand( { emptycapped: "capped7" } ) );
+
+// check that collection storage parameters are the same after empty
+assert.eq.automsg( "11", "tzz.stats().numExtents" );
+assert.eq.automsg( "oldSize", "tzz.stats().storageSize" );
+
+// check that the collection is empty after empty
+assert.eq.automsg( "0", "tzz.find().itcount()" );
+assert.eq.automsg( "0", "tzz.count()" );
+
+// check that we can reuse the empty collection, inserting as many documents
+// as we were able to the first time through.
+insertUntilFull();
+assert.eq.automsg( "oldCount", "count" );
+assert.eq.automsg( "oldCount", "tzz.find().itcount()" );
+assert.eq.automsg( "oldCount", "tzz.count()" );
+
+assert.eq.automsg( "11", "tzz.stats().numExtents" );
+var oldSize = tzz.stats().storageSize;
+
+assert.commandWorked( db._dbCommand( { emptycapped: "capped7" } ) );
+
+// check that the collection storage parameters are unchanged after another empty
+assert.eq.automsg( "11", "tzz.stats().numExtents" );
+assert.eq.automsg( "oldSize", "tzz.stats().storageSize" );
+
+// insert an arbitrary number of documents
+var total = Random.randInt( 2000 );
+for( var j = 1; j <= total; ++j ) {
+ tzz.save( {i:ten,j:j} );
+ // occasionally check that only the oldest documents are removed to make room
+ // for the newest documents
+ if ( Random.rand() > 0.95 ) {
+ assert.automsg( "j >= tzz.count()" );
+ assert.eq.automsg( "tzz.count()", "tzz.find().itcount()" );
+ var c = tzz.find().sort( {$natural:-1} );
+ var k = j;
+ assert.automsg( "c.hasNext()" );
+ while( c.hasNext() ) {
+ assert.eq.automsg( "c.next().j", "k--" );
+ }
+ // check the same thing with a reverse iterator as well
+ var c = tzz.find().sort( {$natural:1} );
+ assert.automsg( "c.hasNext()" );
+ while( c.hasNext() ) {
+ assert.eq.automsg( "c.next().j", "++k" );
+ }
+ assert.eq.automsg( "j", "k" );
+ }
+}