You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@couchdb.apache.org by ch...@apache.org on 2014/08/28 19:27:40 UTC
[18/22] couch-mrview commit: updated refs/heads/1963-eunit-bigcouch
to cc9c436
Move files out of test/couchdb into top level test/ folder
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/d6aa4147
Tree: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/tree/d6aa4147
Diff: http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/diff/d6aa4147
Branch: refs/heads/1963-eunit-bigcouch
Commit: d6aa4147fbdefd445f9cd1a15bb2c7573fa378a4
Parents: 7644769
Author: Russell Branca <ch...@apache.org>
Authored: Wed Aug 27 17:13:16 2014 -0700
Committer: Russell Branca <ch...@apache.org>
Committed: Thu Aug 28 10:27:05 2014 -0700
----------------------------------------------------------------------
.../test/couch_mrview_all_docs_tests.erl | 154 --------------
.../test/couch_mrview_collation_tests.erl | 202 -------------------
.../test/couch_mrview_compact_tests.erl | 101 ----------
.../test/couch_mrview_index_info_tests.erl | 87 --------
.../test/couch_mrview_map_views_tests.erl | 138 -------------
.../test/couch_mrview_modules_load_tests.erl | 37 ----
.../test/couch_mrview_red_views_tests.erl | 110 ----------
test/couch_mrview_all_docs_tests.erl | 154 ++++++++++++++
test/couch_mrview_collation_tests.erl | 202 +++++++++++++++++++
test/couch_mrview_compact_tests.erl | 101 ++++++++++
test/couch_mrview_index_info_tests.erl | 87 ++++++++
test/couch_mrview_map_views_tests.erl | 138 +++++++++++++
test/couch_mrview_modules_load_tests.erl | 37 ++++
test/couch_mrview_red_views_tests.erl | 110 ++++++++++
14 files changed, 829 insertions(+), 829 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/src/couch_mrview/test/couch_mrview_all_docs_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_all_docs_tests.erl b/src/couch_mrview/test/couch_mrview_all_docs_tests.erl
deleted file mode 100644
index 6d73c68..0000000
--- a/src/couch_mrview/test/couch_mrview_all_docs_tests.erl
+++ /dev/null
@@ -1,154 +0,0 @@
-% 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_all_docs_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),
- Db.
-
-teardown(Db) ->
- couch_db:close(Db),
- couch_server:delete(Db#db.name, [?ADMIN_USER]),
- ok.
-
-
-all_docs_test_() ->
- {
- "_all_docs view tests",
- {
- setup,
- fun start/0, fun stop/1,
- {
- foreach,
- fun setup/0, fun teardown/1,
- [
- fun should_query/1,
- fun should_query_with_range/1,
- fun should_query_with_range_rev/1,
- fun should_query_with_limit_and_skip/1,
- fun should_query_with_include_docs/1,
- fun should_query_empty_views/1
- ]
- }
- }
- }.
-
-
-should_query(Db) ->
- Result = run_query(Db, []),
- Expect = {ok, [
- {meta, [{total, 11}, {offset, 0}]},
- mk_row(<<"1">>, <<"1-08d53a5760b95fce6df2e2c5b008be39">>),
- mk_row(<<"10">>, <<"1-a05b6ea2bc0243949f103d5b4f15f71e">>),
- mk_row(<<"2">>, <<"1-b57c77a9e6f7574ca6469f0d6dcd78bb">>),
- mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>),
- mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
- mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
- mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>),
- mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>),
- mk_row(<<"8">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>),
- mk_row(<<"9">>, <<"1-558c8487d9aee25399a91b5d31d90fe2">>),
- mk_row(<<"_design/bar">>, <<"1-a44e1dd1994a7717bf89c894ebd1f081">>)
- ]},
- ?_assertEqual(Expect, Result).
-
-should_query_with_range(Db) ->
- Result = run_query(Db, [{start_key, <<"3">>}, {end_key, <<"5">>}]),
- Expect = {ok, [
- {meta, [{total, 11}, {offset, 3}]},
- mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>),
- mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
- mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>)
- ]},
- ?_assertEqual(Expect, Result).
-
-should_query_with_range_rev(Db) ->
- Result = run_query(Db, [
- {direction, rev},
- {start_key, <<"5">>}, {end_key, <<"3">>},
- {inclusive_end, true}
- ]),
- Expect = {ok, [
- {meta, [{total, 11}, {offset, 5}]},
- mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
- mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
- mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>)
- ]},
- ?_assertEqual(Expect, Result).
-
-should_query_with_limit_and_skip(Db) ->
- Result = run_query(Db, [
- {start_key, <<"2">>},
- {limit, 3},
- {skip, 3}
- ]),
- Expect = {ok, [
- {meta, [{total, 11}, {offset, 5}]},
- mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
- mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>),
- mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>)
- ]},
- ?_assertEqual(Expect, Result).
-
-should_query_with_include_docs(Db) ->
- Result = run_query(Db, [
- {start_key, <<"8">>},
- {end_key, <<"8">>},
- {include_docs, true}
- ]),
- Doc = {[
- {<<"_id">>,<<"8">>},
- {<<"_rev">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>},
- {<<"val">>, 8}
- ]},
- Val = {[{rev, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>}]},
- Expect = {ok, [
- {meta, [{total, 11}, {offset, 8}]},
- {row, [{id, <<"8">>}, {key, <<"8">>}, {value, Val}, {doc, Doc}]}
- ]},
- ?_assertEqual(Expect, Result).
-
-should_query_empty_views(Db) ->
- Result = couch_mrview:query_view(Db, <<"_design/bar">>, <<"bing">>),
- Expect = {ok, [
- {meta, [{total, 0}, {offset, 0}]}
- ]},
- ?_assertEqual(Expect, Result).
-
-
-mk_row(Id, Rev) ->
- {row, [{id, Id}, {key, Id}, {value, {[{rev, Rev}]}}]}.
-
-run_query(Db, Opts) ->
- couch_mrview:query_all_docs(Db, Opts).
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/src/couch_mrview/test/couch_mrview_collation_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_collation_tests.erl b/src/couch_mrview/test/couch_mrview_collation_tests.erl
deleted file mode 100644
index 485fd2d..0000000
--- a/src/couch_mrview/test/couch_mrview_collation_tests.erl
+++ /dev/null
@@ -1,202 +0,0 @@
-% 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_collation_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).
--define(VALUES, [
- null,
- false,
- true,
-
- 1,
- 2,
- 3.0,
- 4,
-
- <<"a">>,
- <<"A">>,
- <<"aa">>,
- <<"b">>,
- <<"B">>,
- <<"ba">>,
- <<"bb">>,
-
- [<<"a">>],
- [<<"b">>],
- [<<"b">>, <<"c">>],
- [<<"b">>, <<"c">>, <<"a">>],
- [<<"b">>, <<"d">>],
- [<<"b">>, <<"d">>, <<"e">>],
-
- {[{<<"a">>, 1}]},
- {[{<<"a">>, 2}]},
- {[{<<"b">>, 1}]},
- {[{<<"b">>, 2}]},
- {[{<<"b">>, 2}, {<<"a">>, 1}]},
- {[{<<"b">>, 2}, {<<"c">>, 2}]}
-]).
-
-
-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, Db1} = couch_mrview_test_util:new_db(?tempdb(), map),
- {ok, Db2} = couch_mrview_test_util:save_docs(Db1, make_docs()),
- Db2.
-
-teardown(Db) ->
- couch_db:close(Db),
- couch_server:delete(Db#db.name, [?ADMIN_USER]),
- ok.
-
-
-collation_test_() ->
- {
- "Collation tests",
- {
- setup,
- fun start/0, fun stop/1,
- {
- foreach,
- fun setup/0, fun teardown/1,
- [
- fun should_collate_fwd/1,
- fun should_collate_rev/1,
- fun should_collate_range/1,
- fun should_collate_with_inclusive_end_fwd/1,
- fun should_collate_with_inclusive_end_rev/1,
- fun should_collate_without_inclusive_end_fwd/1,
- fun should_collate_without_inclusive_end_rev/1,
- fun should_collate_with_endkey_docid/1
- ]
- }
- }
- }.
-
-
-should_collate_fwd(Db) ->
- {ok, Results} = run_query(Db, []),
- Expect = [{meta, [{total, 26}, {offset, 0}]}] ++ rows(),
- %% cannot use _assertEqual since mrview converts
- %% value 3.0 to 3 making assertion fail
- ?_assert(Expect == Results).
-
-should_collate_rev(Db) ->
- {ok, Results} = run_query(Db, [{direction, rev}]),
- Expect = [{meta, [{total, 26}, {offset, 0}]}] ++ lists:reverse(rows()),
- %% cannot use _assertEqual since mrview converts
- %% value 3.0 to 3 making assertion fail
- ?_assert(Expect == Results).
-
-should_collate_range(Db) ->
- ?_assertNot(
- begin
- {_, Error} = lists:foldl(fun(V, {Count, Error}) ->
- {ok, Results} = run_query(Db, [{start_key, V}, {end_key, V}]),
- Id = list_to_binary(integer_to_list(Count)),
- Expect = [
- {meta, [{total, 26}, {offset, Count}]},
- {row, [{id, Id}, {key, V}, {value, 0}]}
- ],
- case Results == Expect of
- true -> {Count+1, Error};
- _ -> {Count+1, true}
- end
- end, {0, false}, ?VALUES),
- Error
- end).
-
-should_collate_with_inclusive_end_fwd(Db) ->
- Opts = [{end_key, <<"b">>}, {inclusive_end, true}],
- {ok, Rows0} = run_query(Db, Opts),
- LastRow = lists:last(Rows0),
- Expect = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
- ?_assertEqual(Expect, LastRow).
-
-should_collate_with_inclusive_end_rev(Db) ->
- Opts = [{end_key, <<"b">>}, {inclusive_end, true}, {direction, rev}],
- {ok, Rows} = run_query(Db, Opts),
- LastRow = lists:last(Rows),
- Expect = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
- ?_assertEqual(Expect, LastRow).
-
-should_collate_without_inclusive_end_fwd(Db) ->
- Opts = [{end_key, <<"b">>}, {inclusive_end, false}],
- {ok, Rows0} = run_query(Db, Opts),
- LastRow = lists:last(Rows0),
- Expect = {row, [{id,<<"9">>}, {key,<<"aa">>}, {value,0}]},
- ?_assertEqual(Expect, LastRow).
-
-should_collate_without_inclusive_end_rev(Db) ->
- Opts = [{end_key, <<"b">>}, {inclusive_end, false}, {direction, rev}],
- {ok, Rows} = run_query(Db, Opts),
- LastRow = lists:last(Rows),
- Expect = {row, [{id,<<"11">>}, {key,<<"B">>}, {value,0}]},
- ?_assertEqual(Expect, LastRow).
-
-should_collate_with_endkey_docid(Db) ->
- ?_test(begin
- {ok, Rows0} = run_query(Db, [
- {end_key, <<"b">>}, {end_key_docid, <<"10">>},
- {inclusive_end, false}
- ]),
- Result0 = lists:last(Rows0),
- Expect0 = {row, [{id,<<"9">>}, {key,<<"aa">>}, {value,0}]},
- ?assertEqual(Expect0, Result0),
-
- {ok, Rows1} = run_query(Db, [
- {end_key, <<"b">>}, {end_key_docid, <<"11">>},
- {inclusive_end, false}
- ]),
- Result1 = lists:last(Rows1),
- Expect1 = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
- ?assertEqual(Expect1, Result1)
- end).
-
-
-make_docs() ->
- {Docs, _} = lists:foldl(fun(V, {Docs0, Count}) ->
- Doc = couch_doc:from_json_obj({[
- {<<"_id">>, list_to_binary(integer_to_list(Count))},
- {<<"foo">>, V}
- ]}),
- {[Doc | Docs0], Count+1}
- end, {[], 0}, ?VALUES),
- Docs.
-
-rows() ->
- {Rows, _} = lists:foldl(fun(V, {Rows0, Count}) ->
- Id = list_to_binary(integer_to_list(Count)),
- Row = {row, [{id, Id}, {key, V}, {value, 0}]},
- {[Row | Rows0], Count+1}
- end, {[], 0}, ?VALUES),
- lists:reverse(Rows).
-
-run_query(Db, Opts) ->
- couch_mrview:query_view(Db, <<"_design/bar">>, <<"zing">>, Opts).
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/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
deleted file mode 100644
index 62d0362..0000000
--- a/src/couch_mrview/test/couch_mrview_compact_tests.erl
+++ /dev/null
@@ -1,101 +0,0 @@
-% 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/d6aa4147/src/couch_mrview/test/couch_mrview_index_info_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_index_info_tests.erl b/src/couch_mrview/test/couch_mrview_index_info_tests.erl
deleted file mode 100644
index 0867a72..0000000
--- a/src/couch_mrview/test/couch_mrview_index_info_tests.erl
+++ /dev/null
@@ -1,87 +0,0 @@
-% 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_index_info_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),
- couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
- {ok, Info} = couch_mrview:get_info(Db, <<"_design/bar">>),
- {Db, Info}.
-
-teardown({Db, _}) ->
- couch_db:close(Db),
- couch_server:delete(Db#db.name, [?ADMIN_USER]),
- ok.
-
-
-view_info_test_() ->
- {
- "Views index tests",
- {
- setup,
- fun start/0, fun stop/1,
- {
- foreach,
- fun setup/0, fun teardown/1,
- [
- fun should_get_property/1
- ]
- }
- }
- }.
-
-
-should_get_property({_, Info}) ->
- InfoProps = [
- {signature, <<"276df562b152b3c4e5d34024f62672ed">>},
- {language, <<"javascript">>},
- {disk_size, 314},
- {data_size, 263},
- {update_seq, 11},
- {purge_seq, 0},
- {updater_running, false},
- {compact_running, false},
- {waiting_clients, 0}
- ],
- [
- {atom_to_list(Key), ?_assertEqual(Val, getval(Key, Info))}
- || {Key, Val} <- InfoProps
- ].
-
-
-getval(Key, PL) ->
- {value, {Key, Val}} = lists:keysearch(Key, 1, PL),
- Val.
-
-
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/src/couch_mrview/test/couch_mrview_map_views_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_map_views_tests.erl b/src/couch_mrview/test/couch_mrview_map_views_tests.erl
deleted file mode 100644
index c09490e..0000000
--- a/src/couch_mrview/test/couch_mrview_map_views_tests.erl
+++ /dev/null
@@ -1,138 +0,0 @@
-% 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_map_views_tests).
-
--include("../../../test/couchdb/couch_eunit.hrl").
--include_lib("couchdb/couch_db.hrl").
-
--define(TIMEOUT, 1000).
--define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
-
-
-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),
- Db.
-
-teardown(Db) ->
- couch_db:close(Db),
- couch_server:delete(Db#db.name, [?ADMIN_USER]),
- ok.
-
-
-map_views_test_() ->
- {
- "Map views",
- {
- setup,
- fun start/0, fun stop/1,
- {
- foreach,
- fun setup/0, fun teardown/1,
- [
- fun should_map/1,
- fun should_map_with_range/1,
- fun should_map_with_limit_and_skip/1,
- fun should_map_with_include_docs/1,
- fun should_map_empty_views/1
- ]
- }
- }
- }.
-
-
-should_map(Db) ->
- Result = run_query(Db, []),
- Expect = {ok, [
- {meta, [{total, 10}, {offset, 0}]},
- {row, [{id, <<"1">>}, {key, 1}, {value, 1}]},
- {row, [{id, <<"2">>}, {key, 2}, {value, 2}]},
- {row, [{id, <<"3">>}, {key, 3}, {value, 3}]},
- {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
- {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
- {row, [{id, <<"6">>}, {key, 6}, {value, 6}]},
- {row, [{id, <<"7">>}, {key, 7}, {value, 7}]},
- {row, [{id, <<"8">>}, {key, 8}, {value, 8}]},
- {row, [{id, <<"9">>}, {key, 9}, {value, 9}]},
- {row, [{id, <<"10">>}, {key, 10}, {value, 10}]}
- ]},
- ?_assertEqual(Expect, Result).
-
-should_map_with_range(Db) ->
- Result = run_query(Db, [
- {direction, rev},
- {start_key, 5}, {end_key, 3},
- {inclusive_end, true}
- ]),
- Expect = {ok, [
- {meta, [{total, 10}, {offset, 5}]},
- {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
- {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
- {row, [{id, <<"3">>}, {key, 3}, {value, 3}]}
- ]},
- ?_assertEqual(Expect, Result).
-
-should_map_with_limit_and_skip(Db) ->
- Result = run_query(Db, [
- {start_key, 2},
- {limit, 3},
- {skip, 3}
- ]),
- Expect = {ok, [
- {meta, [{total, 10}, {offset, 4}]},
- {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
- {row, [{id, <<"6">>}, {key, 6}, {value, 6}]},
- {row, [{id, <<"7">>}, {key, 7}, {value, 7}]}
- ]},
- ?_assertEqual(Expect, Result).
-
-should_map_with_include_docs(Db) ->
- Result = run_query(Db, [
- {start_key, 8},
- {end_key, 8},
- {include_docs, true}
- ]),
- Doc = {[
- {<<"_id">>,<<"8">>},
- {<<"_rev">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>},
- {<<"val">>,8}
- ]},
- Expect = {ok, [
- {meta, [{total, 10}, {offset, 7}]},
- {row, [{id, <<"8">>}, {key, 8}, {value, 8}, {doc, Doc}]}
- ]},
- ?_assertEqual(Expect, Result).
-
-should_map_empty_views(Db) ->
- Result = couch_mrview:query_view(Db, <<"_design/bar">>, <<"bing">>),
- Expect = {ok, [
- {meta, [{total, 0}, {offset, 0}]}
- ]},
- ?_assertEqual(Expect, Result).
-
-
-run_query(Db, Opts) ->
- couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, Opts).
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/src/couch_mrview/test/couch_mrview_modules_load_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_modules_load_tests.erl b/src/couch_mrview/test/couch_mrview_modules_load_tests.erl
deleted file mode 100644
index a6f752a..0000000
--- a/src/couch_mrview/test/couch_mrview_modules_load_tests.erl
+++ /dev/null
@@ -1,37 +0,0 @@
-% 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_modules_load_tests).
-
--include("../../../test/couchdb/couch_eunit.hrl").
-
-
-modules_load_test_() ->
- {
- "Verify that all modules loads",
- should_load_modules()
- }.
-
-
-should_load_modules() ->
- Modules = [
- couch_mrview,
- couch_mrview_compactor,
- couch_mrview_http,
- couch_mrview_index,
- couch_mrview_updater,
- couch_mrview_util
- ],
- [should_load_module(Mod) || Mod <- Modules].
-
-should_load_module(Mod) ->
- {atom_to_list(Mod), ?_assertMatch({module, _}, code:load_file(Mod))}.
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/src/couch_mrview/test/couch_mrview_red_views_tests.erl
----------------------------------------------------------------------
diff --git a/src/couch_mrview/test/couch_mrview_red_views_tests.erl b/src/couch_mrview/test/couch_mrview_red_views_tests.erl
deleted file mode 100644
index 59333e8..0000000
--- a/src/couch_mrview/test/couch_mrview_red_views_tests.erl
+++ /dev/null
@@ -1,110 +0,0 @@
-% 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_red_views_tests).
-
--include("../../../test/couchdb/couch_eunit.hrl").
--include_lib("couchdb/couch_db.hrl").
-
--define(TIMEOUT, 1000).
--define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
-
-
-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(), red),
- Db.
-
-teardown(Db) ->
- couch_db:close(Db),
- couch_server:delete(Db#db.name, [?ADMIN_USER]),
- ok.
-
-
-reduce_views_test_() ->
- {
- "Reduce views",
- {
- setup,
- fun start/0, fun stop/1,
- {
- foreach,
- fun setup/0, fun teardown/1,
- [
- fun should_reduce_basic/1,
- fun should_reduce_key_range/1,
- fun should_reduce_with_group_level/1,
- fun should_reduce_with_group_exact/1
- ]
- }
- }
- }.
-
-
-should_reduce_basic(Db) ->
- Result = run_query(Db, []),
- Expect = {ok, [
- {meta, []},
- {row, [{key, null}, {value, 55}]}
- ]},
- ?_assertEqual(Expect, Result).
-
-should_reduce_key_range(Db) ->
- Result = run_query(Db, [{start_key, [0, 2]}, {end_key, [0, 4]}]),
- Expect = {ok, [
- {meta, []},
- {row, [{key, null}, {value, 6}]}
- ]},
- ?_assertEqual(Expect, Result).
-
-should_reduce_with_group_level(Db) ->
- Result = run_query(Db, [{group_level, 1}]),
- Expect = {ok, [
- {meta, []},
- {row, [{key, [0]}, {value, 30}]},
- {row, [{key, [1]}, {value, 25}]}
- ]},
- ?_assertEqual(Expect, Result).
-
-should_reduce_with_group_exact(Db) ->
- Result = run_query(Db, [{group_level, exact}]),
- Expect = {ok, [
- {meta, []},
- {row, [{key, [0, 2]}, {value, 2}]},
- {row, [{key, [0, 4]}, {value, 4}]},
- {row, [{key, [0, 6]}, {value, 6}]},
- {row, [{key, [0, 8]}, {value, 8}]},
- {row, [{key, [0, 10]}, {value, 10}]},
- {row, [{key, [1, 1]}, {value, 1}]},
- {row, [{key, [1, 3]}, {value, 3}]},
- {row, [{key, [1, 5]}, {value, 5}]},
- {row, [{key, [1, 7]}, {value, 7}]},
- {row, [{key, [1, 9]}, {value, 9}]}
- ]},
- ?_assertEqual(Expect, Result).
-
-
-run_query(Db, Opts) ->
- couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, Opts).
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_all_docs_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_all_docs_tests.erl b/test/couch_mrview_all_docs_tests.erl
new file mode 100644
index 0000000..6d73c68
--- /dev/null
+++ b/test/couch_mrview_all_docs_tests.erl
@@ -0,0 +1,154 @@
+% 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_all_docs_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),
+ Db.
+
+teardown(Db) ->
+ couch_db:close(Db),
+ couch_server:delete(Db#db.name, [?ADMIN_USER]),
+ ok.
+
+
+all_docs_test_() ->
+ {
+ "_all_docs view tests",
+ {
+ setup,
+ fun start/0, fun stop/1,
+ {
+ foreach,
+ fun setup/0, fun teardown/1,
+ [
+ fun should_query/1,
+ fun should_query_with_range/1,
+ fun should_query_with_range_rev/1,
+ fun should_query_with_limit_and_skip/1,
+ fun should_query_with_include_docs/1,
+ fun should_query_empty_views/1
+ ]
+ }
+ }
+ }.
+
+
+should_query(Db) ->
+ Result = run_query(Db, []),
+ Expect = {ok, [
+ {meta, [{total, 11}, {offset, 0}]},
+ mk_row(<<"1">>, <<"1-08d53a5760b95fce6df2e2c5b008be39">>),
+ mk_row(<<"10">>, <<"1-a05b6ea2bc0243949f103d5b4f15f71e">>),
+ mk_row(<<"2">>, <<"1-b57c77a9e6f7574ca6469f0d6dcd78bb">>),
+ mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>),
+ mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
+ mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
+ mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>),
+ mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>),
+ mk_row(<<"8">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>),
+ mk_row(<<"9">>, <<"1-558c8487d9aee25399a91b5d31d90fe2">>),
+ mk_row(<<"_design/bar">>, <<"1-a44e1dd1994a7717bf89c894ebd1f081">>)
+ ]},
+ ?_assertEqual(Expect, Result).
+
+should_query_with_range(Db) ->
+ Result = run_query(Db, [{start_key, <<"3">>}, {end_key, <<"5">>}]),
+ Expect = {ok, [
+ {meta, [{total, 11}, {offset, 3}]},
+ mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>),
+ mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
+ mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>)
+ ]},
+ ?_assertEqual(Expect, Result).
+
+should_query_with_range_rev(Db) ->
+ Result = run_query(Db, [
+ {direction, rev},
+ {start_key, <<"5">>}, {end_key, <<"3">>},
+ {inclusive_end, true}
+ ]),
+ Expect = {ok, [
+ {meta, [{total, 11}, {offset, 5}]},
+ mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
+ mk_row(<<"4">>, <<"1-fcaf5852c08ffb239ac8ce16c409f253">>),
+ mk_row(<<"3">>, <<"1-7fbf84d56f8017880974402d60f5acd6">>)
+ ]},
+ ?_assertEqual(Expect, Result).
+
+should_query_with_limit_and_skip(Db) ->
+ Result = run_query(Db, [
+ {start_key, <<"2">>},
+ {limit, 3},
+ {skip, 3}
+ ]),
+ Expect = {ok, [
+ {meta, [{total, 11}, {offset, 5}]},
+ mk_row(<<"5">>, <<"1-aaac5d460fd40f9286e57b9bf12e23d2">>),
+ mk_row(<<"6">>, <<"1-aca21c2e7bc5f8951424fcfc5d1209d8">>),
+ mk_row(<<"7">>, <<"1-4374aeec17590d82f16e70f318116ad9">>)
+ ]},
+ ?_assertEqual(Expect, Result).
+
+should_query_with_include_docs(Db) ->
+ Result = run_query(Db, [
+ {start_key, <<"8">>},
+ {end_key, <<"8">>},
+ {include_docs, true}
+ ]),
+ Doc = {[
+ {<<"_id">>,<<"8">>},
+ {<<"_rev">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>},
+ {<<"val">>, 8}
+ ]},
+ Val = {[{rev, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>}]},
+ Expect = {ok, [
+ {meta, [{total, 11}, {offset, 8}]},
+ {row, [{id, <<"8">>}, {key, <<"8">>}, {value, Val}, {doc, Doc}]}
+ ]},
+ ?_assertEqual(Expect, Result).
+
+should_query_empty_views(Db) ->
+ Result = couch_mrview:query_view(Db, <<"_design/bar">>, <<"bing">>),
+ Expect = {ok, [
+ {meta, [{total, 0}, {offset, 0}]}
+ ]},
+ ?_assertEqual(Expect, Result).
+
+
+mk_row(Id, Rev) ->
+ {row, [{id, Id}, {key, Id}, {value, {[{rev, Rev}]}}]}.
+
+run_query(Db, Opts) ->
+ couch_mrview:query_all_docs(Db, Opts).
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_collation_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_collation_tests.erl b/test/couch_mrview_collation_tests.erl
new file mode 100644
index 0000000..485fd2d
--- /dev/null
+++ b/test/couch_mrview_collation_tests.erl
@@ -0,0 +1,202 @@
+% 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_collation_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).
+-define(VALUES, [
+ null,
+ false,
+ true,
+
+ 1,
+ 2,
+ 3.0,
+ 4,
+
+ <<"a">>,
+ <<"A">>,
+ <<"aa">>,
+ <<"b">>,
+ <<"B">>,
+ <<"ba">>,
+ <<"bb">>,
+
+ [<<"a">>],
+ [<<"b">>],
+ [<<"b">>, <<"c">>],
+ [<<"b">>, <<"c">>, <<"a">>],
+ [<<"b">>, <<"d">>],
+ [<<"b">>, <<"d">>, <<"e">>],
+
+ {[{<<"a">>, 1}]},
+ {[{<<"a">>, 2}]},
+ {[{<<"b">>, 1}]},
+ {[{<<"b">>, 2}]},
+ {[{<<"b">>, 2}, {<<"a">>, 1}]},
+ {[{<<"b">>, 2}, {<<"c">>, 2}]}
+]).
+
+
+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, Db1} = couch_mrview_test_util:new_db(?tempdb(), map),
+ {ok, Db2} = couch_mrview_test_util:save_docs(Db1, make_docs()),
+ Db2.
+
+teardown(Db) ->
+ couch_db:close(Db),
+ couch_server:delete(Db#db.name, [?ADMIN_USER]),
+ ok.
+
+
+collation_test_() ->
+ {
+ "Collation tests",
+ {
+ setup,
+ fun start/0, fun stop/1,
+ {
+ foreach,
+ fun setup/0, fun teardown/1,
+ [
+ fun should_collate_fwd/1,
+ fun should_collate_rev/1,
+ fun should_collate_range/1,
+ fun should_collate_with_inclusive_end_fwd/1,
+ fun should_collate_with_inclusive_end_rev/1,
+ fun should_collate_without_inclusive_end_fwd/1,
+ fun should_collate_without_inclusive_end_rev/1,
+ fun should_collate_with_endkey_docid/1
+ ]
+ }
+ }
+ }.
+
+
+should_collate_fwd(Db) ->
+ {ok, Results} = run_query(Db, []),
+ Expect = [{meta, [{total, 26}, {offset, 0}]}] ++ rows(),
+ %% cannot use _assertEqual since mrview converts
+ %% value 3.0 to 3 making assertion fail
+ ?_assert(Expect == Results).
+
+should_collate_rev(Db) ->
+ {ok, Results} = run_query(Db, [{direction, rev}]),
+ Expect = [{meta, [{total, 26}, {offset, 0}]}] ++ lists:reverse(rows()),
+ %% cannot use _assertEqual since mrview converts
+ %% value 3.0 to 3 making assertion fail
+ ?_assert(Expect == Results).
+
+should_collate_range(Db) ->
+ ?_assertNot(
+ begin
+ {_, Error} = lists:foldl(fun(V, {Count, Error}) ->
+ {ok, Results} = run_query(Db, [{start_key, V}, {end_key, V}]),
+ Id = list_to_binary(integer_to_list(Count)),
+ Expect = [
+ {meta, [{total, 26}, {offset, Count}]},
+ {row, [{id, Id}, {key, V}, {value, 0}]}
+ ],
+ case Results == Expect of
+ true -> {Count+1, Error};
+ _ -> {Count+1, true}
+ end
+ end, {0, false}, ?VALUES),
+ Error
+ end).
+
+should_collate_with_inclusive_end_fwd(Db) ->
+ Opts = [{end_key, <<"b">>}, {inclusive_end, true}],
+ {ok, Rows0} = run_query(Db, Opts),
+ LastRow = lists:last(Rows0),
+ Expect = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
+ ?_assertEqual(Expect, LastRow).
+
+should_collate_with_inclusive_end_rev(Db) ->
+ Opts = [{end_key, <<"b">>}, {inclusive_end, true}, {direction, rev}],
+ {ok, Rows} = run_query(Db, Opts),
+ LastRow = lists:last(Rows),
+ Expect = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
+ ?_assertEqual(Expect, LastRow).
+
+should_collate_without_inclusive_end_fwd(Db) ->
+ Opts = [{end_key, <<"b">>}, {inclusive_end, false}],
+ {ok, Rows0} = run_query(Db, Opts),
+ LastRow = lists:last(Rows0),
+ Expect = {row, [{id,<<"9">>}, {key,<<"aa">>}, {value,0}]},
+ ?_assertEqual(Expect, LastRow).
+
+should_collate_without_inclusive_end_rev(Db) ->
+ Opts = [{end_key, <<"b">>}, {inclusive_end, false}, {direction, rev}],
+ {ok, Rows} = run_query(Db, Opts),
+ LastRow = lists:last(Rows),
+ Expect = {row, [{id,<<"11">>}, {key,<<"B">>}, {value,0}]},
+ ?_assertEqual(Expect, LastRow).
+
+should_collate_with_endkey_docid(Db) ->
+ ?_test(begin
+ {ok, Rows0} = run_query(Db, [
+ {end_key, <<"b">>}, {end_key_docid, <<"10">>},
+ {inclusive_end, false}
+ ]),
+ Result0 = lists:last(Rows0),
+ Expect0 = {row, [{id,<<"9">>}, {key,<<"aa">>}, {value,0}]},
+ ?assertEqual(Expect0, Result0),
+
+ {ok, Rows1} = run_query(Db, [
+ {end_key, <<"b">>}, {end_key_docid, <<"11">>},
+ {inclusive_end, false}
+ ]),
+ Result1 = lists:last(Rows1),
+ Expect1 = {row, [{id,<<"10">>}, {key,<<"b">>}, {value,0}]},
+ ?assertEqual(Expect1, Result1)
+ end).
+
+
+make_docs() ->
+ {Docs, _} = lists:foldl(fun(V, {Docs0, Count}) ->
+ Doc = couch_doc:from_json_obj({[
+ {<<"_id">>, list_to_binary(integer_to_list(Count))},
+ {<<"foo">>, V}
+ ]}),
+ {[Doc | Docs0], Count+1}
+ end, {[], 0}, ?VALUES),
+ Docs.
+
+rows() ->
+ {Rows, _} = lists:foldl(fun(V, {Rows0, Count}) ->
+ Id = list_to_binary(integer_to_list(Count)),
+ Row = {row, [{id, Id}, {key, V}, {value, 0}]},
+ {[Row | Rows0], Count+1}
+ end, {[], 0}, ?VALUES),
+ lists:reverse(Rows).
+
+run_query(Db, Opts) ->
+ couch_mrview:query_view(Db, <<"_design/bar">>, <<"zing">>, Opts).
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_compact_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_compact_tests.erl b/test/couch_mrview_compact_tests.erl
new file mode 100644
index 0000000..62d0362
--- /dev/null
+++ b/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/d6aa4147/test/couch_mrview_index_info_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_index_info_tests.erl b/test/couch_mrview_index_info_tests.erl
new file mode 100644
index 0000000..0867a72
--- /dev/null
+++ b/test/couch_mrview_index_info_tests.erl
@@ -0,0 +1,87 @@
+% 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_index_info_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),
+ couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>),
+ {ok, Info} = couch_mrview:get_info(Db, <<"_design/bar">>),
+ {Db, Info}.
+
+teardown({Db, _}) ->
+ couch_db:close(Db),
+ couch_server:delete(Db#db.name, [?ADMIN_USER]),
+ ok.
+
+
+view_info_test_() ->
+ {
+ "Views index tests",
+ {
+ setup,
+ fun start/0, fun stop/1,
+ {
+ foreach,
+ fun setup/0, fun teardown/1,
+ [
+ fun should_get_property/1
+ ]
+ }
+ }
+ }.
+
+
+should_get_property({_, Info}) ->
+ InfoProps = [
+ {signature, <<"276df562b152b3c4e5d34024f62672ed">>},
+ {language, <<"javascript">>},
+ {disk_size, 314},
+ {data_size, 263},
+ {update_seq, 11},
+ {purge_seq, 0},
+ {updater_running, false},
+ {compact_running, false},
+ {waiting_clients, 0}
+ ],
+ [
+ {atom_to_list(Key), ?_assertEqual(Val, getval(Key, Info))}
+ || {Key, Val} <- InfoProps
+ ].
+
+
+getval(Key, PL) ->
+ {value, {Key, Val}} = lists:keysearch(Key, 1, PL),
+ Val.
+
+
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_map_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_map_views_tests.erl b/test/couch_mrview_map_views_tests.erl
new file mode 100644
index 0000000..c09490e
--- /dev/null
+++ b/test/couch_mrview_map_views_tests.erl
@@ -0,0 +1,138 @@
+% 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_map_views_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(TIMEOUT, 1000).
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
+
+
+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),
+ Db.
+
+teardown(Db) ->
+ couch_db:close(Db),
+ couch_server:delete(Db#db.name, [?ADMIN_USER]),
+ ok.
+
+
+map_views_test_() ->
+ {
+ "Map views",
+ {
+ setup,
+ fun start/0, fun stop/1,
+ {
+ foreach,
+ fun setup/0, fun teardown/1,
+ [
+ fun should_map/1,
+ fun should_map_with_range/1,
+ fun should_map_with_limit_and_skip/1,
+ fun should_map_with_include_docs/1,
+ fun should_map_empty_views/1
+ ]
+ }
+ }
+ }.
+
+
+should_map(Db) ->
+ Result = run_query(Db, []),
+ Expect = {ok, [
+ {meta, [{total, 10}, {offset, 0}]},
+ {row, [{id, <<"1">>}, {key, 1}, {value, 1}]},
+ {row, [{id, <<"2">>}, {key, 2}, {value, 2}]},
+ {row, [{id, <<"3">>}, {key, 3}, {value, 3}]},
+ {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
+ {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
+ {row, [{id, <<"6">>}, {key, 6}, {value, 6}]},
+ {row, [{id, <<"7">>}, {key, 7}, {value, 7}]},
+ {row, [{id, <<"8">>}, {key, 8}, {value, 8}]},
+ {row, [{id, <<"9">>}, {key, 9}, {value, 9}]},
+ {row, [{id, <<"10">>}, {key, 10}, {value, 10}]}
+ ]},
+ ?_assertEqual(Expect, Result).
+
+should_map_with_range(Db) ->
+ Result = run_query(Db, [
+ {direction, rev},
+ {start_key, 5}, {end_key, 3},
+ {inclusive_end, true}
+ ]),
+ Expect = {ok, [
+ {meta, [{total, 10}, {offset, 5}]},
+ {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
+ {row, [{id, <<"4">>}, {key, 4}, {value, 4}]},
+ {row, [{id, <<"3">>}, {key, 3}, {value, 3}]}
+ ]},
+ ?_assertEqual(Expect, Result).
+
+should_map_with_limit_and_skip(Db) ->
+ Result = run_query(Db, [
+ {start_key, 2},
+ {limit, 3},
+ {skip, 3}
+ ]),
+ Expect = {ok, [
+ {meta, [{total, 10}, {offset, 4}]},
+ {row, [{id, <<"5">>}, {key, 5}, {value, 5}]},
+ {row, [{id, <<"6">>}, {key, 6}, {value, 6}]},
+ {row, [{id, <<"7">>}, {key, 7}, {value, 7}]}
+ ]},
+ ?_assertEqual(Expect, Result).
+
+should_map_with_include_docs(Db) ->
+ Result = run_query(Db, [
+ {start_key, 8},
+ {end_key, 8},
+ {include_docs, true}
+ ]),
+ Doc = {[
+ {<<"_id">>,<<"8">>},
+ {<<"_rev">>, <<"1-55b9a29311341e07ec0a7ca13bc1b59f">>},
+ {<<"val">>,8}
+ ]},
+ Expect = {ok, [
+ {meta, [{total, 10}, {offset, 7}]},
+ {row, [{id, <<"8">>}, {key, 8}, {value, 8}, {doc, Doc}]}
+ ]},
+ ?_assertEqual(Expect, Result).
+
+should_map_empty_views(Db) ->
+ Result = couch_mrview:query_view(Db, <<"_design/bar">>, <<"bing">>),
+ Expect = {ok, [
+ {meta, [{total, 0}, {offset, 0}]}
+ ]},
+ ?_assertEqual(Expect, Result).
+
+
+run_query(Db, Opts) ->
+ couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, Opts).
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_modules_load_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_modules_load_tests.erl b/test/couch_mrview_modules_load_tests.erl
new file mode 100644
index 0000000..a6f752a
--- /dev/null
+++ b/test/couch_mrview_modules_load_tests.erl
@@ -0,0 +1,37 @@
+% 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_modules_load_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+
+
+modules_load_test_() ->
+ {
+ "Verify that all modules loads",
+ should_load_modules()
+ }.
+
+
+should_load_modules() ->
+ Modules = [
+ couch_mrview,
+ couch_mrview_compactor,
+ couch_mrview_http,
+ couch_mrview_index,
+ couch_mrview_updater,
+ couch_mrview_util
+ ],
+ [should_load_module(Mod) || Mod <- Modules].
+
+should_load_module(Mod) ->
+ {atom_to_list(Mod), ?_assertMatch({module, _}, code:load_file(Mod))}.
http://git-wip-us.apache.org/repos/asf/couchdb-couch-mrview/blob/d6aa4147/test/couch_mrview_red_views_tests.erl
----------------------------------------------------------------------
diff --git a/test/couch_mrview_red_views_tests.erl b/test/couch_mrview_red_views_tests.erl
new file mode 100644
index 0000000..59333e8
--- /dev/null
+++ b/test/couch_mrview_red_views_tests.erl
@@ -0,0 +1,110 @@
+% 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_red_views_tests).
+
+-include("../../../test/couchdb/couch_eunit.hrl").
+-include_lib("couchdb/couch_db.hrl").
+
+-define(TIMEOUT, 1000).
+-define(ADMIN_USER, {user_ctx, #user_ctx{roles=[<<"_admin">>]}}).
+
+
+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(), red),
+ Db.
+
+teardown(Db) ->
+ couch_db:close(Db),
+ couch_server:delete(Db#db.name, [?ADMIN_USER]),
+ ok.
+
+
+reduce_views_test_() ->
+ {
+ "Reduce views",
+ {
+ setup,
+ fun start/0, fun stop/1,
+ {
+ foreach,
+ fun setup/0, fun teardown/1,
+ [
+ fun should_reduce_basic/1,
+ fun should_reduce_key_range/1,
+ fun should_reduce_with_group_level/1,
+ fun should_reduce_with_group_exact/1
+ ]
+ }
+ }
+ }.
+
+
+should_reduce_basic(Db) ->
+ Result = run_query(Db, []),
+ Expect = {ok, [
+ {meta, []},
+ {row, [{key, null}, {value, 55}]}
+ ]},
+ ?_assertEqual(Expect, Result).
+
+should_reduce_key_range(Db) ->
+ Result = run_query(Db, [{start_key, [0, 2]}, {end_key, [0, 4]}]),
+ Expect = {ok, [
+ {meta, []},
+ {row, [{key, null}, {value, 6}]}
+ ]},
+ ?_assertEqual(Expect, Result).
+
+should_reduce_with_group_level(Db) ->
+ Result = run_query(Db, [{group_level, 1}]),
+ Expect = {ok, [
+ {meta, []},
+ {row, [{key, [0]}, {value, 30}]},
+ {row, [{key, [1]}, {value, 25}]}
+ ]},
+ ?_assertEqual(Expect, Result).
+
+should_reduce_with_group_exact(Db) ->
+ Result = run_query(Db, [{group_level, exact}]),
+ Expect = {ok, [
+ {meta, []},
+ {row, [{key, [0, 2]}, {value, 2}]},
+ {row, [{key, [0, 4]}, {value, 4}]},
+ {row, [{key, [0, 6]}, {value, 6}]},
+ {row, [{key, [0, 8]}, {value, 8}]},
+ {row, [{key, [0, 10]}, {value, 10}]},
+ {row, [{key, [1, 1]}, {value, 1}]},
+ {row, [{key, [1, 3]}, {value, 3}]},
+ {row, [{key, [1, 5]}, {value, 5}]},
+ {row, [{key, [1, 7]}, {value, 7}]},
+ {row, [{key, [1, 9]}, {value, 9}]}
+ ]},
+ ?_assertEqual(Expect, Result).
+
+
+run_query(Db, Opts) ->
+ couch_mrview:query_view(Db, <<"_design/bar">>, <<"baz">>, Opts).