couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r962874 - in /couchdb/branches/new_replicator: etc/couchdb/default.ini.tpl.in share/Makefile.am share/www/script/couch.js share/www/script/couch_tests.js share/www/script/jquery.couch.js share/www/script/test/new_replication.js
Date Sat, 10 Jul 2010 16:26:30 GMT
Author: fdmanana
Date: Sat Jul 10 16:26:29 2010
New Revision: 962874

URL: http://svn.apache.org/viewvc?rev=962874&view=rev
Log:
Added a temporary new URI and test suite for the new replicator (not yet completed).
This allows for easier testing of the new replicator without messing up with the 
current replicator and its test suite.


Added:
    couchdb/branches/new_replicator/share/www/script/test/new_replication.js
Modified:
    couchdb/branches/new_replicator/etc/couchdb/default.ini.tpl.in
    couchdb/branches/new_replicator/share/Makefile.am
    couchdb/branches/new_replicator/share/www/script/couch.js
    couchdb/branches/new_replicator/share/www/script/couch_tests.js
    couchdb/branches/new_replicator/share/www/script/jquery.couch.js

Modified: couchdb/branches/new_replicator/etc/couchdb/default.ini.tpl.in
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/etc/couchdb/default.ini.tpl.in?rev=962874&r1=962873&r2=962874&view=diff
==============================================================================
--- couchdb/branches/new_replicator/etc/couchdb/default.ini.tpl.in (original)
+++ couchdb/branches/new_replicator/etc/couchdb/default.ini.tpl.in Sat Jul 10 16:26:29 2010
@@ -64,6 +64,7 @@ _all_dbs = {couch_httpd_misc_handlers, h
 _active_tasks = {couch_httpd_misc_handlers, handle_task_status_req}
 _config = {couch_httpd_misc_handlers, handle_config_req}
 _replicate = {couch_httpd_misc_handlers, handle_replicate_req}
+_new_replicate = {couch_httpd_rep, handle_req}
 _uuids = {couch_httpd_misc_handlers, handle_uuids_req}
 _restart = {couch_httpd_misc_handlers, handle_restart_req}
 _stats = {couch_httpd_stats_handlers, handle_stats_req}

Modified: couchdb/branches/new_replicator/share/Makefile.am
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/share/Makefile.am?rev=962874&r1=962873&r2=962874&view=diff
==============================================================================
--- couchdb/branches/new_replicator/share/Makefile.am (original)
+++ couchdb/branches/new_replicator/share/Makefile.am Sat Jul 10 16:26:29 2010
@@ -167,6 +167,7 @@ nobase_dist_localdata_DATA = \
     www/script/test/view_pagination.js \
     www/script/test/view_sandboxing.js \
     www/script/test/view_xml.js \
+    www/script/test/new_replication.js \
     www/status.html \
     www/style/layout.css \
     www/_sidebar.html

Modified: couchdb/branches/new_replicator/share/www/script/couch.js
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/share/www/script/couch.js?rev=962874&r1=962873&r2=962874&view=diff
==============================================================================
--- couchdb/branches/new_replicator/share/www/script/couch.js [utf-8] (original)
+++ couchdb/branches/new_replicator/share/www/script/couch.js [utf-8] Sat Jul 10 16:26:29
2010
@@ -386,6 +386,20 @@ CouchDB.replicate = function(source, tar
   return JSON.parse(CouchDB.last_req.responseText);
 }
 
+CouchDB.new_replicate = function(source, target, rep_options) {
+  rep_options = rep_options || {};
+  var headers = rep_options.headers || {};
+  var body = rep_options.body || {};
+  body.source = source;
+  body.target = target;
+  CouchDB.last_req = CouchDB.request("POST", "/_new_replicate", {
+    headers: headers,
+    body: JSON.stringify(body)
+  });
+  CouchDB.maybeThrowError(CouchDB.last_req);
+  return JSON.parse(CouchDB.last_req.responseText);
+};
+
 CouchDB.newXhr = function() {
   if (typeof(XMLHttpRequest) != "undefined") {
     return new XMLHttpRequest();

Modified: couchdb/branches/new_replicator/share/www/script/couch_tests.js
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/share/www/script/couch_tests.js?rev=962874&r1=962873&r2=962874&view=diff
==============================================================================
--- couchdb/branches/new_replicator/share/www/script/couch_tests.js [utf-8] (original)
+++ couchdb/branches/new_replicator/share/www/script/couch_tests.js [utf-8] Sat Jul 10 16:26:29
2010
@@ -93,5 +93,6 @@ loadTest("view_pagination.js");
 loadTest("view_sandboxing.js");
 loadTest("view_update_seq.js");
 loadTest("view_xml.js");
+loadTest("new_replication.js");
 // keep sorted
 

Modified: couchdb/branches/new_replicator/share/www/script/jquery.couch.js
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/share/www/script/jquery.couch.js?rev=962874&r1=962873&r2=962874&view=diff
==============================================================================
--- couchdb/branches/new_replicator/share/www/script/jquery.couch.js [utf-8] (original)
+++ couchdb/branches/new_replicator/share/www/script/jquery.couch.js [utf-8] Sat Jul 10 16:26:29
2010
@@ -514,6 +514,18 @@
       );
     },
 
+    new_replicate: function(source, target, ajaxOptions, replicationOptions) {
+      replicationOptions = $.extend({source: source, target: target}, replicationOptions);
+      ajax({
+          type: "POST", url: this.urlPrefix + "/_new_replicate",
+          data: JSON.stringify(replicationOptions),
+          contentType: "application/json"
+        },
+        ajaxOptions,
+        "Replication failed"
+      );
+    },
+
     newUUID: function(cacheNum) {
       if (cacheNum === undefined) {
         cacheNum = 1;

Added: couchdb/branches/new_replicator/share/www/script/test/new_replication.js
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/share/www/script/test/new_replication.js?rev=962874&view=auto
==============================================================================
--- couchdb/branches/new_replicator/share/www/script/test/new_replication.js (added)
+++ couchdb/branches/new_replicator/share/www/script/test/new_replication.js Sat Jul 10 16:26:29
2010
@@ -0,0 +1,282 @@
+// 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.new_replication = function(debug) {
+
+  if (debug) debugger;
+
+  var host = CouchDB.host;
+  var sourceDb = new CouchDB("test_suite_db_a",{"X-Couch-Full-Commit":"false"});
+  var targetDb = new CouchDB("test_suite_db_b",{"X-Couch-Full-Commit":"false"});
+
+  var dbPairs = [
+    {
+      source: sourceDb.name,
+      target: targetDb.name
+    },
+    {
+      source: "http://" + host + "/" + sourceDb.name,
+      target: targetDb.name
+    },
+    {
+      source: sourceDb.name,
+      target: "http://" + host + "/" + targetDb.name
+    },
+    {
+      source: "http://" + host + "/" + sourceDb.name,
+      target: "http://" + host + "/" + targetDb.name
+    }
+  ];
+
+  var sourceInfo, targetInfo;
+  var docs, doc, copy;
+  var repResult;
+
+
+  function populateDb(db, docs) {
+    db.deleteDb();
+    db.createDb();
+    for (var i = 0; i < docs.length; i++) {
+      var doc = docs[i];
+      delete doc._rev;
+    }
+    if (docs.length > 0) {
+      db.bulkSave(docs);
+    }
+  }
+
+
+  // test simple replications (not continuous, not filtered), including
+  // conflict creation
+  docs = makeDocs(1, 21);
+  docs.push({
+    _id: "_design/foo",
+    language: "javascript",
+    value: "ddoc"
+  });
+
+  for (var i = 0; i < dbPairs.length; i++) {
+    populateDb(sourceDb, docs);
+    populateDb(targetDb, []);
+
+    repResult = CouchDB.new_replicate(dbPairs[i].source, dbPairs[i].target);
+    T(repResult.ok === true);
+
+    sourceInfo = sourceDb.info();
+    targetInfo = targetDb.info();
+
+    T(sourceInfo.doc_count === targetInfo.doc_count);
+    T(sourceInfo.update_seq === targetInfo.update_seq);
+
+    T(typeof repResult.session_id === "string");
+    T(repResult.source_last_seq === sourceInfo.update_seq);
+    T(repResult.history instanceof Array);
+    T(repResult.history.length === 1);
+    T(repResult.history[0].session_id === repResult.session_id);
+    T(typeof repResult.history[0].start_time === "string");
+    T(typeof repResult.history[0].end_time === "string");
+    T(repResult.history[0].start_last_seq === 0);
+    T(repResult.history[0].end_last_seq === sourceInfo.update_seq);
+    T(repResult.history[0].recorded_seq === sourceInfo.update_seq);
+    T(repResult.history[0].missing_checked === sourceInfo.doc_count);
+    T(repResult.history[0].missing_found === sourceInfo.doc_count);
+    T(repResult.history[0].docs_read === sourceInfo.doc_count);
+    T(repResult.history[0].docs_written === sourceInfo.doc_count);
+    T(repResult.history[0].doc_write_failures === 0);
+
+    for (var j = 0; j < docs.length; j++) {
+      doc = docs[j];
+      copy = targetDb.open(doc._id);
+
+      T(copy !== null);
+      for (var p in doc) {
+        T(copy[p] === doc[p]);
+      }
+    }
+
+
+    // add one more doc to source and replicate again
+    var newDoc = {
+      _id: "foo666",
+      value: "d"
+    };
+    T(sourceDb.save(newDoc).ok);
+
+    repResult = CouchDB.new_replicate(dbPairs[i].source, dbPairs[i].target);
+    T(repResult.ok === true);
+
+    sourceInfo = sourceDb.info();
+    targetInfo = targetDb.info();
+
+    T(sourceInfo.doc_count === targetInfo.doc_count);
+    T(sourceInfo.update_seq === targetInfo.update_seq);
+
+    T(typeof repResult.session_id === "string");
+    T(repResult.source_last_seq === sourceInfo.update_seq);
+    T(repResult.history instanceof Array);
+    T(repResult.history.length === 2);
+    T(repResult.history[0].session_id === repResult.session_id);
+    T(typeof repResult.history[0].start_time === "string");
+    T(typeof repResult.history[0].end_time === "string");
+    T(repResult.history[0].start_last_seq === (sourceInfo.update_seq - 1));
+    T(repResult.history[0].end_last_seq === sourceInfo.update_seq);
+    T(repResult.history[0].recorded_seq === sourceInfo.update_seq);
+    T(repResult.history[0].missing_checked === 1);
+    T(repResult.history[0].missing_found === 1);
+    T(repResult.history[0].docs_read === 1);
+    T(repResult.history[0].docs_written === 1);
+    T(repResult.history[0].doc_write_failures === 0);
+
+    copy = targetDb.open(newDoc._id);
+    T(copy !== null);
+    T(copy._id === newDoc._id);
+    T(copy.value === newDoc.value);
+
+    // test deletion is replicated
+    doc = sourceDb.open(docs[1]._id);
+    T(sourceDb.deleteDoc(doc).ok);
+
+    repResult = CouchDB.new_replicate(dbPairs[i].source, dbPairs[i].target);
+    T(repResult.ok === true);
+
+    sourceInfo = sourceDb.info();
+    targetInfo = targetDb.info();
+
+    T(sourceInfo.doc_count === targetInfo.doc_count);
+    T(sourceInfo.update_seq === targetInfo.update_seq);
+    T(sourceInfo.doc_del_count === targetInfo.doc_del_count);
+    T(targetInfo.doc_del_count === 1);
+
+    T(repResult.history instanceof Array);
+    T(repResult.history.length === 3);
+    T(repResult.history[0].start_last_seq === (sourceInfo.update_seq - 1));
+    T(repResult.history[0].end_last_seq === sourceInfo.update_seq);
+    T(repResult.history[0].recorded_seq === sourceInfo.update_seq);
+    T(repResult.history[0].missing_checked === 1);
+    T(repResult.history[0].missing_found === 1);
+    T(repResult.history[0].docs_read === 1);
+    T(repResult.history[0].docs_written === 1);
+    T(repResult.history[0].doc_write_failures === 0);
+
+    copy = targetDb.open(docs[1]._id);
+    T(copy === null);
+
+    var changes = targetDb.changes({since: sourceInfo.update_seq - 1});
+    T(changes.results[0].id === docs[1]._id);
+    T(changes.results[0].seq === sourceInfo.update_seq);
+    T(changes.results[0].deleted === true);
+
+    // test conflict
+    doc = sourceDb.open(docs[0]._id);
+    doc.value = "white";
+    T(sourceDb.save(doc).ok);
+
+    copy = targetDb.open(docs[0]._id);
+    copy.value = "black";
+    T(targetDb.save(copy).ok);
+
+    repResult = CouchDB.new_replicate(dbPairs[i].source, dbPairs[i].target);
+    T(repResult.ok === true);
+
+    sourceInfo = sourceDb.info();
+    targetInfo = targetDb.info();
+
+    T(sourceInfo.doc_count === targetInfo.doc_count);
+    T(sourceInfo.update_seq === (targetInfo.update_seq - 1));
+
+    T(repResult.history instanceof Array);
+    T(repResult.history.length === 4);
+    T(repResult.history[0].start_last_seq === (sourceInfo.update_seq - 1));
+    T(repResult.history[0].end_last_seq === sourceInfo.update_seq);
+    T(repResult.history[0].recorded_seq === sourceInfo.update_seq);
+    T(repResult.history[0].missing_checked === 1);
+    T(repResult.history[0].missing_found === 1);
+    T(repResult.history[0].docs_read === 1);
+    T(repResult.history[0].docs_written === 1);
+    T(repResult.history[0].doc_write_failures === 0);
+
+    copy = targetDb.open(docs[0]._id, {conflicts: true});
+
+    T(copy._rev.indexOf("2-") === 0);
+    T(copy._conflicts instanceof Array);
+    T(copy._conflicts.length === 1);
+    T(copy._conflicts[0].indexOf("2-") === 0);
+
+    // replicate again with conflict
+    doc.value = "yellow";
+    T(sourceDb.save(doc).ok);
+
+    repResult = CouchDB.new_replicate(dbPairs[i].source, dbPairs[i].target);
+    T(repResult.ok === true);
+
+    sourceInfo = sourceDb.info();
+    targetInfo = targetDb.info();
+
+    T(sourceInfo.doc_count === targetInfo.doc_count);
+    T(sourceInfo.update_seq === (targetInfo.update_seq - 1));
+
+    T(repResult.history instanceof Array);
+    T(repResult.history.length === 5);
+    T(repResult.history[0].start_last_seq === (sourceInfo.update_seq - 1));
+    T(repResult.history[0].end_last_seq === sourceInfo.update_seq);
+    T(repResult.history[0].recorded_seq === sourceInfo.update_seq);
+    T(repResult.history[0].missing_checked === 1);
+    T(repResult.history[0].missing_found === 1);
+    T(repResult.history[0].docs_read === 1);
+    T(repResult.history[0].docs_written === 1);
+    T(repResult.history[0].doc_write_failures === 0);
+
+    copy = targetDb.open(docs[0]._id, {conflicts: true});
+
+    T(copy._rev.indexOf("3-") === 0);
+    T(copy._conflicts instanceof Array);
+    T(copy._conflicts.length === 1);
+    T(copy._conflicts[0].indexOf("2-") === 0);
+
+    // resolve the conflict
+    T(targetDb.deleteDoc({_id: copy._id, _rev: copy._conflicts[0]}).ok);
+
+    // replicate again, check there are no more conflicts
+    doc.value = "rainbow";
+    T(sourceDb.save(doc).ok);
+
+    repResult = CouchDB.new_replicate(dbPairs[i].source, dbPairs[i].target);
+    T(repResult.ok === true);
+
+    sourceInfo = sourceDb.info();
+    targetInfo = targetDb.info();
+
+    T(sourceInfo.doc_count === targetInfo.doc_count);
+    T(sourceInfo.update_seq === (targetInfo.update_seq - 2));
+
+    T(repResult.history instanceof Array);
+    T(repResult.history.length === 6);
+    T(repResult.history[0].start_last_seq === (sourceInfo.update_seq - 1));
+    T(repResult.history[0].end_last_seq === sourceInfo.update_seq);
+    T(repResult.history[0].recorded_seq === sourceInfo.update_seq);
+    T(repResult.history[0].missing_checked === 1);
+    T(repResult.history[0].missing_found === 1);
+    T(repResult.history[0].docs_read === 1);
+    T(repResult.history[0].docs_written === 1);
+    T(repResult.history[0].doc_write_failures === 0);
+
+    copy = targetDb.open(docs[0]._id, {conflicts: true});
+
+    T(copy._rev.indexOf("4-") === 0);
+    T(typeof copy._conflicts === "undefined");
+  }
+
+
+  // cleanup
+  sourceDb.deleteDb();
+  targetDb.deleteDb();
+}
\ No newline at end of file



Mime
View raw message