diff options
author | Siyuan Zhou <siyuan.zhou@mongodb.com> | 2014-02-19 12:45:53 -0500 |
---|---|---|
committer | Matt Kangas <matt.kangas@mongodb.com> | 2014-03-03 22:54:10 -0500 |
commit | 3660343e0b4627d2fee4afb89b74d32644d16d18 (patch) | |
tree | ffa571e0b73ce56d73c2ae23f458f0db772ef782 /jstests/core/mr_merge.js | |
parent | 9fae141a1f3fe652fa6002e47722c5ceb051cffb (diff) | |
download | mongo-3660343e0b4627d2fee4afb89b74d32644d16d18.tar.gz |
SERVER-12127 migrate js tests to jscore suite when not related to writes
Migrate js tests starting from j-z.
Include SERVER-12920 Update use_power_of_2.js
Signed-off-by: Matt Kangas <matt.kangas@mongodb.com>
Diffstat (limited to 'jstests/core/mr_merge.js')
-rw-r--r-- | jstests/core/mr_merge.js | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/jstests/core/mr_merge.js b/jstests/core/mr_merge.js new file mode 100644 index 00000000000..9350c45f773 --- /dev/null +++ b/jstests/core/mr_merge.js @@ -0,0 +1,60 @@ + +t = db.mr_merge; +t.drop(); + +t.insert( { a : [ 1 , 2 ] } ) +t.insert( { a : [ 2 , 3 ] } ) +t.insert( { a : [ 3 , 4 ] } ) + +outName = "mr_merge_out"; +out = db[outName]; +out.drop(); + +m = function(){ for (i=0; i<this.a.length; i++ ) emit( this.a[i] , 1 ); } +r = function(k,vs){ return Array.sum( vs ); } + +function tos( o ){ + var s = ""; + for ( var i=0; i<100; i++ ){ + if ( o[i] ) + s += i + "_" + o[i]; + } + return s; +} + + +res = t.mapReduce( m , r , { out : outName } ) + + +expected = { "1" : 1 , "2" : 2 , "3" : 2 , "4" : 1 } +assert.eq( tos( expected ) , tos( res.convertToSingleObject() ) , "A" ); + +t.insert( { a : [ 4 , 5 ] } ) +out.insert( { _id : 10 , value : "5" } ) +res = t.mapReduce( m , r , { out : outName } ) + +expected["4"]++; +expected["5"] = 1 +assert.eq( tos( expected ) , tos( res.convertToSingleObject() ) , "B" ); + +t.insert( { a : [ 5 , 6 ] } ) +out.insert( { _id : 10 , value : "5" } ) +res = t.mapReduce( m , r , { out : { merge : outName } } ) + +expected["5"]++; +expected["10"] = 5 +expected["6"] = 1 + +assert.eq( tos( expected ) , tos( res.convertToSingleObject() ) , "C" ); + +// test that the nonAtomic output gives valid result +t.insert( { a : [ 6 , 7 ] } ) +out.insert( { _id : 20 , value : "10" } ) +res = t.mapReduce( m , r , { out : { merge : outName, nonAtomic: true } } ) + +expected["6"]++; +expected["20"] = 10 +expected["7"] = 1 + +assert.eq( tos( expected ) , tos( res.convertToSingleObject() ) , "D" ); + |