You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by rn...@apache.org on 2015/07/21 15:16:28 UTC

[1/3] couch commit: updated refs/heads/master to 6c7cd6a

Repository: couchdb-couch
Updated Branches:
  refs/heads/master 668ef5e5d -> 6c7cd6aab


Add dynamic http endpoints


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

Branch: refs/heads/master
Commit: c70c966179970c891e8889c9fd83b85c628c8985
Parents: 8b4af21
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Wed Jul 15 08:04:52 2015 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Fri Jul 17 10:26:48 2015 -0700

----------------------------------------------------------------------
 src/couch.app.src               |   1 +
 test/chttpd_endpoints_tests.erl | 184 +++++++++++++++++++++++++++++++++++
 2 files changed, 185 insertions(+)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/c70c9661/src/couch.app.src
----------------------------------------------------------------------
diff --git a/src/couch.app.src b/src/couch.app.src
index 0b232f7..dc62c37 100644
--- a/src/couch.app.src
+++ b/src/couch.app.src
@@ -46,6 +46,7 @@
         couch_log,
         couch_event,
         ioq,
+        couch_epi,
         couch_stats
     ]}
 ]}.

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/c70c9661/test/chttpd_endpoints_tests.erl
----------------------------------------------------------------------
diff --git a/test/chttpd_endpoints_tests.erl b/test/chttpd_endpoints_tests.erl
new file mode 100644
index 0000000..2965327
--- /dev/null
+++ b/test/chttpd_endpoints_tests.erl
@@ -0,0 +1,184 @@
+% 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.
+
+-module(chttpd_endpoints_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+
+setup("mocked") ->
+    fun setup_mocked/1;
+setup("not_mocked") ->
+    fun setup_not_mocked/1.
+
+setup_mocked({Endpoint, {_Path, Module, Function}}) ->
+    catch meck:unload(Module),
+    meck:new(Module, [passthrough, non_strict]),
+    Expected = mock_handler(Endpoint, Module, Function),
+    Expected.
+
+setup_not_mocked({_Endpoint, {_Path, Module, _Function}}) ->
+    catch meck:unload(Module),
+    meck:new(Module, [non_strict]),
+    ok.
+
+teardown({_Endpoint, {Module, _F, _A}}, _) ->
+    catch meck:unload(Module),
+    ok.
+
+handlers(url_handler) ->
+    [
+        {<<"">>, chttpd_misc, handle_welcome_req},
+        {<<"favicon.ico">>, chttpd_misc, handle_favicon_req},
+        {<<"_utils">>, chttpd_misc, handle_utils_dir_req},
+        {<<"_all_dbs">>, chttpd_misc, handle_all_dbs_req},
+        {<<"_active_tasks">>, chttpd_misc, handle_task_status_req},
+        {<<"_node">>, chttpd_misc, handle_node_req},
+        {<<"_reload_query_servers">>, chttpd_misc, handle_reload_query_servers_req},
+        {<<"_replicate">>, chttpd_misc, handle_replicate_req},
+        {<<"_uuids">>, chttpd_misc, handle_uuids_req},
+        {<<"_session">>, chttpd_auth, handle_session_req},
+        {<<"_oauth">>, couch_httpd_oauth, handle_oauth_req},
+        {<<"_up">>, chttpd_misc, handle_up_req},
+        {<<"_membership">>, mem3_httpd, handle_membership_req},
+        {<<"_db_updates">>, global_changes_httpd, handle_global_changes_req},
+        {<<"_cluster_setup">>, setup_httpd, handle_setup_req},
+        {<<"anything">>, chttpd_db, handle_request}
+    ];
+handlers(db_handler) ->
+    [
+        {<<"_view_cleanup">>, chttpd_db, handle_view_cleanup_req},
+        {<<"_compact">>, chttpd_db, handle_compact_req},
+        {<<"_design">>, chttpd_db, handle_design_req},
+        {<<"_temp_view">>, chttpd_view, handle_temp_view_req},
+        {<<"_changes">>, chttpd_db, handle_changes_req},
+        {<<"_shards">>, mem3_httpd, handle_shards_req},
+        {<<"_index">>, mango_httpd, handle_req},
+        {<<"_explain">>, mango_httpd, handle_req},
+        {<<"_find">>, mango_httpd, handle_req}
+    ];
+handlers(design_handler) ->
+    [
+        {<<"_view">>, chttpd_view, handle_view_req},
+        {<<"_show">>, chttpd_show, handle_doc_show_req},
+        {<<"_list">>, chttpd_show, handle_view_list_req},
+        {<<"_update">>, chttpd_show, handle_doc_update_req},
+        {<<"_info">>, chttpd_db, handle_design_info_req},
+        {<<"_rewrite">>, chttpd_rewrite, handle_rewrite_req}
+    ].
+
+endpoints_test_() ->
+    {
+        "Checking dynamic endpoints",
+        {
+            setup,
+            fun() -> test_util:start_couch([chttpd, mem3, global_changes, mango]) end,
+            fun test_util:stop/1,
+            [
+                check_dynamic_endpoints(
+                    "mocked", url_handler, fun ensure_called/2),
+                check_dynamic_endpoints(
+                    "mocked", db_handler, fun ensure_called/2),
+                check_dynamic_endpoints(
+                    "mocked", design_handler, fun ensure_called/2),
+                check_dynamic_endpoints(
+                    "not_mocked", url_handler, fun verify_we_fail_if_missing/2),
+                check_dynamic_endpoints(
+                    "not_mocked", db_handler, fun verify_we_fail_if_missing/2),
+                check_dynamic_endpoints(
+                    "not_mocked", design_handler, fun verify_we_fail_if_missing/2)
+            ]
+        }
+    }.
+
+check_dynamic_endpoints(Setup, EndpointType, TestFun) ->
+    {
+        "Checking '"
+            ++ atom_to_list(EndpointType)
+            ++ "' [" ++ Setup ++ "] dynamic endpoints",
+        [
+            make_test_case(Setup, EndpointType, Spec, TestFun)
+               || Spec <- handlers(EndpointType)
+        ]
+    }.
+
+make_test_case(Setup, EndpointType, {Path, Module, Function}, TestFun) ->
+    {
+        lists:flatten(io_lib:format("~s -- \"~s\"", [EndpointType, ?b2l(Path)])),
+        {
+            foreachx, setup(Setup), fun teardown/2,
+            [
+                {{EndpointType, {Path, Module, Function}}, TestFun}
+            ]
+        }
+    }.
+
+
+mock_handler(url_handler = Endpoint, M, F) ->
+    meck:expect(M, F, fun(X) -> {return, Endpoint, X} end),
+    fun M:F/1;
+mock_handler(db_handler = Endpoint, M, F) ->
+    meck:expect(M, F, fun(X, Y) -> {return, Endpoint, X, Y} end),
+    fun M:F/2;
+mock_handler(design_handler = Endpoint, M, F) ->
+    meck:expect(M, F, fun(X, Y, Z) -> {return, Endpoint, X, Y, Z} end),
+    fun M:F/3.
+
+ensure_called({url_handler = Endpoint, {Path, _M, _Fun}}, ExpectedFun) ->
+    HandlerFun = handler(Endpoint, Path),
+    ?_test(begin
+        ?assertEqual(ExpectedFun, HandlerFun),
+        ?assertMatch({return, Endpoint, x}, HandlerFun(x))
+     end);
+ensure_called({db_handler = Endpoint, {Path, _M, _Fun}}, ExpectedFun) ->
+    HandlerFun = handler(Endpoint, Path),
+    ?_test(begin
+        ?assertEqual(ExpectedFun, HandlerFun),
+        ?assertMatch({return, Endpoint, x, y}, HandlerFun(x, y))
+     end);
+ensure_called({design_handler = Endpoint, {Path, _M, _Fun}}, ExpectedFun) ->
+    HandlerFun = handler(Endpoint, Path),
+    ?_test(begin
+        ?assertEqual(ExpectedFun, HandlerFun),
+        ?assertMatch({return, Endpoint, x, y, z}, HandlerFun(x, y, z))
+     end).
+
+%% Test the test: when the final target function is missing,
+%% the Fun call must fail.
+verify_we_fail_if_missing({url_handler = Endpoint, {Path, _M, _Fun}}, _) ->
+    HandlerFun = handler(Endpoint, Path),
+    ?_test(begin
+        ?assert(is_function(HandlerFun)),
+        ?assertError(undef, HandlerFun(x))
+    end);
+verify_we_fail_if_missing({db_handler = Endpoint, {Path, _M, _Fun}}, _) ->
+    HandlerFun = handler(Endpoint, Path),
+    ?_test(begin
+        ?assert(is_function(HandlerFun)),
+        ?assertError(undef, HandlerFun(x, y))
+    end);
+verify_we_fail_if_missing({design_handler = Endpoint, {Path, _M, _Fun}}, _) ->
+    HandlerFun = handler(Endpoint, Path),
+    ?_test(begin
+        ?assert(is_function(HandlerFun)),
+        ?assertError(undef, HandlerFun(x, y, z))
+    end).
+
+handler(url_handler, HandlerKey) ->
+    chttpd_handlers:url_handler(HandlerKey, fun chttpd_db:handle_request/1);
+handler(db_handler, HandlerKey) ->
+    chttpd_handlers:db_handler(HandlerKey, fun chttpd_db:db_req/2);
+handler(design_handler, HandlerKey) ->
+    chttpd_handlers:design_handler(HandlerKey, fun dummy/3).
+
+dummy(_, _, _) ->
+    throw(error).


[2/3] couch commit: updated refs/heads/master to 6c7cd6a

Posted by rn...@apache.org.
Use dynamic handler for `_oauth`


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

Branch: refs/heads/master
Commit: e41205f393e1440003927539c53ab1a83d53ac9f
Parents: c70c966
Author: ILYA Khlopotov <ii...@ca.ibm.com>
Authored: Fri Jul 17 10:59:06 2015 -0700
Committer: ILYA Khlopotov <ii...@ca.ibm.com>
Committed: Fri Jul 17 10:59:06 2015 -0700

----------------------------------------------------------------------
 src/couch_httpd_handlers.erl | 22 ++++++++++++++++++++++
 src/couch_secondary_sup.erl  |  5 ++++-
 2 files changed, 26 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/e41205f3/src/couch_httpd_handlers.erl
----------------------------------------------------------------------
diff --git a/src/couch_httpd_handlers.erl b/src/couch_httpd_handlers.erl
new file mode 100644
index 0000000..b8ee3ef
--- /dev/null
+++ b/src/couch_httpd_handlers.erl
@@ -0,0 +1,22 @@
+% 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.
+
+-module(couch_httpd_handlers).
+
+-export([url_handler/1, db_handler/1, design_handler/1]).
+
+url_handler(<<"_oauth">>)          -> fun couch_httpd_oauth:handle_oauth_req/1;
+url_handler(_) -> no_match.
+
+db_handler(_) -> no_match.
+
+design_handler(_) -> no_match.

http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/e41205f3/src/couch_secondary_sup.erl
----------------------------------------------------------------------
diff --git a/src/couch_secondary_sup.erl b/src/couch_secondary_sup.erl
index 09e77b7..4bda4ef 100644
--- a/src/couch_secondary_sup.erl
+++ b/src/couch_secondary_sup.erl
@@ -26,7 +26,10 @@ init([]) ->
             worker,
             dynamic}
     ],
-    Children = SecondarySupervisors ++ [
+    ServiceProviders = [
+        chttpd_handlers:provider(couch, couch_httpd_handlers)
+    ],
+    Children = SecondarySupervisors ++ ServiceProviders ++ [
         begin
             {ok, {Module, Fun, Args}} = couch_util:parse_term(SpecStr),
 


[3/3] couch commit: updated refs/heads/master to 6c7cd6a

Posted by rn...@apache.org.
Merge remote-tracking branch 'cloudant/dynamic-handlers'


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

Branch: refs/heads/master
Commit: 6c7cd6aabd73d374e6882286ddb9ab2b75852412
Parents: 668ef5e e41205f
Author: Robert Newson <rn...@apache.org>
Authored: Tue Jul 21 13:33:37 2015 +0100
Committer: Robert Newson <rn...@apache.org>
Committed: Tue Jul 21 13:33:37 2015 +0100

----------------------------------------------------------------------
 src/couch.app.src               |   1 +
 src/couch_httpd_handlers.erl    |  22 +++++
 src/couch_secondary_sup.erl     |   5 +-
 test/chttpd_endpoints_tests.erl | 184 +++++++++++++++++++++++++++++++++++
 4 files changed, 211 insertions(+), 1 deletion(-)
----------------------------------------------------------------------