summaryrefslogtreecommitdiff
path: root/share
diff options
context:
space:
mode:
authorJohn Christopher Anderson <jchris@apache.org>2009-02-15 20:36:53 +0000
committerJohn Christopher Anderson <jchris@apache.org>2009-02-15 20:36:53 +0000
commit146bc594aef47b675670e7a7fd7f89b7c6a10843 (patch)
tree4f1ea083353560951b640f8c1ceaaf728e2def65 /share
parentc91f851dc421466402721eb7baa644860f874ce1 (diff)
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
Diffstat (limited to 'share')
-rw-r--r--share/www/script/couch_tests.js97
1 files changed, 87 insertions, 10 deletions
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");
}