couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rnew...@apache.org
Subject [5/7] couchdb-couch-epi git commit: Support for overwriting of app supervisors' children
Date Thu, 01 Oct 2015 15:03:54 GMT
Support for overwriting of app supervisors' children


Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/repo
Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/commit/66a854b6
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/tree/66a854b6
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/diff/66a854b6

Branch: refs/heads/master
Commit: 66a854b6536afb63e430f75b22e42f73310664a8
Parents: 01257ff
Author: ILYA Khlopotov <iilyak@ca.ibm.com>
Authored: Tue Sep 29 12:42:07 2015 -0700
Committer: ILYA Khlopotov <iilyak@ca.ibm.com>
Committed: Thu Oct 1 07:29:39 2015 -0700

----------------------------------------------------------------------
 src/couch_epi.erl     | 11 ++++++-----
 src/couch_epi_sup.erl | 30 +++++++++++++++++++++++-------
 2 files changed, 29 insertions(+), 12 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/blob/66a854b6/src/couch_epi.erl
----------------------------------------------------------------------
diff --git a/src/couch_epi.erl b/src/couch_epi.erl
index cd0434f..2754261 100644
--- a/src/couch_epi.erl
+++ b/src/couch_epi.erl
@@ -13,7 +13,7 @@
 -module(couch_epi).
 
 -export([get_handle/1]).
--export([register_service/1]).
+-export([register_service/2]).
 
 %% queries and introspection
 -export([
@@ -162,8 +162,9 @@ is_configured(Handle, Function, Arity) when Handle /= undefined ->
     [] /= couch_epi_functions_gen:modules(Handle, Function, Arity).
 
 
--spec register_service(PluginId :: plugin_id()) ->
-    [supervisor:child_spec()].
+-spec register_service(
+    PluginId :: plugin_id(), Children :: [supervisor:child_spec()]) ->
+        [supervisor:child_spec()].
 
-register_service(Plugin) ->
-    couch_epi_sup:plugin_childspecs(Plugin).
+register_service(Plugin, Children) ->
+    couch_epi_sup:plugin_childspecs(Plugin, Children).

http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/blob/66a854b6/src/couch_epi_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_epi_sup.erl b/src/couch_epi_sup.erl
index 030095b..31f27d7 100644
--- a/src/couch_epi_sup.erl
+++ b/src/couch_epi_sup.erl
@@ -32,7 +32,7 @@
 
 %% API
 -export([start_link/0]).
--export([plugin_childspecs/1]).
+-export([plugin_childspecs/2]).
 
 %% Supervisor callbacks
 -export([init/1]).
@@ -47,9 +47,9 @@
 start_link() ->
     supervisor:start_link({local, ?MODULE}, ?MODULE, []).
 
-plugin_childspecs(Plugin) ->
+plugin_childspecs(Plugin, Children) ->
     Plugins = application:get_env(couch_epi, plugins, []),
-    plugin_childspecs(Plugin, Plugins).
+    plugin_childspecs(Plugin, Plugins, Children).
 
 %% ===================================================================
 %% Supervisor callbacks
@@ -68,10 +68,10 @@ keepers() ->
     Children = keeper_childspecs(Definitions),
     remove_duplicates(Children).
 
-plugin_childspecs(Plugin, Plugins) ->
+plugin_childspecs(Plugin, Plugins, Children) ->
     Definitions = couch_epi_plugin:grouped_definitions([Plugin]),
     ExtraChildren = couch_epi_plugin:plugin_processes(Plugin, Plugins),
-    ExtraChildren ++ childspecs(Definitions).
+    merge(ExtraChildren, Children) ++ childspecs(Definitions).
 
 childspecs(Definitions) ->
     lists:map(fun({{Kind, Key}, Defs}) ->
@@ -127,6 +127,11 @@ modules(#couch_epi_spec{kind = data_providers, value = Value}) ->
 modules(#couch_epi_spec{kind = data_subscriptions, behaviour = Module}) ->
     [Module].
 
+merge([], Children) ->
+    Children;
+merge([{Id, _, _, _, _, _} = Spec | Rest], Children) ->
+    merge(Rest, lists:keystore(Id, 1, Children, Spec)).
+
 
 %% ------------------------------------------------------------------
 %% Tests
@@ -164,7 +169,9 @@ data_subscriptions() ->
 
 processes() ->
     [
-        {?MODULE, [?CHILD(extra_process, worker)]}
+        {?MODULE, [?CHILD(extra_process, worker)]},
+        {?MODULE, [{to_replace, {new, start_link, [bar]},
+            permanent, 5000, worker, [bar]}]}
     ].
 
 notify(_Key, _OldData, _NewData) ->
@@ -188,6 +195,7 @@ parse_child_id(Id) ->
 basic_test() ->
     Expected = lists:sort([
         {extra_process, [], [extra_process]},
+        {to_replace, [bar], [bar]},
         {{my_service, providers},
             [couch_epi_functions_gen_my_service],
             [couch_epi_codechange_monitor, couch_epi_functions_gen_my_service,
@@ -205,7 +213,9 @@ basic_test() ->
             [couch_epi_codechange_monitor, couch_epi_data_gen_test_app_descriptions,
                 couch_epi_sup]}
     ]),
-    Children = lists:sort(plugin_childspecs(?MODULE, [?MODULE])),
+
+    ToReplace = {to_replace, {old, start_link, [foo]}, permanent, 5000, worker, [foo]},
+    Children = lists:sort(plugin_childspecs(?MODULE, [?MODULE], [ToReplace])),
     Results = [
         {parse_child_id(Id), Args, lists:sort(Modules)}
             || {Id, {_M, _F, Args}, _, _, _, Modules} <- Children
@@ -214,6 +224,12 @@ basic_test() ->
     Tests = lists:zip(Expected, Results),
     [?assertEqual(Expect, Result) || {Expect, Result} <- Tests],
 
+    ExpectedChild = {to_replace, {new, start_link, [bar]},
+        permanent, 5000, worker, [bar]},
+    ?assertEqual(
+        ExpectedChild,
+        lists:keyfind(to_replace, 1, Children)),
+
     ok.
 
 -endif.


Mime
View raw message