couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From e...@apache.org
Subject [1/3] couch commit: updated refs/heads/master to 5a009b1
Date Wed, 06 Jul 2016 14:26:26 GMT
Repository: couchdb-couch
Updated Branches:
  refs/heads/master 1bcf52545 -> 5a009b168


Add the tests for _view filtered changes


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

Branch: refs/heads/master
Commit: 884d54723254e769be00f232d57932b5fbc35da3
Parents: 1bcf525
Author: Eric Avdey <eiri@eiri.ca>
Authored: Fri Jun 24 13:31:05 2016 -0300
Committer: Eric Avdey <eiri@eiri.ca>
Committed: Fri Jun 24 13:31:05 2016 -0300

----------------------------------------------------------------------
 test/couch_changes_tests.erl | 97 ++++++++++++++++++++++++++++++++++++++-
 1 file changed, 96 insertions(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/couchdb-couch/blob/884d5472/test/couch_changes_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_changes_tests.erl b/test/couch_changes_tests.erl
index 52eff8a..d8adead 100644
--- a/test/couch_changes_tests.erl
+++ b/test/couch_changes_tests.erl
@@ -63,8 +63,9 @@ changes_test_() ->
                 filter_by_selector(),
                 filter_by_doc_id(),
                 filter_by_design(),
-                continuous_feed()
+                continuous_feed(),
                 %%filter_by_custom_function()
+                filter_by_view()
             ]
         }
     }.
@@ -127,6 +128,19 @@ filter_by_custom_function() ->
         }
     }.
 
+filter_by_view() ->
+    {
+        "Filter _view",
+        {
+            foreach,
+            fun setup/0, fun teardown/1,
+            [
+                fun should_filter_by_view/1,
+                fun should_filter_by_fast_view/1
+            ]
+        }
+    }.
+
 continuous_feed() ->
     {
         "Continuous Feed",
@@ -591,6 +605,87 @@ should_receive_heartbeats(_) ->
              ?assert(Heartbeats3 > Heartbeats2)
         end)}.
 
+should_filter_by_view({DbName, _}) ->
+    ?_test(
+        begin
+            {ok, Db0} = couch_db:open_int(DbName, [?ADMIN_CTX]),
+            DDocId = <<"_design/app">>,
+            DDoc = couch_doc:from_json_obj({[
+                {<<"_id">>, DDocId},
+                {<<"language">>, <<"javascript">>},
+                {<<"views">>, {[
+                    {<<"valid">>, {[
+                        {<<"map">>, <<"function(doc) {"
+                        " if (doc._id == 'doc3') {"
+                            " emit(doc); "
+                        "} }">>}
+                    ]}}
+                ]}}
+            ]}),
+            {ok, _} = couch_db:update_doc(Db0, DDoc, []),
+            couch_db:close(Db0),
+            %%
+            ChangesArgs = #changes_args{filter = "_view"},
+            Opts = {json_req, {[{
+                <<"query">>, {[
+                    {<<"view">>, <<"app/valid">>}
+                ]}
+            }]}},
+            Consumer = spawn_consumer(DbName, ChangesArgs, Opts),
+            {Rows, LastSeq} = wait_finished(Consumer),
+            {ok, Db} = couch_db:open_int(DbName, []),
+            UpSeq = couch_db:get_update_seq(Db),
+            couch_db:close(Db),
+            stop_consumer(Consumer),
+            ?assertEqual(1, length(Rows)),
+            [#row{seq = Seq, id = Id}] = Rows,
+            ?assertEqual(<<"doc3">>, Id),
+            ?assertEqual(6, Seq),
+            ?assertEqual(UpSeq, LastSeq)
+        end).
+
+should_filter_by_fast_view({DbName, _}) ->
+    ?_test(
+        begin
+            {ok, Db0} = couch_db:open_int(DbName, [?ADMIN_CTX]),
+            DDocId = <<"_design/app">>,
+            DDoc = couch_doc:from_json_obj({[
+                {<<"_id">>, DDocId},
+                {<<"language">>, <<"javascript">>},
+                {<<"options">>, {[{<<"seq_indexed">>, true}]}},
+                {<<"views">>, {[
+                    {<<"valid">>, {[
+                        {<<"map">>, <<"function(doc) {"
+                        " if (doc._id == 'doc3') {"
+                            " emit(doc); "
+                        "} }">>}
+                    ]}}
+                ]}}
+            ]}),
+            {ok, _} = couch_db:update_doc(Db0, DDoc, []),
+            couch_db:close(Db0),
+            %%
+            ChangesArgs = #changes_args{filter = "_view"},
+            Opts = {json_req, {[{
+                <<"query">>, {[
+                    {<<"view">>, <<"app/valid">>}
+                ]}
+            }]}},
+            Consumer = spawn_consumer(DbName, ChangesArgs, Opts),
+            {Rows, LastSeq} = wait_finished(Consumer),
+            {ok, Db} = couch_db:open_int(DbName, []),
+            DbUpSeq = couch_db:get_update_seq(Db),
+            {ok, ViewInfo} = couch_mrview:get_view_info(Db, DDoc, <<"valid">>),
+            {update_seq, ViewUpSeq} = lists:keyfind(update_seq, 1, ViewInfo),
+            couch_db:close(Db),
+            stop_consumer(Consumer),
+            ?assertEqual(1, length(Rows)),
+            [#row{seq = Seq, id = Id}] = Rows,
+            ?assertEqual(<<"doc3">>, Id),
+            ?assertEqual(6, Seq),
+            ?assertEqual(LastSeq, Seq),
+            ?assertEqual(DbUpSeq, ViewUpSeq)
+        end).
 
 save_doc(Db, Json) ->
     Doc = couch_doc:from_json_obj(Json),


Mime
View raw message