couchdb-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dav...@apache.org
Subject [couchdb] branch COUCHDB-3287-pluggable-storage-engines updated: Test if deleted docs are included/excluded when folding
Date Mon, 05 Jun 2017 15:57:40 GMT
This is an automated email from the ASF dual-hosted git repository.

davisp pushed a commit to branch COUCHDB-3287-pluggable-storage-engines
in repository https://gitbox.apache.org/repos/asf/couchdb.git


The following commit(s) were added to refs/heads/COUCHDB-3287-pluggable-storage-engines by
this push:
     new 95cfd84  Test if deleted docs are included/excluded when folding
95cfd84 is described below

commit 95cfd84d761b9ef3d9c793e9975ecb3599d25ce1
Author: Garren Smith <garren.smith@gmail.com>
AuthorDate: Mon Jun 5 11:41:12 2017 +0200

    Test if deleted docs are included/excluded when folding
    
    Adds tests to fold_changes and fold_docs to check if deleted are
    included or excluded.
---
 src/couch/src/test_engine_fold_changes.erl | 14 ++++++++++
 src/couch/src/test_engine_fold_docs.erl    | 44 ++++++++++++++++++++++++++++++
 2 files changed, 58 insertions(+)

diff --git a/src/couch/src/test_engine_fold_changes.erl b/src/couch/src/test_engine_fold_changes.erl
index 6e97fda..c711ef4 100644
--- a/src/couch/src/test_engine_fold_changes.erl
+++ b/src/couch/src/test_engine_fold_changes.erl
@@ -120,6 +120,20 @@ cet_update_second_of_two() ->
     ?assertEqual([{<<"a">>, 1}, {<<"b">>, 3}], lists:reverse(Changes)).
 
 
+cet_delete_first() ->
+    {ok, Engine, St1} = test_engine_util:init_engine(),
+    Actions = [
+        {create, {<<"a">>, []}},
+        {create, {<<"b">>, []}},
+        {delete, {<<"a">>, []}}
+    ],
+    {ok, St2} = test_engine_util:apply_actions(Engine, St1, Actions),
+
+    ?assertEqual(2, Engine:count_changes_since(St2, 0)),
+    {ok, Changes} = Engine:fold_changes(St2, 0, fun fold_fun/2, [], []),
+    ?assertEqual([{<<"b">>, 2}, {<<"a">>, 3}], lists:reverse(Changes)).
+
+
 cet_check_mutation_ordering() ->
     Actions = shuffle(lists:map(fun(Seq) ->
         {create, {docid(Seq), []}}
diff --git a/src/couch/src/test_engine_fold_docs.erl b/src/couch/src/test_engine_fold_docs.erl
index 458878d..c25011f 100644
--- a/src/couch/src/test_engine_fold_docs.erl
+++ b/src/couch/src/test_engine_fold_docs.erl
@@ -29,6 +29,18 @@ cet_fold_all_local() ->
     fold_all(fold_local_docs, fun local_docid/1).
 
 
+cet_fold_exclude_deleted_docs() ->
+    fold_exclude_deleted_docs(fold_docs, fun docid/1).
+
+
+cet_fold_exclude_deleted_docs_local() ->
+    fold_exclude_deleted_docs(fold_local_docs, fun local_docid/1).
+
+
+cet_fold_include_deleted_docs() ->
+    fold_include_deleted_docs(fold_docs, fun docid/1).
+
+
 cet_fold_start_key() ->
     fold_start_key(fold_docs, fun docid/1).
 
@@ -93,6 +105,30 @@ fold_all(FoldFun, DocIdFun) ->
     ?assertEqual(DocIds, DocIdAccRev).
 
 
+fold_exclude_deleted_docs(FoldFun, DocIdFun) ->
+    DocIds = [DocIdFun(I) || I <- lists:seq(1, ?NUM_DOCS), I rem 2 =:= 0],
+    DeletedDocIds = [DocIdFun(I) || I <- lists:seq(1, ?NUM_DOCS), I rem 2 > 0],
+
+    {ok, Engine, St0} = init_st(DocIdFun),
+    {ok, Engine, St} = delete_docs(DeletedDocIds, Engine, St0),
+
+    {ok, DocIdAccFwd} = Engine:FoldFun(St, fun fold_fun/2, [], []),
+    ?assertEqual(length(DocIds), length(DocIdAccFwd)),
+    ?assertEqual(DocIds, lists:reverse(DocIdAccFwd)).
+
+
+fold_include_deleted_docs(FoldFun, DocIdFun) ->
+    DocIds = [DocIdFun(I) || I <- lists:seq(1, ?NUM_DOCS)],
+    DeletedDocIds = [DocIdFun(I) || I <- lists:seq(1, ?NUM_DOCS), I rem 2 > 0],
+
+    {ok, Engine, St0} = init_st(DocIdFun),
+    {ok, Engine, St} = delete_docs(DeletedDocIds, Engine, St0),
+
+    {ok, DocIdAccFwd} = Engine:FoldFun(St, fun fold_fun/2, [], [include_deleted]),
+    ?assertEqual(length(DocIds), length(DocIdAccFwd)),
+    ?assertEqual(DocIds, lists:reverse(DocIdAccFwd)).
+    
+
 fold_start_key(FoldFun, DocIdFun) ->
     {ok, Engine, St} = init_st(DocIdFun),
 
@@ -359,6 +395,14 @@ init_st(DocIdFun) ->
     {ok, Engine, St2}.
 
 
+delete_docs(DocIds, Engine, St1) ->
+    Actions = lists:map(fun(Id) ->
+        {delete, {Id, []}}
+    end, DocIds),
+    {ok, St2} = test_engine_util:apply_actions(Engine, St1, Actions),
+    {ok, Engine, St2}.
+
+
 fold_fun(Doc, Acc) ->
     Id = case Doc of
         #doc{id = Id0} -> Id0;

-- 
To stop receiving notification emails like this one, please contact
['"commits@couchdb.apache.org" <commits@couchdb.apache.org>'].

Mime
View raw message