Return-Path: X-Original-To: apmail-couchdb-commits-archive@www.apache.org Delivered-To: apmail-couchdb-commits-archive@www.apache.org Received: from mail.apache.org (hermes.apache.org [140.211.11.3]) by minotaur.apache.org (Postfix) with SMTP id C042E18D42 for ; Thu, 11 Feb 2016 12:54:47 +0000 (UTC) Received: (qmail 71830 invoked by uid 500); 11 Feb 2016 12:54:47 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 71789 invoked by uid 500); 11 Feb 2016 12:54:47 -0000 Mailing-List: contact commits-help@couchdb.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@couchdb.apache.org Delivered-To: mailing list commits@couchdb.apache.org Received: (qmail 71718 invoked by uid 99); 11 Feb 2016 12:54:47 -0000 Received: from git1-us-west.apache.org (HELO git1-us-west.apache.org) (140.211.11.23) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 11 Feb 2016 12:54:47 +0000 Received: by git1-us-west.apache.org (ASF Mail Server at git1-us-west.apache.org, from userid 33) id 5692DE0534; Thu, 11 Feb 2016 12:54:47 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: eiri@apache.org To: commits@couchdb.apache.org Date: Thu, 11 Feb 2016 12:54:47 -0000 Message-Id: X-Mailer: ASF-Git Admin Mailer Subject: [1/2] couch-replicator commit: updated refs/heads/master to 61c59b5 Repository: couchdb-couch-replicator Updated Branches: refs/heads/master ea408866c -> 61c59b5d7 Add filtered with query replication test Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/commit/61c59b5d Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/tree/61c59b5d Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/diff/61c59b5d Branch: refs/heads/master Commit: 61c59b5d7349b222276639bd839d3817542583c8 Parents: b18ff40 Author: Eric Avdey Authored: Fri Feb 5 13:15:33 2016 -0400 Committer: Eric Avdey Committed: Thu Feb 11 08:28:07 2016 -0400 ---------------------------------------------------------------------- test/couch_replicator_filtered_tests.erl | 57 ++++++++++++++++++++++++++- 1 file changed, 56 insertions(+), 1 deletion(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch-replicator/blob/61c59b5d/test/couch_replicator_filtered_tests.erl ---------------------------------------------------------------------- diff --git a/test/couch_replicator_filtered_tests.erl b/test/couch_replicator_filtered_tests.erl index 71aabfb..d39aabd 100644 --- a/test/couch_replicator_filtered_tests.erl +++ b/test/couch_replicator_filtered_tests.erl @@ -21,6 +21,16 @@ {<<"filters">>, {[ {<<"testfilter">>, <<" function(doc, req){if (doc.class == 'mammal') return true;} + ">>}, + {<<"queryfilter">>, <<" + function(doc, req) { + if (doc.class && req.query.starts) { + return doc.class.indexOf(req.query.starts) === 0; + } + else { + return false; + } + } ">>} ]}} ]}). @@ -50,6 +60,18 @@ filtered_replication_test_() -> } }. +query_filtered_replication_test_() -> + Pairs = [{local, local}, {local, remote}, + {remote, local}, {remote, remote}], + { + "Filtered with query replication tests", + { + foreachx, + fun setup/1, fun teardown/2, + [{Pair, fun should_succeed_with_query/2} || Pair <- Pairs] + } + }. + should_succeed({From, To}, {_Ctx, {Source, Target}}) -> RepObject = {[ {<<"source">>, db_url(From, Source)}, @@ -72,6 +94,32 @@ should_succeed({From, To}, {_Ctx, {Source, Target}}) -> ?_assert(lists:all(fun(Valid) -> Valid end, AllReplies))} ]}. +should_succeed_with_query({From, To}, {_Ctx, {Source, Target}}) -> + RepObject = {[ + {<<"source">>, db_url(From, Source)}, + {<<"target">>, db_url(To, Target)}, + {<<"filter">>, <<"filter_ddoc/queryfilter">>}, + {<<"query_params">>, {[ + {<<"starts">>, <<"a">>} + ]}} + ]}, + {ok, _} = couch_replicator:replicate(RepObject, ?ADMIN_USER), + FilterFun = fun(_DocId, {Props}) -> + case couch_util:get_value(<<"class">>, Props) of + <<"a", _/binary>> -> true; + _ -> false + end + end, + {ok, TargetDbInfo, AllReplies} = compare_dbs(Source, Target, FilterFun), + {lists:flatten(io_lib:format("~p -> ~p", [From, To])), [ + {"Target DB has proper number of docs", + ?_assertEqual(2, proplists:get_value(doc_count, TargetDbInfo))}, + {"Target DB doesn't have deleted docs", + ?_assertEqual(0, proplists:get_value(doc_del_count, TargetDbInfo))}, + {"All the docs filtered as expected", + ?_assert(lists:all(fun(Valid) -> Valid end, AllReplies))} + ]}. + compare_dbs(Source, Target, FilterFun) -> {ok, SourceDb} = couch_db:open_int(Source, []), {ok, TargetDb} = couch_db:open_int(Target, []), @@ -120,6 +168,7 @@ create_docs(DbName) -> ]}), Doc2 = couch_doc:from_json_obj({[ {<<"_id">>, <<"doc2">>}, + {<<"class">>, <<"amphibians">>}, {<<"value">>, 2} ]}), @@ -129,7 +178,13 @@ create_docs(DbName) -> {<<"value">>, 3} ]}), - {ok, _} = couch_db:update_docs(Db, [DDoc, Doc1, Doc2, Doc3]), + Doc4 = couch_doc:from_json_obj({[ + {<<"_id">>, <<"doc4">>}, + {<<"class">>, <<"arthropods">>}, + {<<"value">>, 2} + + ]}), + {ok, _} = couch_db:update_docs(Db, [DDoc, Doc1, Doc2, Doc3, Doc4]), couch_db:ensure_full_commit(Db), couch_db:close(Db).