You are viewing a plain text version of this content. The canonical link for it is here.
Posted to notifications@couchdb.apache.org by GitBox <gi...@apache.org> on 2017/11/28 02:19:04 UTC

[GitHub] jiangphcn commented on a change in pull request #1017: Allow replicator documents to include params for db creation

jiangphcn commented on a change in pull request #1017: Allow replicator documents to include params for db creation
URL: https://github.com/apache/couchdb/pull/1017#discussion_r153379321
 
 

 ##########
 File path: src/couch_replicator/test/couch_replicator_create_target_with_options_tests.erl
 ##########
 @@ -0,0 +1,168 @@
+% 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_replicator_create_target_with_options_tests).
+
+-include_lib("couch/include/couch_eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+-include_lib("couch_replicator/src/couch_replicator.hrl").
+
+
+setup(_) ->
+    Ctx1 = test_util:start_couch([fabric, mem3, couch_replicator]),
+    Ctx2 = chttpd_test_util:start_couch(),
+    Source = ?tempdb(),
+    Target = ?tempdb(),
+    {Ctx1, Ctx2, {Source, Target}}.
+
+
+teardown(_, {Ctx1, Ctx2, {_Source, _Target}}) ->
+    ok = test_util:stop_couch(Ctx1),
+    ok = chttpd_test_util:stop_couch(Ctx2).
+
+
+create_target_with_options_replication_test_() ->
+    Ps = [{local, remote}, {remote, remote}],
+    {
+        "Create target with range partitions tests",
+        {
+            foreachx,
+            fun setup/1, fun teardown/2,
+            [{P, fun should_create_target_with_q_1/2} || P <- Ps] ++
+            [{P, fun should_create_target_with_q_4/2} || P <- Ps] ++
+            [{P, fun should_create_target_with_q_8/2} || P <- Ps] ++
+            [{P, fun should_create_target_with_q_default/2} || P <- Ps] ++
+            [{P, fun should_not_create_target_with_q_any/2} || P <- Ps]
+        }
+    }.
+
+
+should_create_target_with_q_1({From, To}, {_Ctx1, _Ctx2, {Source, Target}}) ->
+    RepObject = {[
+        {<<"source">>, db_url(From, Source)},
+        {<<"target">>, db_url(To, Target)},
+        {<<"create_target">>, true},
+        {<<"create_target_params">>, {[{<<"q">>, <<"1">>}]}}
+    ]},
+    create_db(From, Source),
+    create_doc(From, Source),
+    {ok, _} = couch_replicator:replicate(RepObject, ?ADMIN_USER),
+
+    {ok, TargetInfo} = fabric:get_db_info(Target),
+    {ClusterInfo} = couch_util:get_value(cluster, TargetInfo),
+    delete_db(From, Source),
+    delete_db(To, Target),
+    ?_assertEqual(1, couch_util:get_value(q, ClusterInfo)).
+
+
+should_create_target_with_q_4({From, To}, {_Ctx1, _Ctx2, {Source, Target}}) ->
+    RepObject = {[
+        {<<"source">>, db_url(From, Source)},
+        {<<"target">>, db_url(To, Target)},
+        {<<"create_target">>, true},
+        {<<"create_target_params">>, {[{<<"q">>, <<"4">>}]}}
+    ]},
+    create_db(From, Source),
+    create_doc(From, Source),
+    {ok, _} = couch_replicator:replicate(RepObject, ?ADMIN_USER),
+
+    {ok, TargetInfo} = fabric:get_db_info(Target),
+    {ClusterInfo} = couch_util:get_value(cluster, TargetInfo),
+    delete_db(From, Source),
+    delete_db(To, Target),
+    ?_assertEqual(4, couch_util:get_value(q, ClusterInfo)).
+
+
+should_create_target_with_q_8({From, To}, {_Ctx1, _Ctx2, {Source, Target}}) ->
+    RepObject = {[
+        {<<"source">>, db_url(From, Source)},
+        {<<"target">>, db_url(To, Target)},
+        {<<"create_target">>, true},
+        {<<"create_target_params">>, {[{<<"q">>, <<"8">>}]}}
+    ]},
+    create_db(From, Source),
+    create_doc(From, Source),
+    {ok, _} = couch_replicator:replicate(RepObject, ?ADMIN_USER),
+
+    {ok, TargetInfo} = fabric:get_db_info(Target),
+    {ClusterInfo} = couch_util:get_value(cluster, TargetInfo),
+    delete_db(From, Source),
+    delete_db(To, Target),
+    ?_assertEqual(8, couch_util:get_value(q, ClusterInfo)).
+
+
+should_create_target_with_q_default(
+    {From, To}, {_Ctx1, _Ctx2, {Source, Target}}) ->
+    RepObject = {[
+        {<<"source">>, db_url(From, Source)},
+        {<<"target">>, db_url(To, Target)},
+        {<<"create_target">>, true}
+    ]},
+    create_db(From, Source),
+    create_doc(From, Source),
+    {ok, _} = couch_replicator:replicate(RepObject, ?ADMIN_USER),
+
+    {ok, TargetInfo} = fabric:get_db_info(Target),
+    {ClusterInfo} = couch_util:get_value(cluster, TargetInfo),
+    Q = config:get("cluster", "q", "8"),
+    delete_db(From, Source),
+    delete_db(To, Target),
+    ?_assertEqual(list_to_integer(Q), couch_util:get_value(q, ClusterInfo)).
+
+
+should_not_create_target_with_q_any(
 
 Review comment:
   This test case is used to prevent from regression. If `create_target` is not specified or set to false, there should not be target database to be created, even if there is any value set for `create_target_params`.

----------------------------------------------------------------
This is an automated message from the Apache Git Service.
To respond to the message, please log on GitHub and use the
URL above to go to the specific comment.
 
For queries about this service, please contact Infrastructure at:
users@infra.apache.org


With regards,
Apache Git Services