From 146bc594aef47b675670e7a7fd7f89b7c6a10843 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Sun, 15 Feb 2009 20:36:53 +0000 Subject: View etags are now provided. See note in the source about how they could be more efficient. Changes arity on make_view_fold_fun etc. Closes COUCHDB-4 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@744747 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/couch_tests.js | 97 ++++++++++++++++++++++++++++++++++++----- 1 file changed, 87 insertions(+), 10 deletions(-) (limited to 'share/www/script/couch_tests.js') diff --git a/share/www/script/couch_tests.js b/share/www/script/couch_tests.js index 0ffee4cd..7cf2c6a4 100644 --- a/share/www/script/couch_tests.js +++ b/share/www/script/couch_tests.js @@ -2425,17 +2425,87 @@ db.createDb(); }); T(xhr.status == 200); }, + etags_views: function(debug) { + var db = new CouchDB("test_suite_db"); + db.deleteDb(); + db.createDb(); + if (debug) debugger; + + var designDoc = { + _id:"_design/etags", + language: "javascript", + views : { + basicView : { + map : stringFun(function(doc) { + emit(doc.integer, doc.string); + }) + }, + withReduce : { + map : stringFun(function(doc) { + emit(doc.integer, doc.string); + }), + reduce : stringFun(function(keys, values, rereduce) { + if (rereduce) { + return sum(values); + } else { + return values.length; + } + }) + } + } + } + T(db.save(designDoc).ok); + var xhr; + var docs = makeDocs(0, 10); + var saveResult = db.bulkSave(docs); + T(saveResult.ok); + + // verify get w/Etag on map view + xhr = CouchDB.request("GET", "/test_suite_db/_view/etags/basicView"); + T(xhr.status == 200); + var etag = xhr.getResponseHeader("etag"); + xhr = CouchDB.request("GET", "/test_suite_db/_view/etags/basicView", { + headers: {"if-none-match": etag} + }); + T(xhr.status == 304); + // TODO GET with keys (when that is available) + + // reduce view + xhr = CouchDB.request("GET", "/test_suite_db/_view/etags/withReduce"); + T(xhr.status == 200); + var etag = xhr.getResponseHeader("etag"); + xhr = CouchDB.request("GET", "/test_suite_db/_view/etags/withReduce", { + headers: {"if-none-match": etag} + }); + T(xhr.status == 304); + + // all docs + xhr = CouchDB.request("GET", "/test_suite_db/_all_docs"); + T(xhr.status == 200); + var etag = xhr.getResponseHeader("etag"); + xhr = CouchDB.request("GET", "/test_suite_db/_all_docs", { + headers: {"if-none-match": etag} + }); + T(xhr.status == 304); + + // by seq + xhr = CouchDB.request("GET", "/test_suite_db/_all_docs_by_seq"); + T(xhr.status == 200); + var etag = xhr.getResponseHeader("etag"); + xhr = CouchDB.request("GET", "/test_suite_db/_all_docs_by_seq", { + headers: {"if-none-match": etag} + }); + T(xhr.status == 304); + + // list etag + // in the list test for now + }, show_documents: function(debug) { var db = new CouchDB("test_suite_db"); db.deleteDb(); db.createDb(); if (debug) debugger; - - function stringFun(fun) { - var string = fun.toSource ? fun.toSource() : "(" + fun.toString() + ")"; - return string; - } var designDoc = { _id:"_design/template", @@ -2706,11 +2776,6 @@ db.createDb(); db.deleteDb(); db.createDb(); if (debug) debugger; - - function stringFun(fun) { - var string = fun.toSource ? fun.toSource() : "(" + fun.toString() + ")"; - return string; - } var designDoc = { _id:"_design/lists", @@ -2850,6 +2915,13 @@ db.createDb(); var lines = xhr.responseText.split('\n'); T(/LineNo: 5/.test(lines[6])); + // test that etags are available + var etag = xhr.getResponseHeader("etag"); + xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/simpleForm/basicView", { + headers: {"if-none-match": etag} + }); + T(xhr.status == 304); + // get with query params var xhr = CouchDB.request("GET", "/test_suite_db/_list/lists/simpleForm/basicView?startkey=3"); T(xhr.status == 200); @@ -3313,6 +3385,11 @@ function run_on_modified_server(settings, fun) { } } +function stringFun(fun) { + var string = fun.toSource ? fun.toSource() : "(" + fun.toString() + ")"; + return string; +} + function restartServer() { CouchDB.request("POST", "/_restart"); } -- cgit v1.2.3