diff options
author | Paul Joseph Davis <davisp@apache.org> | 2009-03-17 03:47:37 +0000 |
---|---|---|
committer | Paul Joseph Davis <davisp@apache.org> | 2009-03-17 03:47:37 +0000 |
commit | c97712350df0161ab41bcaca26afe7ae4e1cc91b (patch) | |
tree | f9a3d6fe09fde88b031ae52f607cf6cecf427112 /share | |
parent | 3b2787badaf54be2b6b5353dbd1b0af5ccff1db4 (diff) |
Closes COUCHDB-135 View offset regression after 0.8.1
This test shows that Damien's changes to couch_btree.erl have alleviated the
offset regersion reported by Paul Carey.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@755105 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share')
-rw-r--r-- | share/Makefile.am | 1 | ||||
-rw-r--r-- | share/www/script/couch_tests.js | 1 | ||||
-rw-r--r-- | share/www/script/test/view_offsets.js | 101 |
3 files changed, 103 insertions, 0 deletions
diff --git a/share/Makefile.am b/share/Makefile.am index 3cabe166..f92ca16b 100644 --- a/share/Makefile.am +++ b/share/Makefile.am @@ -100,6 +100,7 @@ nobase_dist_localdata_DATA = \ www/script/test/view_multi_key_all_docs.js \ www/script/test/view_multi_key_design.js \ www/script/test/view_multi_key_temp.js \ + www/script/test/view_offsets.js \ www/script/test/view_pagination.js \ www/script/test/view_sandboxing.js \ www/script/test/view_xml.js \ diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 8ba1f76d..3d2585e8 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -55,6 +55,7 @@ loadTest("view_include_docs.js"); loadTest("view_multi_key_all_docs.js"); loadTest("view_multi_key_design.js"); loadTest("view_multi_key_temp.js"); +loadTest("view_offsets.js"); loadTest("view_pagination.js"); loadTest("view_sandboxing.js"); loadTest("view_xml.js"); diff --git a/share/www/script/test/view_offsets.js b/share/www/script/test/view_offsets.js new file mode 100644 index 00000000..97cd6b97 --- /dev/null +++ b/share/www/script/test/view_offsets.js @@ -0,0 +1,101 @@ +// Licensed under the Apache License, Version 2.0 (the "License"); you may not +// use this file except in compliance with the License. You may obtain a copy +// of the License at +// +// http://www.apache.org/licenses/LICENSE-2.0 +// +// Unless required by applicable law or agreed to in writing, software +// distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +// WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +// License for the specific language governing permissions and limitations under +// the License. + +couchTests.view_offsets = function(debug) { + if (debug) debugger; + + var db = new CouchDB("test_suite_db"); + db.deleteDb(); + db.createDb(); + + var designDoc = { + _id : "_design/test", + views : { + offset : { + map : "function(doc) { emit([doc.letter, doc.number], doc); }", + } + } + }; + T(db.save(designDoc).ok); + + var docs = [ + {_id : "a1", letter : "a", number : 1, foo: "bar"}, + {_id : "a2", letter : "a", number : 2, foo: "bar"}, + {_id : "a3", letter : "a", number : 3, foo: "bar"}, + {_id : "b1", letter : "b", number : 1, foo: "bar"}, + {_id : "b2", letter : "b", number : 2, foo: "bar"}, + {_id : "b3", letter : "b", number : 3, foo: "bar"}, + {_id : "b4", letter : "b", number : 4, foo: "bar"}, + {_id : "b5", letter : "b", number : 5, foo: "bar"}, + {_id : "c1", letter : "c", number : 1, foo: "bar"}, + {_id : "c2", letter : "c", number : 2, foo: "bar"}, + ]; + db.bulkSave(docs); + + var check = function(startkey, offset) { + var opts = {startkey: startkey, descending: true, reduce: false}; + T(db.view("test/offset", opts).offset == offset); + }; + + [ + [["c", 2], 0], + [["c", 1], 1], + [["b", 5], 2], + [["b", 4], 3], + [["b", 3], 4], + [["b", 2], 5], + [["b", 1], 6], + [["a", 3], 7], + [["a", 2], 8], + [["a", 1], 9] + ].forEach(function(row){ check(row[0], row[1]);}); + + var runTest = function () { + var db = new CouchDB("test_suite_db"); + db.deleteDb(); + db.createDb(); + + var designDoc = { + _id : "_design/test", + views : { + offset : { + map : "function(doc) { emit([doc.letter, doc.number], doc);}", + } + } + }; + T(db.save(designDoc).ok); + + var docs = [ + {_id : "a1", letter : "a", number : 1, foo : "bar"}, + {_id : "a2", letter : "a", number : 2, foo : "bar"}, + {_id : "a3", letter : "a", number : 3, foo : "bar"}, + {_id : "b1", letter : "b", number : 1, foo : "bar"}, + {_id : "b2", letter : "b", number : 2, foo : "bar"}, + {_id : "b3", letter : "b", number : 3, foo : "bar"}, + {_id : "b4", letter : "b", number : 4, foo : "bar"}, + {_id : "b5", letter : "b", number : 5, foo : "bar"}, + {_id : "c1", letter : "c", number : 1, foo : "bar"}, + {_id : "c2", letter : "c", number : 2, foo : "bar"} + ]; + db.bulkSave(docs); + + var res = db.view("test/offset", { + startkey: ["b",4], startkey_docid: "b4", endkey: ["b"], + limit: 2, descending: true, skip: 1, reduce: false + }) + + return res.offset == 4; + }; + + for(var i = 0; i < 15; i++) T(runTest()); +} + |