diff options
Diffstat (limited to 'src/mongo/dbtests/querytests.cpp')
-rw-r--r-- | src/mongo/dbtests/querytests.cpp | 40 |
1 files changed, 21 insertions, 19 deletions
diff --git a/src/mongo/dbtests/querytests.cpp b/src/mongo/dbtests/querytests.cpp index decd6867e99..c9cf3886711 100644 --- a/src/mongo/dbtests/querytests.cpp +++ b/src/mongo/dbtests/querytests.cpp @@ -196,6 +196,7 @@ namespace QueryTests { _prevError = mongo::lastError._get( false ); mongo::lastError.release(); mongo::lastError.reset( new LastError() ); + _txn.getCurOp()->reset(); } virtual ~ClientBase() { mongo::lastError.reset( _prevError ); @@ -231,7 +232,7 @@ namespace QueryTests { a.appendMaxKey( "$lt" ); BSONObj limit = a.done(); ASSERT( !_client.findOne( ns, QUERY( "a" << limit ) ).isEmpty() ); - _client.ensureIndex( ns, BSON( "a" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns, BSON( "a" << 1 ) )); ASSERT( !_client.findOne( ns, QUERY( "a" << limit ).hint( BSON( "a" << 1 ) ) ).isEmpty() ); } }; @@ -691,7 +692,7 @@ namespace QueryTests { } void run() { const char *ns = "unittests.querytests.BasicCount"; - _client.ensureIndex( ns, BSON( "a" << 1 ) ); + ASSERT_OK(dbtests::createIndex(&_txn, ns, BSON( "a" << 1 ) )); count( 0 ); insert( ns, BSON( "a" << 3 ) ); count( 0 ); @@ -715,7 +716,7 @@ namespace QueryTests { } void run() { const char *ns = "unittests.querytests.ArrayId"; - _client.ensureIndex( ns, BSON( "_id" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns, BSON( "_id" << 1 ) )); ASSERT( !error() ); _client.insert( ns, fromjson( "{'_id':[1,2]}" ) ); ASSERT( error() ); @@ -786,7 +787,7 @@ namespace QueryTests { const char *ns = "unittests.querytests.NumericEmbedded"; _client.insert( ns, BSON( "a" << BSON ( "b" << 1 ) ) ); ASSERT( ! _client.findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() ); - _client.ensureIndex( ns , BSON( "a" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns , BSON( "a" << 1 ) )); ASSERT( ! _client.findOne( ns, BSON( "a" << BSON ( "b" << 1.0 ) ) ).isEmpty() ); } }; @@ -801,7 +802,7 @@ namespace QueryTests { void index() { ASSERT_EQUALS(2u, _client.getIndexSpecs(ns()).size()); } void noIndex() { ASSERT_EQUALS(0u, _client.getIndexSpecs(ns()).size()); } void checkIndex() { - _client.ensureIndex( ns(), BSON( "a" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns() , BSON( "a" << 1 ) )); index(); } void run() { @@ -824,12 +825,12 @@ namespace QueryTests { } void run() { const char *ns = "unittests.querytests.UniqueIndex"; - _client.ensureIndex( ns, BSON( "a" << 1 ), true ); + ASSERT_OK(dbtests::createIndex( &_txn, ns , BSON( "a" << 1 ), true )); _client.insert( ns, BSON( "a" << 4 << "b" << 2 ) ); _client.insert( ns, BSON( "a" << 4 << "b" << 3 ) ); ASSERT_EQUALS( 1U, _client.count( ns, BSONObj() ) ); _client.dropCollection( ns ); - _client.ensureIndex( ns, BSON( "b" << 1 ), true ); + ASSERT_OK(dbtests::createIndex( &_txn, ns , BSON( "b" << 1 ), true )); _client.insert( ns, BSON( "a" << 4 << "b" << 2 ) ); _client.insert( ns, BSON( "a" << 4 << "b" << 3 ) ); ASSERT_EQUALS( 2U, _client.count( ns, BSONObj() ) ); @@ -845,7 +846,8 @@ namespace QueryTests { const char *ns = "unittests.querytests.UniqueIndexPreexistingData"; _client.insert( ns, BSON( "a" << 4 << "b" << 2 ) ); _client.insert( ns, BSON( "a" << 4 << "b" << 3 ) ); - _client.ensureIndex( ns, BSON( "a" << 1 ), true ); + ASSERT_EQUALS(ErrorCodes::DuplicateKey, + dbtests::createIndex( &_txn, ns , BSON( "a" << 1 ), true )); ASSERT_EQUALS( 0U, _client.count( "unittests.system.indexes", BSON( "ns" << ns << "name" << NE << "_id_" ) ) ); } }; @@ -871,7 +873,7 @@ namespace QueryTests { void run() { const char *ns = "unittests.querytests.Size"; _client.insert( ns, fromjson( "{a:[1,2,3]}" ) ); - _client.ensureIndex( ns, BSON( "a" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns , BSON( "a" << 1 ) )); ASSERT( _client.query( ns, QUERY( "a" << mongo::BSIZE << 3 ).hint( BSON( "a" << 1 ) ) )->more() ); } }; @@ -885,7 +887,7 @@ namespace QueryTests { const char *ns = "unittests.querytests.IndexedArray"; _client.insert( ns, fromjson( "{a:[1,2,3]}" ) ); ASSERT( _client.query( ns, Query( "{a:[1,2,3]}" ) )->more() ); - _client.ensureIndex( ns, BSON( "a" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns , BSON( "a" << 1 ) )); ASSERT( _client.query( ns, Query( "{a:{$in:[1,[1,2,3]]}}" ).hint( BSON( "a" << 1 ) ) )->more() ); ASSERT( _client.query( ns, Query( "{a:[1,2,3]}" ).hint( BSON( "a" << 1 ) ) )->more() ); // SERVER-146 } @@ -900,7 +902,7 @@ namespace QueryTests { const char *ns = "unittests.querytests.InsideArray"; _client.insert( ns, fromjson( "{a:[[1],2]}" ) ); check( "$natural" ); - _client.ensureIndex( ns, BSON( "a" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns , BSON( "a" << 1 ) )); check( "a" ); // SERVER-146 } private: @@ -922,7 +924,7 @@ namespace QueryTests { const char *ns = "unittests.querytests.IndexInsideArrayCorrect"; _client.insert( ns, fromjson( "{'_id':1,a:[1]}" ) ); _client.insert( ns, fromjson( "{'_id':2,a:[[1]]}" ) ); - _client.ensureIndex( ns, BSON( "a" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns , BSON( "a" << 1 ) )); ASSERT_EQUALS( 1, _client.query( ns, Query( "{a:[1]}" ).hint( BSON( "a" << 1 ) ) )->next().getIntField( "_id" ) ); } }; @@ -936,7 +938,7 @@ namespace QueryTests { const char *ns = "unittests.querytests.SubobjArr"; _client.insert( ns, fromjson( "{a:[{b:[1]}]}" ) ); check( "$natural" ); - _client.ensureIndex( ns, BSON( "a" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns , BSON( "a" << 1 ) )); check( "a" ); } private: @@ -954,7 +956,7 @@ namespace QueryTests { _client.dropCollection( "unittests.querytests.MinMax" ); } void run() { - _client.ensureIndex( ns, BSON( "a" << 1 << "b" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns, BSON( "a" << 1 << "b" << 1 ) )); _client.insert( ns, BSON( "a" << 1 << "b" << 1 ) ); _client.insert( ns, BSON( "a" << 1 << "b" << 2 ) ); _client.insert( ns, BSON( "a" << 2 << "b" << 1 ) ); @@ -1010,7 +1012,7 @@ namespace QueryTests { } void run() { checkMatch(); - _client.ensureIndex( _ns, BSON( "a" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, _ns, BSON( "a" << 1 ) )); checkMatch(); } private: @@ -1047,7 +1049,7 @@ namespace QueryTests { } void run() { checkMatch(); - _client.ensureIndex( _ns, BSON( "a" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, _ns, BSON( "a" << 1 ) )); checkMatch(); } private: @@ -1085,7 +1087,7 @@ namespace QueryTests { void run() { const char *ns = "unittests.querytests.FastCountIn"; _client.insert( ns, BSON( "i" << "a" ) ); - _client.ensureIndex( ns, BSON( "i" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns, BSON( "i" << 1 ) )); ASSERT_EQUALS( 1U, _client.count( ns, fromjson( "{i:{$in:['a']}}" ) ) ); } }; @@ -1130,7 +1132,7 @@ namespace QueryTests { { BSONObjBuilder b; b.append( "7" , (double)3.7 ); _client.insert( ns , b.obj() ); } t(ns); - _client.ensureIndex( ns , BSON( "7" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns , BSON( "7" << 1 ) )); t(ns); } }; @@ -1181,7 +1183,7 @@ namespace QueryTests { ASSERT_EQUALS( 17 , _client.findOne( ns() , b.obj() )["z"].number() ); } ASSERT_EQUALS( 17 , _client.findOne( ns() , BSON( "x" << "eliot" ) )["z"].number() ); - _client.ensureIndex( ns() , BSON( "x" << 1 ) ); + ASSERT_OK(dbtests::createIndex( &_txn, ns() , BSON( "x" << 1 ) )); ASSERT_EQUALS( 17 , _client.findOne( ns() , BSON( "x" << "eliot" ) )["z"].number() ); } }; |