diff options
author | Aaron <aaron@10gen.com> | 2010-12-27 11:50:41 -0800 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2010-12-27 11:51:58 -0800 |
commit | da324130dc721ef74b13af8cbea17d56996db90e (patch) | |
tree | c629b88fc877a92c02765d6d2a52f26d0a57b89f /jstests/capped6.js | |
parent | 7085a082e30dfe5c914053f6e26bb2c82c3ea338 (diff) | |
download | mongo-da324130dc721ef74b13af8cbea17d56996db90e.tar.gz |
add test comments
Diffstat (limited to 'jstests/capped6.js')
-rw-r--r-- | jstests/capped6.js | 25 |
1 files changed, 25 insertions, 0 deletions
diff --git a/jstests/capped6.js b/jstests/capped6.js index 851bbd19ce3..65798075208 100644 --- a/jstests/capped6.js +++ b/jstests/capped6.js @@ -1,3 +1,5 @@ +// Test NamespaceDetails::cappedTruncateAfter via 'captrunc' command + Random.setRandomSeed(); db.capped6.drop(); @@ -8,6 +10,12 @@ function debug( x ) { // print( x ); } +/** + * Check that documents in the collection are in order according to the value + * of a, which corresponds to the insert order. This is a check that the oldest + * document(s) is/are deleted when space is needed for the newest document. The + * check is performed in both forward and reverse directions. + */ function checkOrder( i ) { res = tzz.find().sort( { $natural: -1 } ); assert( res.hasNext(), "A" ); @@ -30,12 +38,18 @@ function checkOrder( i ) { var val = new Array( 500 ); var c = ""; for( i = 0; i < 500; ++i, c += "-" ) { + // The a values are strings of increasing length. val[ i ] = { a: c }; } var oldMax = Random.randInt( 500 ); var max = 0; +/** + * Insert new documents until there are 'oldMax' documents in the collection, + * then remove a random number of documents (often all but one) via one or more + * 'captrunc' requests. + */ function doTest() { for( var i = max; i < oldMax; ++i ) { tzz.save( val[ i ] ); @@ -48,7 +62,13 @@ function doTest() { min = Random.randInt( count ) + 1; } + // Iteratively remove a random number of documents until we have no more + // than 'min' documents. while( count > min ) { + // 'n' is the number of documents to remove - we must account for the + // possibility that 'inc' will be true, and avoid removing all documents + // from the collection in that case, as removing all documents is not + // allowed by 'captrunc' var n = Random.randInt( count - min - 1 ); // 0 <= x <= count - min - 1 var inc = Random.rand() > 0.5; debug( count + " " + n + " " + inc ); @@ -58,10 +78,13 @@ function doTest() { } count -= n; max -= n; + // Validate the remaining documents. checkOrder( max - 1 ); } } +// Repeatedly add up to 'oldMax' documents and then truncate the newest +// documents. Newer documents take up more space than older documents. for( var i = 0; i < 10; ++i ) { doTest(); } @@ -77,6 +100,8 @@ db.capped6.drop(); db._dbCommand( { create: "capped6", capped: true, size: 1000, $nExtents: 11, autoIndexId: false } ); tzz = db.capped6; +// Same test as above, but now the newer documents take less space than the +// older documents instead of more. for( var i = 0; i < 10; ++i ) { doTest(); } |