summaryrefslogtreecommitdiff
path: root/jstests/capped7.js
diff options
context:
space:
mode:
authorAaron <aaron@10gen.com>2010-12-27 11:50:41 -0800
committerAaron <aaron@10gen.com>2010-12-27 11:51:58 -0800
commitda324130dc721ef74b13af8cbea17d56996db90e (patch)
treec629b88fc877a92c02765d6d2a52f26d0a57b89f /jstests/capped7.js
parent7085a082e30dfe5c914053f6e26bb2c82c3ea338 (diff)
downloadmongo-da324130dc721ef74b13af8cbea17d56996db90e.tar.gz
add test comments
Diffstat (limited to 'jstests/capped7.js')
-rw-r--r--jstests/capped7.js19
1 files changed, 18 insertions, 1 deletions
diff --git a/jstests/capped7.js b/jstests/capped7.js
index ecb689e23c6..693828da85f 100644
--- a/jstests/capped7.js
+++ b/jstests/capped7.js
@@ -1,3 +1,5 @@
+// Test NamespaceDetails::emptyCappedCollection via 'emptycapped' command
+
Random.setRandomSeed();
db.capped7.drop();
@@ -8,6 +10,10 @@ 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;
@@ -23,21 +29,27 @@ while( 1 ) {
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()" );
@@ -47,12 +59,16 @@ 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()" );
@@ -62,6 +78,7 @@ for( var j = 1; j <= total; ++j ) {
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() ) {