summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGarren Smith <garren.smith@gmail.com>2018-10-04 10:45:03 +0200
committerRobert Newson <rnewson@apache.org>2018-10-08 14:15:28 +0100
commit07bacf050eacf9c48e03df5044e75d155a9780f3 (patch)
tree7a9cae85d54a001ec6e39e41ab77a30c20a8b0ae
parente1ae21b09d7366145524c8fcd08c074c8c8ac124 (diff)
downloadcouchdb-07bacf050eacf9c48e03df5044e75d155a9780f3.tar.gz
fix eunit tests for partitions PR
-rw-r--r--src/chttpd/src/chttpd_view.erl4
-rw-r--r--src/chttpd/test/chttpd_db_bulk_get_test.erl33
-rw-r--r--src/couch/src/couch_db.erl19
-rw-r--r--src/fabric/src/fabric_view.erl4
-rw-r--r--src/fabric/src/fabric_view_all_docs.erl2
-rw-r--r--src/mango/src/mango_idx.erl1
6 files changed, 45 insertions, 18 deletions
diff --git a/src/chttpd/src/chttpd_view.erl b/src/chttpd/src/chttpd_view.erl
index e56be0c7b..7c1dc81bb 100644
--- a/src/chttpd/src/chttpd_view.erl
+++ b/src/chttpd/src/chttpd_view.erl
@@ -20,9 +20,11 @@ multi_query_view(Req, Db, DDoc, ViewName, Queries) ->
Args0 = couch_mrview_http:parse_params(Req, undefined),
{ok, #mrst{views=Views}} = couch_mrview_util:ddoc_to_mrst(Db, DDoc),
Args1 = couch_mrview_util:set_view_type(Args0, ViewName, Views),
+ % We don't support multi query in partitions
+ Args2 = couch_mrview_util:set_extra(Args1, partitioned, false),
ArgQueries = lists:map(fun({Query}) ->
QueryArg = couch_mrview_http:parse_params(Query, undefined,
- Args1, [decoded]),
+ Args2, [decoded]),
QueryArg1 = couch_mrview_util:set_view_type(QueryArg, ViewName, Views),
couch_mrview_util:validate_args(QueryArg1)
end, Queries),
diff --git a/src/chttpd/test/chttpd_db_bulk_get_test.erl b/src/chttpd/test/chttpd_db_bulk_get_test.erl
index f8921311b..b983487d9 100644
--- a/src/chttpd/test/chttpd_db_bulk_get_test.erl
+++ b/src/chttpd/test/chttpd_db_bulk_get_test.erl
@@ -14,6 +14,7 @@
-include_lib("couch/include/couch_eunit.hrl").
-include_lib("couch/include/couch_db.hrl").
+-include_lib("couch/src/couch_db_int.hrl").
-define(TIMEOUT, 3000).
@@ -26,6 +27,7 @@ setup() ->
mock(couch_stats),
mock(fabric),
mock(mochireq),
+ mock(mem3),
Pid = spawn_accumulator(),
Pid.
@@ -38,7 +40,8 @@ teardown(Pid) ->
meck:unload(couch_httpd),
meck:unload(couch_stats),
meck:unload(fabric),
- meck:unload(mochireq).
+ meck:unload(mochireq),
+ meck:unload(mem3).
bulk_get_test_() ->
@@ -95,7 +98,8 @@ should_get_doc_with_all_revs(Pid) ->
DocRevB = #doc{id = DocId, body = {[{<<"_rev">>, <<"1-CDE">>}]}},
mock_open_revs(all, {ok, [{ok, DocRevA}, {ok, DocRevB}]}),
- chttpd_db:db_req(Req, nil),
+ Db = fake_db(),
+ chttpd_db:db_req(Req, Db),
[{Result}] = get_results_from_response(Pid),
?assertEqual(DocId, couch_util:get_value(<<"id">>, Result)),
@@ -115,7 +119,8 @@ should_validate_doc_with_bad_id(Pid) ->
DocId = <<"_docudoc">>,
Req = fake_request(DocId),
- chttpd_db:db_req(Req, nil),
+ Db = fake_db(),
+ chttpd_db:db_req(Req, Db),
[{Result}] = get_results_from_response(Pid),
?assertEqual(DocId, couch_util:get_value(<<"id">>, Result)),
@@ -138,7 +143,8 @@ should_validate_doc_with_bad_rev(Pid) ->
Rev = <<"revorev">>,
Req = fake_request(DocId, Rev),
- chttpd_db:db_req(Req, nil),
+ Db = fake_db(),
+ chttpd_db:db_req(Req, Db),
[{Result}] = get_results_from_response(Pid),
?assertEqual(DocId, couch_util:get_value(<<"id">>, Result)),
@@ -162,7 +168,8 @@ should_validate_missing_doc(Pid) ->
Req = fake_request(DocId, Rev),
mock_open_revs([{1,<<"revorev">>}], {ok, []}),
- chttpd_db:db_req(Req, nil),
+ Db = fake_db(),
+ chttpd_db:db_req(Req, Db),
[{Result}] = get_results_from_response(Pid),
?assertEqual(DocId, couch_util:get_value(<<"id">>, Result)),
@@ -186,7 +193,8 @@ should_validate_bad_atts_since(Pid) ->
Req = fake_request(DocId, Rev, <<"badattsince">>),
mock_open_revs([{1,<<"revorev">>}], {ok, []}),
- chttpd_db:db_req(Req, nil),
+ Db = fake_db(),
+ chttpd_db:db_req(Req, Db),
[{Result}] = get_results_from_response(Pid),
?assertEqual(DocId, couch_util:get_value(<<"id">>, Result)),
@@ -210,10 +218,11 @@ should_include_attachments_when_atts_since_specified(_) ->
Req = fake_request(DocId, Rev, [<<"1-abc">>]),
mock_open_revs([{1,<<"revorev">>}], {ok, []}),
- chttpd_db:db_req(Req, nil),
+ Db = fake_db(),
+ chttpd_db:db_req(Req, Db),
?_assert(meck:called(fabric, open_revs,
- [nil, DocId, [{1, <<"revorev">>}],
+ [Db, DocId, [{1, <<"revorev">>}],
[{atts_since, [{1, <<"abc">>}]}, attachments]])).
%% helpers
@@ -233,6 +242,10 @@ fake_request(DocId, Rev, AttsSince) ->
{<<"atts_since">>, AttsSince}]}]}]}).
+fake_db() ->
+ #db{name = <<"dbName">>}.
+
+
mock_open_revs(RevsReq0, RevsResp) ->
ok = meck:expect(fabric, open_revs,
fun(_, _, RevsReq1, _) ->
@@ -276,6 +289,10 @@ mock(fabric) ->
mock(config) ->
ok = meck:new(config, [passthrough]),
ok = meck:expect(config, get, fun(_, _, Default) -> Default end),
+ ok;
+mock(mem3) ->
+ ok = meck:new(mem3, [passthrough]),
+ ok = meck:expect(mem3, is_partitioned, 1, false),
ok.
diff --git a/src/couch/src/couch_db.erl b/src/couch/src/couch_db.erl
index 5dfe32485..5a3e47dfc 100644
--- a/src/couch/src/couch_db.erl
+++ b/src/couch/src/couch_db.erl
@@ -1139,7 +1139,11 @@ doc_tag(#doc{meta=Meta}) ->
update_docs(Db, Docs0, Options, replicated_changes) ->
increment_stat(Db, [couchdb, database_writes]),
Docs = tag_docs(Docs0),
- DocBuckets = before_docs_update(Db, group_alike_docs(Docs)),
+
+ % Separate _local docs from normal docs
+ {NonRepDocs, Docs2} = lists:partition(fun is_local/1, Docs),
+
+ DocBuckets = before_docs_update(Db, group_alike_docs(Docs2)),
case (Db#db.validate_doc_funs /= []) orelse
lists:any(
@@ -1160,7 +1164,7 @@ update_docs(Db, Docs0, Options, replicated_changes) ->
end,
DocBuckets4 = [[doc_flush_atts(Db, check_dup_atts(Doc))
|| Doc <- Bucket] || Bucket <- DocBuckets3],
- {ok, []} = write_and_commit(Db, DocBuckets4, [], [merge_conflicts | Options]),
+ {ok, _} = write_and_commit(Db, DocBuckets4, NonRepDocs, [merge_conflicts | Options]),
{ok, DocErrors};
update_docs(Db, Docs0, Options, interactive_edit) ->
@@ -1169,11 +1173,7 @@ update_docs(Db, Docs0, Options, interactive_edit) ->
Docs = tag_docs(Docs0),
% Separate _local docs from normal docs
- IsLocal = fun
- (#doc{id= <<?LOCAL_DOC_PREFIX, _/binary>>}) -> true;
- (_) -> false
- end,
- {NonRepDocs, Docs2} = lists:partition(IsLocal, Docs),
+ {NonRepDocs, Docs2} = lists:partition(fun is_local/1, Docs),
DocBuckets = before_docs_update(Db, group_alike_docs(Docs2)),
@@ -1227,6 +1227,11 @@ update_docs(Db, Docs0, Options, interactive_edit) ->
end, Docs)}
end.
+is_local(#doc{id= <<?LOCAL_DOC_PREFIX, _/binary>>}) ->
+ true;
+is_local(_) ->
+ false.
+
% Returns the first available document on disk. Input list is a full rev path
% for the doc.
make_first_doc_on_disk(_Db, _Id, _Pos, []) ->
diff --git a/src/fabric/src/fabric_view.erl b/src/fabric/src/fabric_view.erl
index de374cdec..85ef0f173 100644
--- a/src/fabric/src/fabric_view.erl
+++ b/src/fabric/src/fabric_view.erl
@@ -338,7 +338,9 @@ get_shards(DbName, #mrargs{} = Args) ->
{false, true, undefined} ->
mem3:shards(DbName);
{false, true, Partition} ->
- mem3:shards(DbName, Partition)
+ mem3:shards(DbName, Partition);
+ {false, undefined, _} ->
+ mem3:shards(DbName)
end.
% create a fake docid within the specified partition.
diff --git a/src/fabric/src/fabric_view_all_docs.erl b/src/fabric/src/fabric_view_all_docs.erl
index e8868c505..9a3755241 100644
--- a/src/fabric/src/fabric_view_all_docs.erl
+++ b/src/fabric/src/fabric_view_all_docs.erl
@@ -395,7 +395,7 @@ cancel_read_pids(Pids) ->
Args = #mrargs{
start_key = null,
end_key = null,
- extra = [{partitioned, true}]
+ extra = [{partitioned, false}]
},
meck:expect(mem3, shards, fun(<<"db">>) -> [] end),
shards(DbName, Args),
diff --git a/src/mango/src/mango_idx.erl b/src/mango/src/mango_idx.erl
index 261e8f0b1..978a1b916 100644
--- a/src/mango/src/mango_idx.erl
+++ b/src/mango/src/mango_idx.erl
@@ -422,6 +422,7 @@ index(SelectorName, Selector) ->
<<"Selected">>,<<"json">>,
{[{<<"fields">>,{[{<<"location">>,<<"asc">>}]}},
{SelectorName,{Selector}}]},
+ [],
[{<<"def">>,{[{<<"fields">>,[<<"location">>]}]}}]
}.