couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From robertkowal...@apache.org
Subject chttpd commit: updated refs/heads/master to ca0195f
Date Sun, 24 May 2015 12:42:19 GMT
Repository: couchdb-chttpd
Updated Branches:
  refs/heads/master f3662acb4 -> ca0195f38


add _changes?feed=live sugar for continuous

allow `feed=live` as sugar for `continuous` which is hard to type.
PouchDB already supports `live`.

PRs for the change:
https://github.com/apache/couchdb/pull/307
https://github.com/apache/couchdb-couch/pull/40
https://github.com/apache/couchdb-chttpd/pull/28

closes COUCHDB-2237


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

Branch: refs/heads/master
Commit: ca0195f38645b770c63715022ca14b7cdf649208
Parents: f3662ac
Author: Robert Kowalski <rok@kowalski.gd>
Authored: Sun Mar 1 15:42:24 2015 +0100
Committer: Robert Kowalski <rok@kowalski.gd>
Committed: Sun May 24 14:29:02 2015 +0200

----------------------------------------------------------------------
 src/chttpd_db.erl       |  5 ++++-
 test/chttpd_db_test.erl | 26 +++++++++++++++++++++++---
 2 files changed, 27 insertions(+), 4 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/ca0195f3/src/chttpd_db.erl
----------------------------------------------------------------------
diff --git a/src/chttpd_db.erl b/src/chttpd_db.erl
index 27fa745..7f63023 100644
--- a/src/chttpd_db.erl
+++ b/src/chttpd_db.erl
@@ -93,7 +93,7 @@ handle_changes_req1(#httpd{}=Req, Db) ->
             couch_stats:decrement_counter([couchdb, httpd, clients_requesting_changes])
         end;
     _ ->
-        Msg = <<"Supported `feed` types: normal, continuous, longpoll, eventsource">>,
+        Msg = <<"Supported `feed` types: normal, continuous, live, longpoll, eventsource">>,
         throw({bad_request, Msg})
     end.
 
@@ -1317,6 +1317,9 @@ parse_changes_query(Req) ->
     erlang:erase(changes_seq_interval),
     ChangesArgs = lists:foldl(fun({Key, Value}, Args) ->
         case {string:to_lower(Key), Value} of
+        {"feed", "live"} ->
+            %% sugar for continuous
+            Args#changes_args{feed="continuous"};
         {"feed", _} ->
             Args#changes_args{feed=Value};
         {"descending", "true"} ->

http://git-wip-us.apache.org/repos/asf/couchdb-chttpd/blob/ca0195f3/test/chttpd_db_test.erl
----------------------------------------------------------------------
diff --git a/test/chttpd_db_test.erl b/test/chttpd_db_test.erl
index 8446b9b..9890625 100644
--- a/test/chttpd_db_test.erl
+++ b/test/chttpd_db_test.erl
@@ -31,6 +31,11 @@ create_db(Url) ->
     {ok, _, _, _} = test_request:put(Url,
                 [{"Content-Type", "application/json"}], "{}").
 
+
+create_doc(Url, Id) ->
+    test_request:put(Url ++ "/" ++ Id,
+        [{"Content-Type", "application/json"}], "{\"mr\": \"rockoartischocko\"}").
+
 delete_db(Url) ->
     {ok, _, _, _} = test_request:delete(Url).
 
@@ -44,7 +49,8 @@ all_test_() ->
                 foreach,
                 fun setup/0, fun teardown/1,
                 [
-                    fun should_return_ok_true_on_bulk_update/1
+                    fun should_return_ok_true_on_bulk_update/1,
+                    fun should_accept_live_as_an_alias_for_continuous/1
                 ]
             }
         }
@@ -54,8 +60,7 @@ all_test_() ->
 should_return_ok_true_on_bulk_update(Url) ->
     ?_assertEqual(true,
         begin
-            {ok, _, _, Body} = test_request:put(Url ++ "/testdoc",
-                [{"Content-Type", "application/json"}], "{}"),
+            {ok, _, _, Body} = create_doc(Url, "testdoc"),
             {Json} = ?JSON_DECODE(Body),
             Ref = couch_util:get_value(<<"rev">>, Json, undefined),
             NewDoc = "{\"docs\": [{\"_rev\": \"" ++ ?b2l(Ref) ++ "\", \"_id\": \"testdoc\"}]}",
@@ -65,3 +70,18 @@ should_return_ok_true_on_bulk_update(Url) ->
             {InnerJson} = lists:nth(1, ResultJson),
             couch_util:get_value(<<"ok">>, InnerJson, undefined)
         end).
+
+
+should_accept_live_as_an_alias_for_continuous(Url) ->
+    {ok, _, _, ResultBody} = test_request:get(Url ++ "/_changes?feed=live&timeout=1"),
+    {ResultJson} = ?JSON_DECODE(ResultBody),
+    [Last_Seq, _] = couch_util:get_value(<<"last_seq">>, ResultJson, undefined),
+    {ok, _, _, _} = create_doc(Url, "testdoc2"),
+
+    ?_assertEqual(Last_Seq + 1,
+        begin
+            {ok, _, _, ResultBody2} = test_request:get(Url ++ "/_changes?feed=live&timeout=1"),
+            [_, CleanedResult] = binary:split(ResultBody2, <<"\n">>),
+            {[{_, [Seq, _]}, _]} = ?JSON_DECODE(CleanedResult),
+            Seq
+        end).


Mime
View raw message