You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by kx...@apache.org on 2015/10/27 20:31:25 UTC

[1/3] couchdb-couch-epi git commit: Ensure calling order of plugins during dispatch

Repository: couchdb-couch-epi
Updated Branches:
  refs/heads/master 727cf7132 -> 77dfaf413


Ensure calling order of plugins during dispatch

If there are multiple plugins providing same service they will be called
in the order they listed in application:get_env(couch_epi, plugins).


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/926d3b13
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/tree/926d3b13
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/diff/926d3b13

Branch: refs/heads/master
Commit: 926d3b13207fe829bcefd51d4465f9cacd35315e
Parents: be34447
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Tue Oct 6 12:17:31 2015 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Tue Oct 6 12:17:31 2015 -0700

----------------------------------------------------------------------
 README.md                   |  4 ++++
 src/couch_epi_functions.erl |  5 +++--
 src/couch_epi_plugin.erl    |  2 +-
 test/couch_epi_tests.erl    | 36 ++++++++++++++++++++++++++++++------
 4 files changed, 38 insertions(+), 9 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/blob/926d3b13/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 3f15a62..685d314 100644
--- a/README.md
+++ b/README.md
@@ -96,6 +96,10 @@ There are multiple ways of doing the apply which is controlled by Opts
 Notes:
 
   - `concurrent` is incompatible with `pipe`
+  - if there are multiple plugins providing same service they will be called in the order
+    they listed in application:get_env(couch_epi, plugins)
+  - if the same plugin provides multiple implementations of the same service
+    the order is undefined (fixable)
 
 # couch_epi_plugin behaviour
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/blob/926d3b13/src/couch_epi_functions.erl
----------------------------------------------------------------------
diff --git a/src/couch_epi_functions.erl b/src/couch_epi_functions.erl
index 34d1a06..ac93739 100644
--- a/src/couch_epi_functions.erl
+++ b/src/couch_epi_functions.erl
@@ -43,6 +43,7 @@ definitions(Modules) ->
     [{M, M:module_info(exports) -- Blacklist} || M <- Modules].
 
 group(KV) ->
-    dict:to_list(lists:foldr(fun({K,V}, D) ->
+    Dict = lists:foldr(fun({K,V}, D) ->
         dict:append_list(K, V, D)
-    end, dict:new(), KV)).
+    end, dict:new(), KV),
+    [{K, lists:reverse(V)} || {K, V} <- dict:to_list(Dict)].

http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/blob/926d3b13/src/couch_epi_plugin.erl
----------------------------------------------------------------------
diff --git a/src/couch_epi_plugin.erl b/src/couch_epi_plugin.erl
index 05aa591..718e5fb 100644
--- a/src/couch_epi_plugin.erl
+++ b/src/couch_epi_plugin.erl
@@ -68,7 +68,7 @@ definitions(Kind, Key) ->
     Filtered = filter_by_key(Definitions, Kind, Key),
     case group_specs(Filtered) of
         [] -> [];
-        [{_, Defs}] -> Defs
+        [{_, Defs}] -> lists:reverse(Defs)
     end.
 
 notify(Key, OldData, NewData, Specs) ->

http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/blob/926d3b13/test/couch_epi_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_epi_tests.erl b/test/couch_epi_tests.erl
index fc2daa8..56733b1 100644
--- a/test/couch_epi_tests.erl
+++ b/test/couch_epi_tests.erl
@@ -86,7 +86,7 @@
 %% couch_epi_plugin behaviour
 %% ------------------------------------------------------------------
 
-plugin_module([KV, Spec]) ->
+plugin_module([KV, Spec]) when is_tuple(Spec) ->
     SpecStr = io_lib:format("~w", [Spec]),
     KVStr = "'" ++ atom_to_list(KV) ++ "'",
     "
@@ -114,7 +114,7 @@ plugin_module([KV, Spec]) ->
         notify(Key, OldData, Data) ->
             couch_epi_tests:notify_cb(Key, OldData, Data, " ++ KVStr ++ ").
     ";
-plugin_module([KV]) ->
+plugin_module([KV, Provider]) when is_atom(Provider) ->
     KVStr = "'" ++ atom_to_list(KV) ++ "'",
     "
         -compile([export_all]).
@@ -122,13 +122,12 @@ plugin_module([KV]) ->
         app() -> test_app.
         providers() ->
             [
-                {my_service, provider1},
-                {my_service, provider2}
+                {my_service, " ++ atom_to_list(Provider) ++ "}
             ].
 
         services() ->
             [
-                {my_service, provider1}
+                {my_service, " ++ atom_to_list(Provider) ++ "}
             ].
 
         data_providers() ->
@@ -203,7 +202,10 @@ setup(functions) ->
 
     KV = start_state_storage(),
 
-    ok = start_epi([{provider_epi, plugin_module([KV])}]),
+    ok = start_epi([
+        {provider_epi1, plugin_module([KV, provider1])},
+        {provider_epi2, plugin_module([KV, provider2])}
+    ]),
 
     Pid = whereis(couch_epi:get_handle(Key)),
     Handle = couch_epi:get_handle(Key),
@@ -285,6 +287,20 @@ epi_apply_test_() ->
         }
     }.
 
+epi_providers_order_test_() ->
+    {
+        "epi providers' order test",
+        {
+            foreach,
+            fun() -> setup(functions) end,
+            fun teardown/1,
+            [
+                fun check_providers_order/1
+            ]
+        }
+    }.
+
+
 epi_reload_test_() ->
     Cases = [
         data_file,
@@ -525,6 +541,14 @@ ensure_no_reload_when_no_change(_Case,
         ?assertEqual(error, get(Ctx, is_called))
     end).
 
+check_providers_order(#ctx{handle = Handle, kv = KV, key = Key} = Ctx) ->
+    ?_test(begin
+        Result = couch_epi:apply(Handle, Key, inc, [KV, 2], [pipe]),
+        ?assertMatch([KV, 4], Result),
+        Order = [element(2, get(Ctx, K)) || K <- [inc1, inc2]],
+        ?assertEqual(Order, [3, 4]),
+        ok
+    end).
 
 %% ------------------------------------------------------------------
 %% Internal Function Definitions


[2/3] couchdb-couch-epi git commit: Handle providers in order of definition

Posted by kx...@apache.org.
Handle providers in order of definition


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/90fdbed3
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/tree/90fdbed3
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/diff/90fdbed3

Branch: refs/heads/master
Commit: 90fdbed36bd22f4201281790270f051cf45ca044
Parents: 926d3b1
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Thu Oct 8 08:09:37 2015 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Thu Oct 8 08:09:37 2015 -0700

----------------------------------------------------------------------
 README.md                |  2 +-
 src/couch_epi_plugin.erl | 51 ++++++++++++++++++++++++++++++++++++++-----
 2 files changed, 47 insertions(+), 6 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/blob/90fdbed3/README.md
----------------------------------------------------------------------
diff --git a/README.md b/README.md
index 685d314..7d5cc70 100644
--- a/README.md
+++ b/README.md
@@ -99,7 +99,7 @@ Notes:
   - if there are multiple plugins providing same service they will be called in the order
     they listed in application:get_env(couch_epi, plugins)
   - if the same plugin provides multiple implementations of the same service
-    the order is undefined (fixable)
+    the order is as defined in providers callback
 
 # couch_epi_plugin behaviour
 

http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/blob/90fdbed3/src/couch_epi_plugin.erl
----------------------------------------------------------------------
diff --git a/src/couch_epi_plugin.erl b/src/couch_epi_plugin.erl
index 718e5fb..0d76465 100644
--- a/src/couch_epi_plugin.erl
+++ b/src/couch_epi_plugin.erl
@@ -68,7 +68,7 @@ definitions(Kind, Key) ->
     Filtered = filter_by_key(Definitions, Kind, Key),
     case group_specs(Filtered) of
         [] -> [];
-        [{_, Defs}] -> lists:reverse(Defs)
+        [{_, Defs}] -> Defs
     end.
 
 notify(Key, OldData, NewData, Specs) ->
@@ -109,9 +109,10 @@ extract_definitions(Plugin) ->
         [{{kind(), key()}, [{couch_epi:app(), #couch_epi_spec{}}]}].
 
 group_specs(Specs) ->
-    group(
+    Grouped = group(
         [{{Kind, Key}, group([{App, Spec}])}
-            || #couch_epi_spec{kind = Kind, key = Key, app = App} = Spec <- Specs]).
+            || #couch_epi_spec{kind = Kind, key = Key, app = App} = Spec <- Specs]),
+    [{K, lists:reverse(V)} || {K, V} <- Grouped].
 
 
 group(KV) ->
@@ -168,7 +169,8 @@ plugin_module(foo_epi) ->
         providers() ->
             [
                 {chttpd_handlers, foo_provider},
-                {bar_handlers, bar_provider}
+                {bar_handlers, bar_provider1},
+                {bar_handlers, bar_provider2}
             ].
 
         services() ->
@@ -228,6 +230,35 @@ generate_module(Name, Body) ->
 generate_modules(Kind, Providers) ->
     [generate_module(P, Kind(P)) || P <- Providers].
 
+provider_modules_order_test() ->
+    [ok,ok] = generate_modules(fun plugin_module/1, [foo_epi, bar_epi]),
+    ok = application:set_env(couch_epi, plugins, [foo_epi, bar_epi]),
+    Expected = [
+        {foo, bar_provider1},
+        {foo, bar_provider2},
+        {bar, bar_provider}
+    ],
+
+    Defs = definitions(providers, bar_handlers),
+    Result = [{App, V} || {App, #couch_epi_spec{value = V}} <- Defs],
+    Tests = lists:zip(Expected, Result),
+    [?assertEqual(Expect, Result) || {Expect, Result} <- Tests],
+    ok.
+
+providers_order_test() ->
+    [ok,ok] = generate_modules(fun plugin_module/1, [foo_epi, bar_epi]),
+    Expected = [
+        {foo, bar_provider1},
+        {foo, bar_provider2},
+        {bar, bar_provider}
+    ],
+    AllDefs = grouped_definitions([foo_epi, bar_epi]),
+    {_, Defs} = lists:keyfind({providers, bar_handlers}, 1, AllDefs),
+    Result = [{App, V} || {App, #couch_epi_spec{value = V}} <- Defs],
+    Tests = lists:zip(Expected, Result),
+    [?assertEqual(Expect, Result) || {Expect, Result} <- Tests],
+    ok.
+
 definitions_test() ->
     Expected = lists:sort([
         #couch_epi_spec{
@@ -275,7 +306,17 @@ definitions_test() ->
             kind = providers,
             options = [],
             key = bar_handlers,
-            value = bar_provider,
+            value = bar_provider1,
+            codegen = couch_epi_functions_gen,
+            type = couch_epi_functions
+        },
+        #couch_epi_spec{
+            behaviour = foo_epi,
+            app = foo,
+            kind = providers,
+            options = [],
+            key = bar_handlers,
+            value = bar_provider2,
             codegen = couch_epi_functions_gen,
             type = couch_epi_functions
         },


[3/3] couchdb-couch-epi git commit: Merge remote-tracking branch 'github/pr/14'

Posted by kx...@apache.org.
Merge remote-tracking branch 'github/pr/14'


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/77dfaf41
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/tree/77dfaf41
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-epi/diff/77dfaf41

Branch: refs/heads/master
Commit: 77dfaf413be31b98de59ef3fe995cc3da5d338d2
Parents: 727cf71 90fdbed
Author: Alexander Shorin <kx...@apache.org>
Authored: Tue Oct 27 22:22:49 2015 +0300
Committer: Alexander Shorin <kx...@apache.org>
Committed: Tue Oct 27 22:22:49 2015 +0300

----------------------------------------------------------------------
 README.md                   |  4 ++++
 src/couch_epi_functions.erl |  5 ++--
 src/couch_epi_plugin.erl    | 49 ++++++++++++++++++++++++++++++++++++----
 test/couch_epi_tests.erl    | 36 ++++++++++++++++++++++++-----
 4 files changed, 82 insertions(+), 12 deletions(-)
----------------------------------------------------------------------