mirror of
https://github.com/mongodb/mongo.git
synced 2024-12-01 09:32:32 +01:00
add cursortests
This commit is contained in:
parent
66a33c8162
commit
f077e9f75d
115
dbtests/cursortests.cpp
Normal file
115
dbtests/cursortests.cpp
Normal file
@ -0,0 +1,115 @@
|
||||
// cusrortests.cpp // cursor related unit tests
|
||||
//
|
||||
|
||||
/**
|
||||
* Copyright (C) 2009 10gen Inc.
|
||||
*
|
||||
* This program is free software: you can redistribute it and/or modify
|
||||
* it under the terms of the GNU Affero General Public License, version 3,
|
||||
* as published by the Free Software Foundation.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful,
|
||||
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
* GNU Affero General Public License for more details.
|
||||
*
|
||||
* You should have received a copy of the GNU Affero General Public License
|
||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "../db/clientcursor.h"
|
||||
|
||||
#include "dbtests.h"
|
||||
|
||||
namespace CursorTests {
|
||||
|
||||
namespace IdSetTests {
|
||||
|
||||
class BasicSize {
|
||||
public:
|
||||
void run() {
|
||||
IdSet a;
|
||||
IdSet b;
|
||||
ASSERT_EQUALS( 0, IdSet::aggregateSize() );
|
||||
a.put( BSON( "a" << 4 ) );
|
||||
ASSERT_EQUALS( 24, a.mySize() );
|
||||
a.put( BSON( "ab" << 4 ) );
|
||||
ASSERT_EQUALS( 49, a.mySize() );
|
||||
ASSERT_EQUALS( 49, IdSet::aggregateSize() );
|
||||
b.put( BSON( "abc" << 4 ) );
|
||||
ASSERT_EQUALS( 26, b.mySize() );
|
||||
ASSERT_EQUALS( 75, IdSet::aggregateSize() );
|
||||
}
|
||||
~BasicSize() {
|
||||
if ( 0 != IdSet::aggregateSize() )
|
||||
FAIL( "aggregateSize not reset" );
|
||||
}
|
||||
private:
|
||||
dblock lk_;
|
||||
};
|
||||
|
||||
class Upgrade {
|
||||
public:
|
||||
Upgrade() : num_() {}
|
||||
void run() {
|
||||
setClient( "foo.bar" );
|
||||
|
||||
IdSet::maxSize_ = 200;
|
||||
|
||||
IdSet a;
|
||||
IdSet b;
|
||||
ASSERT( a.inMem() );
|
||||
ASSERT( b.inMem() );
|
||||
a.put( twentySix() );
|
||||
b.put( twentySix() );
|
||||
b.put( twentySix() );
|
||||
b.put( twentySix() );
|
||||
b.mayUpgradeStorage( "b" );
|
||||
ASSERT( b.inMem() );
|
||||
a.put( twentySix() );
|
||||
a.put( twentySix() );
|
||||
a.mayUpgradeStorage( "a" );
|
||||
ASSERT( a.inMem() );
|
||||
a.put( twentySix() );
|
||||
a.mayUpgradeStorage( "a" );
|
||||
ASSERT( !a.inMem() );
|
||||
b.put( twentySix() );
|
||||
b.mayUpgradeStorage( "b" );
|
||||
ASSERT( !b.inMem() );
|
||||
|
||||
ASSERT( a.get( twentySix( 0 ) ) );
|
||||
for( int i = 1; i < 4; ++i )
|
||||
ASSERT( b.get( twentySix( i ) ) );
|
||||
for( int i = 4; i < 7; ++i )
|
||||
ASSERT( a.get( twentySix( i ) ) );
|
||||
ASSERT( b.get( twentySix( 7 ) ) );
|
||||
}
|
||||
~Upgrade() {
|
||||
setClient( "local.temp" );
|
||||
if ( nsdetails( "local.temp.clientcursor.a" ) || nsdetails( "local.temp.clientcursor.b" ) )
|
||||
FAIL( "client cursor temp collection not deleted" );
|
||||
}
|
||||
private:
|
||||
BSONObj twentySix( int i = -1 ) {
|
||||
if ( i == -1 )
|
||||
i = num_++;
|
||||
return BSON( "_id" << i );
|
||||
}
|
||||
dblock lk_;
|
||||
int num_;
|
||||
};
|
||||
|
||||
} // namespace IdSetTests
|
||||
|
||||
class All : public UnitTest::Suite {
|
||||
public:
|
||||
All() {
|
||||
add< IdSetTests::BasicSize >();
|
||||
add< IdSetTests::Upgrade >();
|
||||
}
|
||||
};
|
||||
} // namespace CursorTests
|
||||
|
||||
UnitTest::TestPtr cursorTests() {
|
||||
return UnitTest::createSuite< CursorTests::All >();
|
||||
}
|
@ -96,6 +96,7 @@ int main( int argc, char** argv ) {
|
||||
|
||||
tests.add( basicTests(), "basic" );
|
||||
tests.add( btreeTests(), "btree" );
|
||||
tests.add( cursorTests(), "cursor" );
|
||||
tests.add( jsobjTests(), "jsobj" );
|
||||
tests.add( jsonTests(), "json" );
|
||||
tests.add( matcherTests(), "matcher" );
|
||||
|
@ -23,6 +23,7 @@ using namespace mongo;
|
||||
|
||||
UnitTest::TestPtr basicTests();
|
||||
UnitTest::TestPtr btreeTests();
|
||||
UnitTest::TestPtr cursorTests();
|
||||
UnitTest::TestPtr jsTests();
|
||||
UnitTest::TestPtr jsobjTests();
|
||||
UnitTest::TestPtr jsonTests();
|
||||
|
@ -149,6 +149,8 @@
|
||||
938A7A480F54873600FB7A07 /* reccache.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reccache.h; sourceTree = "<group>"; };
|
||||
938A7A490F54873600FB7A07 /* reci.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = reci.h; sourceTree = "<group>"; };
|
||||
938A7A4A0F54873600FB7A07 /* recstore.h */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.c.h; path = recstore.h; sourceTree = "<group>"; };
|
||||
938DEB9A0FB4957900C393D8 /* cursortests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = cursortests.cpp; sourceTree = "<group>"; };
|
||||
938DEB9B0FB4957900C393D8 /* jstests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = jstests.cpp; sourceTree = "<group>"; };
|
||||
939C67200F535D72006570D3 /* cursor8.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = cursor8.js; sourceTree = "<group>"; };
|
||||
93A13A210F4620A500AF1B0D /* commands.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = commands.cpp; sourceTree = "<group>"; };
|
||||
93A13A230F4620A500AF1B0D /* config.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = config.cpp; sourceTree = "<group>"; };
|
||||
@ -243,7 +245,6 @@
|
||||
93A8D2100F37544800C92B85 /* update2.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = update2.js; sourceTree = "<group>"; };
|
||||
93A8D2110F37544800C92B85 /* where1.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = where1.js; sourceTree = "<group>"; };
|
||||
93A8D8200F38FE2400C92B85 /* autoid.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = autoid.js; sourceTree = "<group>"; };
|
||||
93AB914E0F4F1C7A0020A046 /* javajstests.cpp */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.cpp.cpp; path = javajstests.cpp; sourceTree = "<group>"; };
|
||||
93AB914F0F4F1C970020A046 /* _runner_leak.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = _runner_leak.js; sourceTree = "<group>"; };
|
||||
93AB91500F4F1C970020A046 /* _runner_leak_nojni.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = _runner_leak_nojni.js; sourceTree = "<group>"; };
|
||||
93AB91510F4F1C970020A046 /* _runner_sharding.js */ = {isa = PBXFileReference; fileEncoding = 4; lastKnownFileType = sourcecode.javascript; path = _runner_sharding.js; sourceTree = "<group>"; };
|
||||
@ -377,8 +378,9 @@
|
||||
934223850EF16D7000608550 /* dbtests */ = {
|
||||
isa = PBXGroup;
|
||||
children = (
|
||||
938DEB9A0FB4957900C393D8 /* cursortests.cpp */,
|
||||
938DEB9B0FB4957900C393D8 /* jstests.cpp */,
|
||||
93C38E940FA66622007D6E4A /* basictests.cpp */,
|
||||
93AB914E0F4F1C7A0020A046 /* javajstests.cpp */,
|
||||
932AC3EB0F4A5B34005BF8B0 /* queryoptimizertests.cpp */,
|
||||
933E22100F4327B2000209E3 /* perf */,
|
||||
937D0E340F28CB070071FFA9 /* repltests.cpp */,
|
||||
|
Loading…
Reference in New Issue
Block a user