diff options
author | Aaron <aaron@10gen.com> | 2010-01-20 12:17:22 -0800 |
---|---|---|
committer | Aaron <aaron@10gen.com> | 2010-01-20 12:17:22 -0800 |
commit | 0036246413fd1cd6fd96a60c7512f303572d432f (patch) | |
tree | 497e04c7fd712e26dbb406e83eb88596a14063dd | |
parent | 2597876acbb883cd3b80d17cbc5cf00396429b81 (diff) | |
download | mongo-0036246413fd1cd6fd96a60c7512f303572d432f.tar.gz |
SERVER-525 add more extensive test for undoInsert
-rw-r--r-- | jstests/capped6.js | 72 | ||||
-rw-r--r-- | mongo.xcodeproj/project.pbxproj | 2 |
2 files changed, 74 insertions, 0 deletions
diff --git a/jstests/capped6.js b/jstests/capped6.js new file mode 100644 index 00000000000..091f9834ae6 --- /dev/null +++ b/jstests/capped6.js @@ -0,0 +1,72 @@ +db.capped6.drop(); +db._dbCommand( { create: "capped6", capped: true, size: 1000, $nExtents: 11, autoIndexId: false } ); +tzz = db.capped6; +tzz.ensureIndex( {i:1}, {unique:true} ); + +function debug( x ) { +// print( x ); +} + +var val = new Array( 2000 ); +var c = ""; +for( i = 0; i < 2000; ++i, c += "-" ) { + 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( "capped6 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 6: " + i ); + tzz.save( {a:val[ i ].a, i:i } ); + if ( i % 5 == 2 ) { + if( 1 == tzz.count( {i:i-2} ) ) { + tzz.save( {a:val[ i ].a, i:i-2 } ); // this is a duplicate for i & will fail + assert.eq( 1, tzz.count( {i:i-2} ) ); + } + } + if ( tzz.count() == 0 ) { + assert( i > 100, "K" ); + break; + } + checkIncreasing( i ); +} + +for( i = 600 ; i >= 0 ; --i ) { + debug( "capped 6: " + i ); + tzz.save( {a:val[ i ].a, i:i } ); + if ( i % 5 == 0 ) { + tzz.save( {a:val[ i ].a, i:i } ); // this is a duplicate for i & will fail + } + checkDecreasing( i ); +} diff --git a/mongo.xcodeproj/project.pbxproj b/mongo.xcodeproj/project.pbxproj index f8dabceb0d8..5a2921e30bd 100644 --- a/mongo.xcodeproj/project.pbxproj +++ b/mongo.xcodeproj/project.pbxproj @@ -399,6 +399,7 @@ 934DD88D0EFAD23B00459CC1 /* unittest.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = unittest.h; sourceTree = "<group>"; }; 934DD88E0EFAD23B00459CC1 /* util.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = util.cpp; sourceTree = "<group>"; }; 935C941B1106709800439EB1 /* preallocate.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = preallocate.js; sourceTree = "<group>"; }; + 935C9632110794F500439EB1 /* capped6.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = capped6.js; sourceTree = "<group>"; }; 936B89590F4C899400934AF2 /* file.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = file.h; sourceTree = "<group>"; }; 936B895A0F4C899400934AF2 /* md5.c */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.c; path = md5.c; sourceTree = "<group>"; }; 936B895B0F4C899400934AF2 /* md5.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = md5.h; sourceTree = "<group>"; }; @@ -728,6 +729,7 @@ 934BEB9A10DFFA9600178102 /* jstests */ = { isa = PBXGroup; children = ( + 935C9632110794F500439EB1 /* capped6.js */, 93BCE41810F3AF1B00FA139B /* capped2.js */, 93BCE1D310F26CDA00FA139B /* fsync2.js */, 93BCE15610F25DFE00FA139B /* arrayfind1.js */, |