diff options
author | Adam Midvidy <amidvidy@gmail.com> | 2016-02-16 13:53:45 -0500 |
---|---|---|
committer | Adam Midvidy <amidvidy@gmail.com> | 2016-02-16 13:53:45 -0500 |
commit | 62ebc18691ef982d15506d8e50204c5a32897e5f (patch) | |
tree | 65324f726e218c3d6ca39317305cfecdcf506b9d /jstests/readonly | |
parent | 1c7404095583a712d9e946e2751572c8973f13aa (diff) | |
download | mongo-62ebc18691ef982d15506d8e50204c5a32897e5f.tar.gz |
SERVER-22354 add more coverage of basic functionality to readOnly suite
Diffstat (limited to 'jstests/readonly')
-rw-r--r-- | jstests/readonly/aggregate.js | 98 | ||||
-rw-r--r-- | jstests/readonly/count.js | 37 | ||||
-rw-r--r-- | jstests/readonly/distinct.js | 42 | ||||
-rw-r--r-- | jstests/readonly/geo.js | 38 | ||||
-rw-r--r-- | jstests/readonly/lib/read_only_test.js | 40 | ||||
-rw-r--r-- | jstests/readonly/server_status.js | 15 |
6 files changed, 263 insertions, 7 deletions
diff --git a/jstests/readonly/aggregate.js b/jstests/readonly/aggregate.js new file mode 100644 index 00000000000..3bfaeab6a20 --- /dev/null +++ b/jstests/readonly/aggregate.js @@ -0,0 +1,98 @@ +load('jstests/readonly/lib/read_only_test.js'); + +runReadOnlyTest(function() { + 'use strict'; + return { + name: 'aggregate', + + load: function(writableCollection) { + assert.doesNotThrow(() => { writableCollection.insertMany([ + {award: "Best Picture", + nominations: [ + {title: "The Big Short"}, + {title: "Bridge of Spies"}, + {title: "Brooklyn"}, + {title: "Max Max: Fury Road"}, + {title: "The Martian"}, + {title: "The Revenant"}, + {title: "Room"}, + {title: "Spotlight"} + ] + }, + {award: "Best Actor", + nominations: [ + {title: "Trumbo", + person: "Bryan Cranston"}, + {title: "The Martian", + person: "Matt Damon"}, + {title: "The Revenant", + person: "Leonardo DiCaprio"}, + {title: "Steve Jobs", + person: "Michael Fassbender"}, + {title: "The Danish Girl", + person: "Eddie Redmayne"} + ] + }, + {award: "Best Actress", + nominations: [ + {title: "Carol", + person: "Cate Blanchett"}, + {title: "Room", + person: "Brie Larson"}, + {title: "Joy", + person: "Jennifer Lawrence"}, + {title: "45 Years", + person: "Charlotte Rampling"}, + {title: "Brooklyn", + person: "Saoirse Ronan"} + ] + }, + {award: "Best Supporting Actor", + nominations: [ + {title: "The Big Short", + person: "Christian Bale"}, + {title: "The Revenant", + person: "Tom Hardy"}, + {title: "Spotlight", + person: "Mark Ruffalo"}, + {title: "Bridge Of Spies", + person: "Mark Rylance"}, + {title: "Creed", + person: "Sylvester Stallone"} + ] + }, + {award: "Best Supporting Actress", + nominations: [ + {title: "The Hateful Eight", + person: "Jennifer Jason Leigh"}, + {title: "Carol", + person: "Rooney Mara"}, + {title: "Spotlight", + person: "Rachel McAdams"}, + {title: "The Danish Girl", + person: "Alicia Vikander"}, + {title: "Steve Jobs", + person: "Kate Winslet"} + ] + } + ]); }); + }, + exec: function(readableCollection) { + + // Find titles nominated for the most awards. + var mostAwardsPipeline = [ + {$unwind: "$nominations"}, + {$group: { + _id: "$nominations.title", + count: {$sum: 1}}}, + {$sort: {count: -1}}, + {$limit: 2} + ]; + + assert.docEq(readableCollection.aggregate(mostAwardsPipeline).toArray(), [ + {_id: "The Revenant", count: 3}, + {_id: "Spotlight", count: 3} + ]); + } + }; +}()); diff --git a/jstests/readonly/count.js b/jstests/readonly/count.js new file mode 100644 index 00000000000..62571f9d7a0 --- /dev/null +++ b/jstests/readonly/count.js @@ -0,0 +1,37 @@ +load('jstests/readonly/lib/read_only_test.js'); + +runReadOnlyTest(function() { + 'use strict' ; + return { + name: 'count', + + count: 100, + countLt10: 10, + countEq35: 2, + countGte10: 90, + + load: function(writableCollection) { + var bulk = writableCollection.initializeUnorderedBulkOp(); + + for (var i = 0; i < this.countLt10; ++i) { + bulk.insert({x: 5}); + } + + for (var i = 0; i < this.countEq35; ++i) { + bulk.insert({x: 35}); + } + + for (var i = 0; i < this.countGte10 - this.countEq35; ++i) { + bulk.insert({x: 70}); + } + + assert.writeOK(bulk.execute()); + }, + exec: function(readableCollection) { + assert.eq(readableCollection.find({x: {$lt : 10}}).count(), this.countLt10); + assert.eq(readableCollection.find({x: {$eq : 35}}).count(), this.countEq35); + assert.eq(readableCollection.find({x: {$gte : 10}}).count(), this.countGte10); + assert.eq(readableCollection.count(), this.count); + } + }; +}()); diff --git a/jstests/readonly/distinct.js b/jstests/readonly/distinct.js new file mode 100644 index 00000000000..b269d3eae68 --- /dev/null +++ b/jstests/readonly/distinct.js @@ -0,0 +1,42 @@ +load('jstests/readonly/lib/read_only_test.js'); + +runReadOnlyTest(function() { + 'use strict'; + return { + name: 'find', + + colors: ['blue', 'green', 'orange', 'white'], + nums: [1, 2, 3, 4, 5, 6], + + load: function(writableCollection) { + var N = 1000; + + this.colors.sort(); + this.nums.sort(); + + var bulk = writableCollection.initializeUnorderedBulkOp(); + + for (var [color, num] of zip2(cycleN(this.colors, N), cycleN(this.nums, N))) { + bulk.insert({color, num}); + } + assert.writeOK(bulk.execute()); + }, + exec: function(readableCollection) { + var distinctColors = readableCollection.distinct('color'); + var distinctNums = readableCollection.distinct('num'); + + distinctColors.sort(); + distinctNums.sort(); + + assert.eq(distinctColors.length, this.colors.length); + for (var i = 0; i < distinctColors; ++i) { + assert.eq(distinctColors[i], this.colors[i]); + } + + assert.eq(distinctNums.length, this.nums.length); + for (var i = 0; i < distinctNums; ++i) { + assert.eq(distinctNums[i], this.nums[i]); + } + } + }; +}()); diff --git a/jstests/readonly/geo.js b/jstests/readonly/geo.js new file mode 100644 index 00000000000..1127a70a18f --- /dev/null +++ b/jstests/readonly/geo.js @@ -0,0 +1,38 @@ +load('jstests/readonly/lib/read_only_test.js'); + +runReadOnlyTest(function() { + 'use strict'; + + return { + name: 'geo', + + load: function(writableCollection) { + assert.commandWorked(writableCollection.createIndex({loc: "2dsphere"})); + + var locDocs = [ + {name: "Berry Park", + loc: {type: "Point", coordinates: [40.722396, -73.9573645]}}, + {name: "Northern Territory", + loc: {type: "Point", coordinates: [40.7252334, -73.9595218]}}, + {name: "Kent Ale House", + loc: {type: "Point", coordinates: [40.7223364, -73.9614495]}}, + {name: "The Shanty", + loc: {type: "Point", coordinates: [40.7185752, -73.9510538]}}, + {name: "The Counting Room", + loc: {type: "Point", coordinates: [40.7209601, -73.9588041]}}, + {name: "Kinfolk 94", + loc: {type: "Point", coordinates: [40.7217058, -73.9605489]}} + ]; + + writableCollection.insertMany(locDocs); + }, + exec: function(readableCollection) { + var res = readableCollection.find({loc: {$near: { + $geometry: { + type: "Point", + coordinates: [40.7211404, -73.9591494] + }}}}).limit(1).toArray(); + assert.eq(res[0].name, "The Counting Room"); + } + }; +}()); diff --git a/jstests/readonly/lib/read_only_test.js b/jstests/readonly/lib/read_only_test.js index 6d144d6e0f8..f2e52ae7157 100644 --- a/jstests/readonly/lib/read_only_test.js +++ b/jstests/readonly/lib/read_only_test.js @@ -2,9 +2,11 @@ function runReadOnlyTest(test) { - assert.eq(typeof(test.exec), "function"); - assert.eq(typeof(test.load), "function"); - assert.eq(typeof(test.name), "string"); + printjson(test); + + assert.eq(typeof(test.exec), 'function'); + assert.eq(typeof(test.load), 'function'); + assert.eq(typeof(test.name), 'string'); // TODO: read storageEngine from testData when read-only mode is supported in WiredTiger. var options = { @@ -15,8 +17,8 @@ function runReadOnlyTest(test) { var writableMongod = MongoRunner.runMongod(options); var dbpath = writableMongod.dbpath; - jsTest.log("starting load phase for test: " + test.name); - test.load(writableMongod.getDB("test")[test.name]); + jsTest.log('starting load phase for test: ' + test.name); + test.load(writableMongod.getDB('test')[test.name]); MongoRunner.stopMongod(writableMongod); @@ -28,8 +30,32 @@ function runReadOnlyTest(test) { var readOnlyMongod = MongoRunner.runMongod(readOnlyOptions); - jsTest.log("starting execution phase for test: " + test.name); - test.exec(readOnlyMongod.getDB("test")[test.name]); + jsTest.log('starting execution phase for test: ' + test.name); + test.exec(readOnlyMongod.getDB('test')[test.name]); MongoRunner.stopMongod(readOnlyMongod); } + +function* cycleN(arr, N) { + for (var i = 0; i < N; ++i) { + yield arr[i % arr.length]; + } +}; + +function* zip2(iter1, iter2) { + var n1 = iter1.next(); + var n2 = iter2.next(); + while (!n1.done || !n2.done) { + var res = []; + if (!n1.done) { + res.push(n1.value); + n1 = iter1.next(); + } + if (!n2.done) { + res.push(n2.value); + n2 = iter2.next(); + } + + yield res; + } +}; diff --git a/jstests/readonly/server_status.js b/jstests/readonly/server_status.js new file mode 100644 index 00000000000..cbb70f52560 --- /dev/null +++ b/jstests/readonly/server_status.js @@ -0,0 +1,15 @@ +load('jstests/readonly/lib/read_only_test.js'); + +runReadOnlyTest(function() { + 'use strict'; + + return { + name: 'server_status', + + load: function(writableCollection) { + }, + exec: function(readableCollection) { + assert.commandWorked(readableCollection.getDB().serverStatus()); + } + }; +}()); |