This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3326-clustered-purge-davisp-refactor-2
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 2e15fc84ed888ab31165c4a144359bc191ea323b
Author: Paul J. Davis <[email protected]>
AuthorDate: Thu May 3 16:05:42 2018 -0500

    [SQUERGE] Initial internal replication tests
---
 src/couch/src/test_engine_purge_replication.erl | 139 ++++++++++++++++++++++++
 src/couch/src/test_engine_util.erl              |  63 ++++++++---
 2 files changed, 185 insertions(+), 17 deletions(-)

diff --git a/src/couch/src/test_engine_purge_replication.erl 
b/src/couch/src/test_engine_purge_replication.erl
new file mode 100644
index 0000000..03cdcb9
--- /dev/null
+++ b/src/couch/src/test_engine_purge_replication.erl
@@ -0,0 +1,139 @@
+% 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(test_engine_purge_replication).
+-compile(export_all).
+
+
+-include_lib("eunit/include/eunit.hrl").
+-include_lib("couch/include/couch_db.hrl").
+-include_lib("mem3/include/mem3.hrl").
+
+
+cet_purge_repl_disabled() ->
+    config:set("mem3", "replicate_purges", "false", false),
+    try
+        do_repl_disabled()
+    after
+        config:set("mem3", "replicate_purges", "true", false)
+    end.
+
+
+do_repl_disabled() ->
+    {ok, SrcDb, TgtDb} = create_db_pair(),
+    repl(SrcDb, TgtDb),
+
+    Actions1 = [
+        {create, {<<"foo1">>, {[{<<"vsn">>, 1}]}}},
+        {create, {<<"foo2">>, {[{<<"vsn">>, 2}]}}}
+    ],
+    ok = test_engine_util:apply_actions(SrcDb, Actions1),
+    repl(SrcDb, TgtDb),
+
+    Actions2 = [
+        {purge, {<<"foo1">>, prev_rev(SrcDb, <<"foo1">>)}}
+    ],
+    ok = test_engine_util:apply_actions(SrcDb, Actions2),
+
+    Actions3 = [
+        {purge, {<<"foo2">>, prev_rev(TgtDb, <<"foo2">>)}}
+    ],
+    ok = test_engine_util:apply_actions(TgtDb, Actions3),
+
+
+    SrcShard = make_shard(SrcDb),
+    TgtShard = make_shard(TgtDb),
+    ?assertEqual({ok, 0}, mem3_rep:go(SrcShard, TgtShard)),
+
+    ?assertMatch([#full_doc_info{}], open_docs(SrcDb, [<<"foo2">>])),
+    ?assertMatch([#full_doc_info{}], open_docs(TgtDb, [<<"foo1">>])).
+
+
+cet_purge_repl_simple_pull() ->
+    {ok, SrcDb, TgtDb} = create_db_pair(),
+    repl(SrcDb, TgtDb),
+
+    Actions1 = [
+        {create, {<<"foo">>, {[{<<"vsn">>, 1}]}}}
+    ],
+    ok = test_engine_util:apply_actions(SrcDb, Actions1),
+    repl(SrcDb, TgtDb),
+
+    Actions2 = [
+        {purge, {<<"foo">>, prev_rev(TgtDb, <<"foo">>)}}
+    ],
+    ok = test_engine_util:apply_actions(TgtDb, Actions2),
+    repl(SrcDb, TgtDb).
+
+
+cet_purge_repl_simple_push() ->
+    {ok, SrcDb, TgtDb} = create_db_pair(),
+    repl(SrcDb, TgtDb),
+
+    Actions1 = [
+        {create, {<<"foo">>, {[{<<"vsn">>, 1}]}}}
+    ],
+    ok = test_engine_util:apply_actions(SrcDb, Actions1),
+    repl(SrcDb, TgtDb),
+
+    Actions2 = [
+        {purge, {<<"foo">>, prev_rev(SrcDb, <<"foo">>)}}
+    ],
+    ok = test_engine_util:apply_actions(SrcDb, Actions2),
+    repl(SrcDb, TgtDb).
+
+
+create_db_pair() ->
+    {ok, SrcDb} = test_engine_util:create_db(),
+    {ok, TgtDb} = test_engine_util:create_db(),
+    try
+        {ok, couch_db:name(SrcDb), couch_db:name(TgtDb)}
+    after
+        couch_db:close(SrcDb),
+        couch_db:close(TgtDb)
+    end.
+
+
+repl(SrcDb, TgtDb) ->
+    SrcShard = make_shard(SrcDb),
+    TgtShard = make_shard(TgtDb),
+
+    ?assertEqual({ok, 0}, mem3_rep:go(SrcShard, TgtShard)),
+
+    SrcTerm = test_engine_util:db_as_term(SrcDb, replication),
+    TgtTerm = test_engine_util:db_as_term(TgtDb, replication),
+    Diff = test_engine_util:term_diff(SrcTerm, TgtTerm),
+    ?assertEqual(nodiff, Diff).
+
+
+make_shard(DbName) ->
+    #shard{
+        name = DbName,
+        node = node(),
+        dbname = DbName,
+        range = [0, 16#FFFFFFFF]
+    }.
+
+
+open_docs(DbName, DocIds) ->
+    {ok, Db} = couch_db:open_int(DbName, [?ADMIN_CTX]),
+    try
+        couch_db_engine:open_docs(Db, DocIds)
+    after
+        couch_db:close(Db)
+    end.
+
+
+prev_rev(DbName, DocId) ->
+    [FDI] = open_docs(DbName, [DocId]),
+    PrevRev = test_engine_util:prev_rev(FDI),
+    PrevRev#rev_info.rev.
diff --git a/src/couch/src/test_engine_util.erl 
b/src/couch/src/test_engine_util.erl
index b9c41c8..8858b48 100644
--- a/src/couch/src/test_engine_util.erl
+++ b/src/couch/src/test_engine_util.erl
@@ -18,16 +18,17 @@
 
 
 -define(TEST_MODULES, [
-    test_engine_open_close_delete,
-    test_engine_get_set_props,
-    test_engine_read_write_docs,
-    test_engine_attachments,
-    test_engine_fold_docs,
-    test_engine_fold_changes,
-    test_engine_fold_purge_infos,
-    test_engine_purge_docs,
-    test_engine_compaction,
-    test_engine_ref_counting
+    %% test_engine_open_close_delete,
+    %% test_engine_get_set_props,
+    %% test_engine_read_write_docs,
+    %% test_engine_attachments,
+    %% test_engine_fold_docs,
+    %% test_engine_fold_changes,
+    %% test_engine_fold_purge_infos,
+    %% test_engine_purge_docs,
+    test_engine_purge_replication
+    %% test_engine_compaction,
+    %% test_engine_ref_counting
 ]).
 
 
@@ -48,10 +49,11 @@ create_tests(EngineApp, EngineModule, Extension) ->
         {atom_to_list(TestMod), gather(TestMod)}
     end, ?TEST_MODULES),
     Setup = fun() ->
-        Ctx = test_util:start_couch(),
+        Ctx = test_util:start_couch([mem3, fabric]),
         EngineModStr = atom_to_list(EngineModule),
         config:set("couchdb_engines", Extension, EngineModStr, false),
         config:set("log", "include_sasl", "false", false),
+        config:set("mem3", "replicate_purges", "true", false),
         Ctx
     end,
     {
@@ -135,6 +137,12 @@ shutdown_db(Db) ->
     end).
 
 
+apply_actions(DbName, Actions) when is_binary(DbName) ->
+    {ok, Db0} = couch_db:open_int(DbName, [?ADMIN_CTX]),
+    {ok, Db1} = apply_actions(Db0, Actions),
+    couch_db:close(Db1),
+    ok;
+
 apply_actions(Db, []) ->
     {ok, Db};
 
@@ -319,17 +327,28 @@ prev_rev(#full_doc_info{} = FDI) ->
 
 
 db_as_term(Db) ->
+    db_as_term(Db, compact).
+
+db_as_term(DbName, Type) when is_binary(DbName) ->
+    {ok, Db} = couch_db:open_int(DbName, [?ADMIN_CTX]),
+    try
+        db_as_term(Db, Type)
+    after
+        couch_db:close(Db)
+    end;
+
+db_as_term(Db, Type) ->
     [
-        {props, db_props_as_term(Db)},
+        {props, db_props_as_term(Db, Type)},
         {docs, db_docs_as_term(Db)},
-        {local_docs, db_local_docs_as_term(Db)},
+        {local_docs, db_local_docs_as_term(Db, Type)},
         {changes, db_changes_as_term(Db)},
         {purged_docs, db_purged_docs_as_term(Db)}
     ].
 
 
-db_props_as_term(Db) ->
-    Props = [
+db_props_as_term(Db, Type) ->
+    Props0 = [
         get_doc_count,
         get_del_doc_count,
         get_disk_version,
@@ -341,6 +360,9 @@ db_props_as_term(Db) ->
         get_uuid,
         get_epochs
     ],
+    Props = if Type /= replication -> Props0; true ->
+        Props0 -- [get_uuid]
+    end,
     lists:map(fun(Fun) ->
         {Fun, couch_db_engine:Fun(Db)}
     end, Props).
@@ -354,8 +376,15 @@ db_docs_as_term(Db) ->
     end, FDIs)).
 
 
-db_local_docs_as_term(Db) ->
-    FoldFun = fun(Doc, Acc) -> {ok, [Doc | Acc]} end,
+db_local_docs_as_term(Db, Type) ->
+    FoldFun = fun(Doc, Acc) ->
+        case Doc#doc.id of
+            <<"_local/purge-mem3-", _/binary>> when Type == replication ->
+                {ok, Acc};
+            _ ->
+                {ok, [Doc | Acc]}
+        end
+    end,
     {ok, LDocs} = couch_db:fold_local_docs(Db, FoldFun, [], []),
     lists:reverse(LDocs).
 

-- 
To stop receiving notification emails like this one, please contact
[email protected].

Reply via email to