couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From fdman...@apache.org
Subject svn commit: r962875 - in /couchdb/branches/new_replicator: share/www/script/test/new_replication.js src/couchdb/couch_api_wrap.erl src/couchdb/couch_replicate.erl
Date Sat, 10 Jul 2010 16:27:31 GMT
Author: fdmanana
Date: Sat Jul 10 16:27:30 2010
New Revision: 962875

URL: http://svn.apache.org/viewvc?rev=962875&view=rev
Log:
Added support for the create_target option.

Modified:
    couchdb/branches/new_replicator/share/www/script/test/new_replication.js
    couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl
    couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl

Modified: 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=962875&r1=962874&r2=962875&view=diff
==============================================================================
--- couchdb/branches/new_replicator/share/www/script/test/new_replication.js (original)
+++ couchdb/branches/new_replicator/share/www/script/test/new_replication.js Sat Jul 10 16:27:30
2010
@@ -40,6 +40,7 @@ couchTests.new_replication = function(de
   var sourceInfo, targetInfo;
   var docs, doc, copy;
   var repResult;
+  var i, j;
 
 
   function populateDb(db, docs) {
@@ -64,7 +65,7 @@ couchTests.new_replication = function(de
     value: "ddoc"
   });
 
-  for (var i = 0; i < dbPairs.length; i++) {
+  for (i = 0; i < dbPairs.length; i++) {
     populateDb(sourceDb, docs);
     populateDb(targetDb, []);
 
@@ -93,7 +94,7 @@ couchTests.new_replication = function(de
     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++) {
+    for (j = 0; j < docs.length; j++) {
       doc = docs[j];
       copy = targetDb.open(doc._id);
 
@@ -276,6 +277,26 @@ couchTests.new_replication = function(de
   }
 
 
+  // test create_target option
+  for (i = 0; i < dbPairs.length; i++) {
+    populateDb(sourceDb, docs);
+    targetDb.deleteDb();
+
+    repResult = CouchDB.new_replicate(
+      dbPairs[i].source,
+      dbPairs[i].target,
+      {body: {create_target: true}}
+    );
+    T(repResult.ok === true);
+
+    sourceInfo = sourceDb.info();
+    targetInfo = targetDb.info();
+
+    T(sourceInfo.doc_count === targetInfo.doc_count);
+    T(sourceInfo.update_seq === targetInfo.update_seq);
+  }
+
+
   // cleanup
   sourceDb.deleteDb();
   targetDb.deleteDb();

Modified: couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl?rev=962875&r1=962874&r2=962875&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_api_wrap.erl Sat Jul 10 16:27:30 2010
@@ -34,6 +34,7 @@
 
 -export([
     db_open/2,
+    db_open/3,
     db_close/1,
     get_db_info/1,
     open_doc/3,
@@ -45,9 +46,32 @@
     changes_since/5
     ]).
 
-db_open(#httpdb{}=Db, _Options) ->
+db_open(Db, Options) ->
+    db_open(Db, Options, false).
+
+db_open(#httpdb{} = Db, _Options, Create) ->
+    #httpdb{url=Url, oauth=OAuth, headers=Headers} = Db,
+    case Create of
+    false ->
+        ok;
+    true ->
+        Headers2 = oauth_header(Url, [], put, OAuth) ++ Headers,
+        catch ibrowse:send_req(Url, Headers2, put, [],
+            [{response_format, binary}], infinity)
+    end,
     {ok, Db};
-db_open(DbName, Options) ->
+db_open(DbName, Options, Create) ->
+    case Create of
+    false ->
+        ok;
+    true ->
+        case couch_db:create(DbName, Options) of
+        {ok, _Db} ->
+            ok;
+        file_exists ->
+            ok
+        end
+    end,
     couch_db:open(DbName,Options).
 
 db_close(#httpdb{}) ->

Modified: couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl
URL: http://svn.apache.org/viewvc/couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl?rev=962875&r1=962874&r2=962875&view=diff
==============================================================================
--- couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl (original)
+++ couchdb/branches/new_replicator/src/couchdb/couch_replicate.erl Sat Jul 10 16:27:30 2010
@@ -47,7 +47,6 @@
 start(Src, Tgt, Options, UserCtx) ->
     
     _Continuous = couch_util:get_value(continuous, Options, false),
-    _CreateTarget = couch_util:get_value(create_target, Options, false),
     
     % initalize the replication state, looking for existing rep records
     % for incremental replication.
@@ -84,7 +83,8 @@ start(Src, Tgt, Options, UserCtx) ->
 
 init_state(Src,Tgt,Options,UserCtx)->    
     {ok, Source} = couch_api_wrap:db_open(Src, [{user_ctx, UserCtx}]),
-    {ok, Target} = couch_api_wrap:db_open(Tgt, [{user_ctx, UserCtx}]),
+    {ok, Target} = couch_api_wrap:db_open(Tgt, [{user_ctx, UserCtx}],
+        couch_util:get_value(create_target, Options, false)),
 
     {ok, SourceInfo} = couch_api_wrap:get_db_info(Source),
     {ok, TargetInfo} = couch_api_wrap:get_db_info(Target),



Mime
View raw message