From 2bdd75901fba402068d08e316a3ac32249307e27 Mon Sep 17 00:00:00 2001 From: John Christopher Anderson Date: Fri, 26 Feb 2010 01:11:02 +0000 Subject: fdmananas patch for filtered replication via COUCHDB-673 git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@916518 13f79535-47bb-0310-9956-ffa450edef68 --- share/www/script/test/replication.js | 77 ++++++++++++++++++++++++++++++++++++ 1 file changed, 77 insertions(+) (limited to 'share/www/script/test/replication.js') diff --git a/share/www/script/test/replication.js b/share/www/script/test/replication.js index a5ed5110..c6f6ff61 100644 --- a/share/www/script/test/replication.js +++ b/share/www/script/test/replication.js @@ -377,4 +377,81 @@ couchTests.replication = function(debug) { T(docFoo666 === null); } + // test filtered replication + + var sourceDb = new CouchDB( + "test_suite_filtered_rep_db_a", {"X-Couch-Full-Commit":"false"} + ); + + sourceDb.deleteDb(); + sourceDb.createDb(); + + T(sourceDb.save({_id:"foo1",value:1}).ok); + T(sourceDb.save({_id:"foo2",value:2}).ok); + T(sourceDb.save({_id:"foo3",value:3}).ok); + T(sourceDb.save({_id:"foo4",value:4}).ok); + T(sourceDb.save({ + "_id": "_design/mydesign", + "language" : "javascript", + "filters" : { + "myfilter" : (function(doc, req) { + if (doc.value < Number(req.query.maxvalue)) { + return true; + } else { + return false; + } + }).toString() + } + }).ok); + + var dbPairs = [ + {source:"test_suite_filtered_rep_db_a", + target:"test_suite_filtered_rep_db_b"}, + {source:"test_suite_filtered_rep_db_a", + target:"http://" + host + "/test_suite_filtered_rep_db_b"}, + {source:"http://" + host + "/test_suite_filtered_rep_db_a", + target:"test_suite_filtered_rep_db_b"}, + {source:"http://" + host + "/test_suite_filtered_rep_db_a", + target:"http://" + host + "/test_suite_filtered_rep_db_b"} + ]; + + for (var i = 0; i < dbPairs.length; i++) { + var targetDb = new CouchDB("test_suite_filtered_rep_db_b"); + targetDb.deleteDb(); + targetDb.createDb(); + + var dbA = dbPairs[i].source; + var dbB = dbPairs[i].target; + + var repResult = CouchDB.replicate(dbA, dbB, { + body: { + "filter" : "mydesign/myfilter", + "query_params" : { + "maxvalue": "3" + } + } + }); + + T(repResult.ok); + T($.isArray(repResult.history)); + T(repResult.history.length === 1); + T(repResult.history[0].docs_written === 2); + T(repResult.history[0].docs_read === 2); + T(repResult.history[0].doc_write_failures === 0); + + var docFoo1 = targetDb.open("foo1"); + T(docFoo1 !== null); + T(docFoo1.value === 1); + + var docFoo2 = targetDb.open("foo2"); + T(docFoo2 !== null); + T(docFoo2.value === 2); + + var docFoo3 = targetDb.open("foo3"); + T(docFoo3 === null); + + var docFoo4 = targetDb.open("foo4"); + T(docFoo4 === null); + } + }; -- cgit v1.2.3