nickva closed pull request #1219: Implement format_status/2 for replication 
worker gen_server
URL: https://github.com/apache/couchdb/pull/1219
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/couch_replicator/src/couch_replicator_worker.erl 
b/src/couch_replicator/src/couch_replicator_worker.erl
index e51565866e..ec98fa0f35 100644
--- a/src/couch_replicator/src/couch_replicator_worker.erl
+++ b/src/couch_replicator/src/couch_replicator_worker.erl
@@ -20,6 +20,7 @@
 % gen_server callbacks
 -export([init/1, terminate/2, code_change/3]).
 -export([handle_call/3, handle_cast/2, handle_info/2]).
+-export([format_status/2]).
 
 -include_lib("couch/include/couch_db.hrl").
 -include_lib("couch_replicator/include/couch_replicator_api_wrap.hrl").
@@ -218,6 +219,25 @@ terminate(_Reason, State) ->
     stop_db_compaction_notifier(State#state.source_db_compaction_notifier),
     stop_db_compaction_notifier(State#state.target_db_compaction_notifier).
 
+format_status(_Opt, [_PDict, State]) ->
+    #state{
+        cp = MainJobPid,
+        loop = LoopPid,
+        source = Source,
+        target = Target,
+        readers = Readers,
+        pending_fetch = PendingFetch,
+        batch = #batch{size = BatchSize}
+    } = State,
+    [
+        {main_pid, MainJobPid},
+        {loop, LoopPid},
+        {source, couch_replicator_api_wrap:db_uri(Source)},
+        {target, couch_replicator_api_wrap:db_uri(Target)},
+        {num_readers, length(Readers)},
+        {pending_fetch, PendingFetch},
+        {batch_size, BatchSize}
+    ].
 
 code_change(_OldVsn, State, _Extra) ->
     {ok, State}.
@@ -559,3 +579,30 @@ maybe_report_stats(Cp, Stats) ->
     false ->
         Stats
     end.
+
+
+-ifdef(TEST).
+
+-include_lib("eunit/include/eunit.hrl").
+
+
+replication_worker_format_status_test() ->
+    State = #state{
+        cp = self(),
+        loop = self(),
+        source = #httpdb{url = "http://u:p@h/d1"},
+        target = #httpdb{url = "http://u:p@h/d2"},
+        readers = [r1, r2, r3],
+        pending_fetch = nil,
+        batch = #batch{size = 5}
+    },
+    Format = format_status(opts_ignored, [pdict, State]),
+    ?assertEqual(self(), proplists:get_value(main_pid, Format)),
+    ?assertEqual(self(), proplists:get_value(loop, Format)),
+    ?assertEqual("http://u:*****@h/d1";, proplists:get_value(source, Format)),
+    ?assertEqual("http://u:*****@h/d2";, proplists:get_value(target, Format)),
+    ?assertEqual(3, proplists:get_value(num_readers, Format)),
+    ?assertEqual(nil, proplists:get_value(pending_fetch, Format)),
+    ?assertEqual(5, proplists:get_value(batch_size, Format)).
+
+-endif.


 

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


With regards,
Apache Git Services

Reply via email to