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 CAD9C116A1 for ; Thu, 28 Aug 2014 17:27:25 +0000 (UTC) Received: (qmail 1795 invoked by uid 500); 28 Aug 2014 17:27:25 -0000 Delivered-To: apmail-couchdb-commits-archive@couchdb.apache.org Received: (qmail 1751 invoked by uid 500); 28 Aug 2014 17:27:25 -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 1742 invoked by uid 99); 28 Aug 2014 17:27:25 -0000 Received: from tyr.zones.apache.org (HELO tyr.zones.apache.org) (140.211.11.114) by apache.org (qpsmtpd/0.29) with ESMTP; Thu, 28 Aug 2014 17:27:25 +0000 Received: by tyr.zones.apache.org (Postfix, from userid 65534) id 4D134A04A18; Thu, 28 Aug 2014 17:27:25 +0000 (UTC) Content-Type: text/plain; charset="us-ascii" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit From: chewbranca@apache.org To: commits@couchdb.apache.org Date: Thu, 28 Aug 2014 17:27:38 -0000 Message-Id: <8161ec386df44303861502216ae9a237@git.apache.org> In-Reply-To: <246c8843d93a42e78b3768a98479c21c@git.apache.org> References: <246c8843d93a42e78b3768a98479c21c@git.apache.org> X-Mailer: ASF-Git Admin Mailer Subject: [16/22] couch-mrview commit: updated refs/heads/1963-eunit-bigcouch to cc9c436 Port couch_mrview/07-compact-swap.t etap test suite to eunit Project: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/repo Commit: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/commit/7644769a Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/7644769a Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/7644769a Branch: refs/heads/1963-eunit-bigcouch Commit: 7644769a73acad3ff523cbaba2374d9976242ae6 Parents: 40e770e Author: Alexander Shorin Authored: Thu Jun 12 02:44:30 2014 +0400 Committer: Russell Branca Committed: Thu Aug 28 10:27:05 2014 -0700 ---------------------------------------------------------------------- .../test/couch_mrview_compact_tests.erl | 101 +++++++++++++++++++ test/07-compact-swap.t | 57 ----------- 2 files changed, 101 insertions(+), 57 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/7644769a/src/couch_mrview/test/couch_mrview_compact_tests.erl ---------------------------------------------------------------------- diff --git a/src/couch_mrview/test/couch_mrview_compact_tests.erl b/src/couch_mrview/test/couch_mrview_compact_tests.erl new file mode 100644 index 0000000..62d0362 --- /dev/null +++ b/src/couch_mrview/test/couch_mrview_compact_tests.erl @@ -0,0 +1,101 @@ +% 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_mrview_compact_tests). + +-include("../../../test/couchdb/couch_eunit.hrl"). +-include_lib("couchdb/couch_db.hrl"). + +-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}). +-define(TIMEOUT, 1000). + + +start() -> + {ok, Pid} = couch_server_sup:start_link(?CONFIG_CHAIN), + Pid. + +stop(Pid) -> + erlang:monitor(process, Pid), + couch_server_sup:stop(), + receive + {'DOWN', _, _, Pid, _} -> + ok + after ?TIMEOUT -> + throw({timeout, server_stop}) + end. + +setup() -> + {ok, Db} = couch_mrview_test_util:init_db(?tempdb(), map, 1000), + Db. + +teardown(Db) -> + couch_db:close(Db), + couch_server:delete(Db#db.name, [?ADMIN_USER]), + ok. + + +compaction_test_() -> + { + "Compaction tests", + { + setup, + fun start/0, fun stop/1, + { + foreach, + fun setup/0, fun teardown/1, + [ + fun should_swap/1 + ] + } + } + }. + + +should_swap(Db) -> + ?_test(begin + couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>), + {ok, QPid} = start_query(Db), + {ok, MonRef} = couch_mrview:compact(Db, <<"_design/bar">>, [monitor]), + receive + {'DOWN', MonRef, process, _, _} -> ok + after ?TIMEOUT -> + erlang:error( + {assertion_failed, + [{module, ?MODULE}, {line, ?LINE}, + {reason, "compaction failed"}]}) + end, + QPid ! {self(), continue}, + receive + {QPid, Count} -> + ?assertEqual(1000, Count) + after ?TIMEOUT -> + erlang:error( + {assertion_failed, + [{module, ?MODULE}, {line, ?LINE}, + {reason, "query failed"}]}) + end + end). + + +start_query(Db) -> + Self = self(), + Pid = spawn(fun() -> + CB = fun + (_, wait) -> receive {Self, continue} -> {ok, 0} end; + ({row, _}, Count) -> {ok, Count+1}; + (_, Count) -> {ok, Count} + end, + {ok, Result} = + couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, [], CB, wait), + Self ! {self(), Result} + end), + {ok, Pid}. http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/7644769a/test/07-compact-swap.t ---------------------------------------------------------------------- diff --git a/test/07-compact-swap.t b/test/07-compact-swap.t deleted file mode 100644 index c1fd043..0000000 --- a/test/07-compact-swap.t +++ /dev/null @@ -1,57 +0,0 @@ -#!/usr/bin/env escript -%% -*- erlang -*- - -% 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. - -main(_) -> - test_util:run(1, fun() -> test() end). - - -test() -> - test_util:start_couch(), - {ok, Db} = couch_mrview_test_util:init_db(<<"foo">>, map, 1000), - couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>), - test_swap(Db), - ok. - - -test_swap(Db) -> - {ok, QPid} = start_query(Db), - {ok, MonRef} = couch_mrview:compact(Db, <<"_design/bar">>, [monitor]), - receive - {'DOWN', MonRef, process, _, _} -> ok - after 1000 -> - throw(compaction_failed) - end, - QPid ! {self(), continue}, - receive - {QPid, Count} -> - etap:is(Count, 1000, "View finished successfully.") - after 1000 -> - throw("query failed") - end. - - -start_query(Db) -> - Self = self(), - Pid = spawn(fun() -> - CB = fun - (_, wait) -> receive {Self, continue} -> {ok, 0} end; - ({row, _}, Count) -> {ok, Count+1}; - (_, Count) -> {ok, Count} - end, - {ok, Result} = - couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, [], CB, wait), - Self ! {self(), Result} - end), - {ok, Pid}.