diff options
author | Filipe David Borba Manana <fdmanana@apache.org> | 2010-09-28 16:49:58 +0000 |
---|---|---|
committer | Filipe David Borba Manana <fdmanana@apache.org> | 2010-09-28 16:49:58 +0000 |
commit | cff79d01f26f2a4917204fcf3dd8d4d4d57271bc (patch) | |
tree | e9aa1fe88e1a3e8ab6485ede62bbe84824d544e6 /share/www | |
parent | 7665e449cdfff1e660ed2bbac3de4507cb063a18 (diff) |
Replicator fix: for a filtered replication, the replication ID should take into account the filter function's code and not only its name.
Closes COUCHDB-892.
git-svn-id: https://svn.apache.org/repos/asf/couchdb/trunk@1002259 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'share/www')
-rw-r--r-- | share/www/script/test/replication.js | 94 |
1 files changed, 69 insertions, 25 deletions
diff --git a/share/www/script/test/replication.js b/share/www/script/test/replication.js index b92c3fcd..60051a67 100644 --- a/share/www/script/test/replication.js +++ b/share/www/script/test/replication.js @@ -452,31 +452,17 @@ couchTests.replication = function(debug) { } // 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() + var filterFun1 = (function(doc, req) { + if (doc.value < Number(req.query.maxvalue)) { + return true; + } else { + return false; } - }).ok); + }).toString(); + + var filterFun2 = (function(doc, req) { + return true; + }).toString(); var dbPairs = [ {source:"test_suite_filtered_rep_db_a", @@ -488,9 +474,28 @@ couchTests.replication = function(debug) { {source:CouchDB.protocol + host + "/test_suite_filtered_rep_db_a", target:CouchDB.protocol + host + "/test_suite_filtered_rep_db_b"} ]; + var sourceDb = new CouchDB("test_suite_filtered_rep_db_a"); + var targetDb = new CouchDB("test_suite_filtered_rep_db_b"); for (var i = 0; i < dbPairs.length; i++) { - var targetDb = new CouchDB("test_suite_filtered_rep_db_b"); + 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); + + var ddoc = { + "_id": "_design/mydesign", + "language": "javascript", + "filters": { + "myfilter": filterFun1 + } + }; + + T(sourceDb.save(ddoc).ok); + targetDb.deleteDb(); targetDb.createDb(); @@ -526,6 +531,45 @@ couchTests.replication = function(debug) { var docFoo4 = targetDb.open("foo4"); T(docFoo4 === null); + + // replication should start from scratch after the filter's code changed + + ddoc.filters.myfilter = filterFun2; + T(sourceDb.save(ddoc).ok); + + repResult = CouchDB.replicate(dbA, dbB, { + body: { + "filter" : "mydesign/myfilter", + "query_params" : { + "maxvalue": "3" + } + } + }); + + T(repResult.ok); + T(repResult.history instanceof Array); + T(repResult.history.length === 1); + T(repResult.history[0].docs_written === 3); + T(repResult.history[0].docs_read === 3); + T(repResult.history[0].doc_write_failures === 0); + + docFoo1 = targetDb.open("foo1"); + T(docFoo1 !== null); + T(docFoo1.value === 1); + + docFoo2 = targetDb.open("foo2"); + T(docFoo2 !== null); + T(docFoo2.value === 2); + + docFoo3 = targetDb.open("foo3"); + T(docFoo3 !== null); + T(docFoo3.value === 3); + + docFoo4 = targetDb.open("foo4"); + T(docFoo4 !== null); + T(docFoo4.value === 4); + + T(targetDb.open("_design/mydesign") !== null); } }; |