diff options
author | Alberto Lerner <alerner@10gen.com> | 2013-01-13 23:16:36 -0500 |
---|---|---|
committer | Alberto Lerner <alerner@10gen.com> | 2013-01-15 17:34:15 -0500 |
commit | 503672094dcc6370bc015638cc36c0a306cf2996 (patch) | |
tree | 4eba7c67652b39dffff62fbdb661ffee5913366d /src/mongo/dbtests/updatetests.cpp | |
parent | 402d5c7cde95110610098a3daeba13503b494789 (diff) | |
download | mongo-503672094dcc6370bc015638cc36c0a306cf2996.tar.gz |
SERVER-8008 Moved checks for sort pattern to early and performed them only once per update.
Diffstat (limited to 'src/mongo/dbtests/updatetests.cpp')
-rw-r--r-- | src/mongo/dbtests/updatetests.cpp | 64 |
1 files changed, 42 insertions, 22 deletions
diff --git a/src/mongo/dbtests/updatetests.cpp b/src/mongo/dbtests/updatetests.cpp index 4cf5b5e0832..196cfbd058e 100644 --- a/src/mongo/dbtests/updatetests.cpp +++ b/src/mongo/dbtests/updatetests.cpp @@ -1259,35 +1259,55 @@ namespace UpdateTests { } }; - class PushSortInvalidSortPattern { + class PushSortInvalidSortPattern : public SetBase { public: void run() { - vector<BSONObj> dummy; + // Sort pattern validation is made during update command checking. Therefore, to + // catch bad patterns, we have to write updated that use them. + + BSONObj expected = fromjson( "{'_id':0,x:[{a:1}, {a:2}]}" ); + client().insert( ns(), expected ); + + // { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {a..d:1} } } } + BSONObj pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << + "$slice" << -2 << + "$sort" << BSON( "a..d" << 1 ) ); + client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + BSONObj result = client().findOne( ns(), Query() ); + ASSERT_EQUALS( result, expected ); - ASSERT_THROWS( sort( dummy.begin(), - dummy.end(), - ProjectKeyCmp( fromjson( "{'a..d':-1}" ) ) ), - UserException ); - ASSERT_THROWS( sort( dummy.begin(), - dummy.end(), - ProjectKeyCmp( fromjson( "{'a.':-1}" ) ) ), - UserException ); + // { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {a.:1} } } } + pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << + "$slice" << -2 << + "$sort" << BSON( "a." << 1 ) ); + client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + result = client().findOne( ns(), Query() ); + ASSERT_EQUALS( result, expected ); - ASSERT_THROWS( sort( dummy.begin(), - dummy.end(), - ProjectKeyCmp( fromjson( "{'.b':-1}" ) ) ), - UserException ); + // { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {.b:1} } } } + pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << + "$slice" << -2 << + "$sort" << BSON( ".b" << 1 ) ); + client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + result = client().findOne( ns(), Query() ); + ASSERT_EQUALS( result, expected ); - ASSERT_THROWS( sort( dummy.begin(), - dummy.end(), - ProjectKeyCmp( fromjson( "{'.':-1}" ) ) ), - UserException ); + // { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {.:1} } } } + pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << + "$slice" << -2 << + "$sort" << BSON( "." << 1 ) ); + client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + result = client().findOne( ns(), Query() ); + ASSERT_EQUALS( result, expected ); - ASSERT_THROWS( sort( dummy.begin(), - dummy.end(), - ProjectKeyCmp( fromjson( "{'':-1}" ) ) ), - UserException ); + // { $push : { x : { $each : [ {a:3} ], $slice:-2, $sort : {'':1} } } } + pushObj = BSON( "$each" << BSON_ARRAY( BSON( "a" << 3 ) ) << + "$slice" << -2 << + "$sort" << BSON( "" << 1 ) ); + client().update( ns(), Query(), BSON( "$push" << BSON( "x" << pushObj ) ) ); + result = client().findOne( ns(), Query() ); + ASSERT_EQUALS( result, expected ); } }; |