diff options
Diffstat (limited to 'dbtests')
-rw-r--r-- | dbtests/queryoptimizertests.cpp | 92 | ||||
-rw-r--r-- | dbtests/queryutiltests.cpp | 23 |
2 files changed, 110 insertions, 5 deletions
diff --git a/dbtests/queryoptimizertests.cpp b/dbtests/queryoptimizertests.cpp index 38d631e..59a9874 100644 --- a/dbtests/queryoptimizertests.cpp +++ b/dbtests/queryoptimizertests.cpp @@ -1921,6 +1921,33 @@ namespace QueryOptimizerTests { } }; + /** Yield and remove document with $or query. */ + class YieldRemoveOr : public Base { + public: + void run() { + _cli.insert( ns(), BSON( "_id" << 1 ) ); + _cli.insert( ns(), BSON( "_id" << 2 ) ); + + { + dblock lk; + Client::Context ctx( ns() ); + setQueryOptimizerCursor( BSON( "$or" << BSON_ARRAY( BSON( "_id" << 1 ) << BSON( "_id" << 2 ) ) ) ); + ASSERT_EQUALS( 1, current().getIntField( "_id" ) ); + ASSERT( prepareToYield() ); + } + + _cli.remove( ns(), BSON( "_id" << 1 ) ); + + { + dblock lk; + Client::Context ctx( ns() ); + recoverFromYield(); + ASSERT( ok() ); + ASSERT_EQUALS( 2, current().getIntField( "_id" ) ); + } + } + }; + /** Yield and overwrite current in capped collection. */ class YieldCappedOverwrite : public Base { public: @@ -2074,6 +2101,68 @@ namespace QueryOptimizerTests { } }; + /** Yielding with delete, multiple plans active, and $or clause. */ + class YieldMultiplePlansDeleteOr : public Base { + public: + void run() { + _cli.insert( ns(), BSON( "_id" << 1 << "a" << 2 ) ); + _cli.insert( ns(), BSON( "_id" << 2 << "a" << 1 ) ); + _cli.ensureIndex( ns(), BSON( "a" << 1 ) ); + + { + dblock lk; + Client::Context ctx( ns() ); + setQueryOptimizerCursor( BSON( "$or" << BSON_ARRAY( BSON( "_id" << 1 << "a" << 2 ) << BSON( "_id" << 2 << "a" << 1 ) ) ) ); + ASSERT_EQUALS( 1, current().getIntField( "_id" ) ); + ASSERT( prepareToYield() ); + } + + _cli.remove( ns(), BSON( "_id" << 1 ) ); + + { + dblock lk; + Client::Context ctx( ns() ); + c()->recoverFromYield(); + ASSERT( ok() ); + ASSERT_EQUALS( 2, current().getIntField( "_id" ) ); + ASSERT( !advance() ); + ASSERT( !ok() ); + } + } + }; + + /** Yielding with delete, multiple plans active with advancement to the second, and $or clause. */ + class YieldMultiplePlansDeleteOrAdvance : public Base { + public: + void run() { + _cli.insert( ns(), BSON( "_id" << 1 << "a" << 2 ) ); + _cli.insert( ns(), BSON( "_id" << 2 << "a" << 1 ) ); + _cli.ensureIndex( ns(), BSON( "a" << 1 ) ); + + { + dblock lk; + Client::Context ctx( ns() ); + setQueryOptimizerCursor( BSON( "$or" << BSON_ARRAY( BSON( "_id" << 1 << "a" << 2 ) << BSON( "_id" << 2 << "a" << 1 ) ) ) ); + ASSERT_EQUALS( 1, current().getIntField( "_id" ) ); + ASSERT( prepareToYield() ); + c()->advance(); + ASSERT_EQUALS( 1, current().getIntField( "_id" ) ); + } + + _cli.remove( ns(), BSON( "_id" << 1 ) ); + + { + dblock lk; + Client::Context ctx( ns() ); + c()->recoverFromYield(); + ASSERT( ok() ); + ASSERT_EQUALS( 2, current().getIntField( "_id" ) ); + ASSERT( !advance() ); + ASSERT( !ok() ); + } + } + }; + /** Yielding with multiple plans and capped overwrite. */ class YieldMultiplePlansCappedOverwrite : public Base { public: @@ -2703,11 +2792,14 @@ namespace QueryOptimizerTests { add<QueryOptimizerCursorTests::YieldUpdate>(); add<QueryOptimizerCursorTests::YieldDrop>(); add<QueryOptimizerCursorTests::YieldDropOr>(); + add<QueryOptimizerCursorTests::YieldRemoveOr>(); add<QueryOptimizerCursorTests::YieldCappedOverwrite>(); add<QueryOptimizerCursorTests::YieldDropIndex>(); add<QueryOptimizerCursorTests::YieldMultiplePlansNoOp>(); add<QueryOptimizerCursorTests::YieldMultiplePlansAdvanceNoOp>(); add<QueryOptimizerCursorTests::YieldMultiplePlansDelete>(); + add<QueryOptimizerCursorTests::YieldMultiplePlansDeleteOr>(); + add<QueryOptimizerCursorTests::YieldMultiplePlansDeleteOrAdvance>(); add<QueryOptimizerCursorTests::YieldMultiplePlansCappedOverwrite>(); add<QueryOptimizerCursorTests::YieldMultiplePlansCappedOverwriteManual>(); add<QueryOptimizerCursorTests::YieldMultiplePlansCappedOverwriteManual2>(); diff --git a/dbtests/queryutiltests.cpp b/dbtests/queryutiltests.cpp index e825b4f..c3dd64d 100644 --- a/dbtests/queryutiltests.cpp +++ b/dbtests/queryutiltests.cpp @@ -238,7 +238,14 @@ namespace QueryUtilTests { } }; - class QueryPatternTest { + class QueryPatternBase { + protected: + static QueryPattern p( const BSONObj &query, const BSONObj &sort = BSONObj() ) { + return FieldRangeSet( "", query, true ).pattern( sort ); + } + }; + + class QueryPatternTest : public QueryPatternBase { public: void run() { ASSERT( p( BSON( "a" << 1 ) ) == p( BSON( "a" << 1 ) ) ); @@ -258,12 +265,17 @@ namespace QueryUtilTests { ASSERT( p( BSON( "a" << 1 ), BSON( "b" << 1 << "c" << 1 ) ) != p( BSON( "a" << 4 ), BSON( "b" << 1 ) ) ); ASSERT( p( BSON( "a" << 1 ), BSON( "b" << 1 ) ) != p( BSON( "a" << 4 ), BSON( "b" << 1 << "c" << 1 ) ) ); } - private: - static QueryPattern p( const BSONObj &query, const BSONObj &sort = BSONObj() ) { - return FieldRangeSet( "", query, true ).pattern( sort ); + }; + + class QueryPatternNeConstraint : public QueryPatternBase { + public: + void run() { + ASSERT( p( BSON( "a" << NE << 5 ) ) != p( BSON( "a" << GT << 1 ) ) ); + ASSERT( p( BSON( "a" << NE << 5 ) ) != p( BSONObj() ) ); + ASSERT( p( BSON( "a" << NE << 5 ) ) == p( BSON( "a" << NE << "a" ) ) ); } }; - + class NoWhere { public: void run() { @@ -902,6 +914,7 @@ namespace QueryUtilTests { add< FieldRangeTests::Equality >(); add< FieldRangeTests::SimplifiedQuery >(); add< FieldRangeTests::QueryPatternTest >(); + add< FieldRangeTests::QueryPatternNeConstraint >(); add< FieldRangeTests::NoWhere >(); add< FieldRangeTests::Numeric >(); add< FieldRangeTests::InLowerBound >(); |