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

davisp pushed a commit to branch prototype/fdb-layer-get-dbs-info
in repository https://gitbox.apache.org/repos/asf/couchdb.git

commit 959ece78daf885d6c32337c2f7eb49c8a98e8b93
Author: Paul J. Davis <paul.joseph.da...@gmail.com>
AuthorDate: Wed Feb 12 15:01:19 2020 -0600

    fixup size tests
---
 src/fabric/src/fabric2_util.erl            |  2 +-
 src/fabric/test/fabric2_doc_size_tests.erl | 78 +++++++++++++++++++++++++++---
 2 files changed, 73 insertions(+), 7 deletions(-)

diff --git a/src/fabric/src/fabric2_util.erl b/src/fabric/src/fabric2_util.erl
index 766441c..f51c6e8 100644
--- a/src/fabric/src/fabric2_util.erl
+++ b/src/fabric/src/fabric2_util.erl
@@ -105,7 +105,7 @@ rev_size(#doc{} = Doc) ->
     ]).
 
 
-ldoc_size(#doc{id = <<"_local/">>} = Doc) ->
+ldoc_size(#doc{id = <<"_local/", _/binary>>} = Doc) ->
     #doc{
         id = Id,
         revs = {0, [Rev]},
diff --git a/src/fabric/test/fabric2_doc_size_tests.erl 
b/src/fabric/test/fabric2_doc_size_tests.erl
index 37f1740..96ecf74 100644
--- a/src/fabric/test/fabric2_doc_size_tests.erl
+++ b/src/fabric/test/fabric2_doc_size_tests.erl
@@ -106,7 +106,6 @@
     >>}
 ]).
 
-
 -define(ATT_HEADERS, [
     {0, undefined},
     {2, {[]}},
@@ -114,6 +113,24 @@
     {32, {[{<<"a">>, <<"header">>}, {<<"b">>, <<"such header">>}]}}
 ]).
 
+-define(LDOC_IDS, [
+    {7, <<"_local/">>},
+    {8, <<"_local/a">>},
+    {10, <<"_local/foo">>},
+    {13, <<"_local/foobar">>},
+    {39, <<"_local/af196ae095631b020eedf8f69303e336">>}
+]).
+
+-define(LDOC_REVS, [
+    {1, <<"0">>},
+    {2, <<"10">>},
+    {3, <<"100">>},
+    {4, <<"1000">>},
+    {5, <<"10000">>},
+    {6, <<"100000">>},
+    {7, <<"1000000">>}
+]).
+
 
 empty_doc_test() ->
     ?assertEqual(4, fabric2_util:rev_size(#doc{})).
@@ -184,7 +201,27 @@ att_headers_test() ->
     end, ?ATT_HEADERS).
 
 
-combinatorics_test() ->
+local_doc_ids_test() ->
+    lists:foreach(fun({Size, LDocId}) ->
+        ?assertEqual(3 + Size, fabric2_util:ldoc_size(mk_ldoc(LDocId, 0)))
+    end, ?LDOC_IDS).
+
+
+local_doc_revs_test() ->
+    lists:foreach(fun({Size, Rev}) ->
+        Doc = mk_ldoc(<<"_local/foo">>, Rev),
+        ?assertEqual(12 + Size, fabric2_util:ldoc_size(Doc))
+    end, ?LDOC_REVS).
+
+
+local_doc_bodies_test() ->
+    lists:foreach(fun({Size, Body}) ->
+        Doc = mk_ldoc(<<"_local/foo">>, 0, Body),
+        ?assertEqual(11 + Size, fabric2_util:ldoc_size(Doc))
+    end, ?BODIES).
+
+
+doc_combinatorics_test() ->
     Elements = [
         {?DOC_IDS, fun(Doc, DocId) -> Doc#doc{id = DocId} end},
         {?REV_STARTS, fun(Doc, RevStart) ->
@@ -198,18 +235,35 @@ combinatorics_test() ->
         {?DELETED, fun(Doc, Deleted) -> Doc#doc{deleted = Deleted} end},
         {?BODIES, fun(Doc, Body) -> Doc#doc{body = Body} end}
     ],
-    combine(Elements, 0, #doc{}).
+    doc_combine(Elements, 0, #doc{}).
 
 
-combine([], TotalSize, Doc) ->
+doc_combine([], TotalSize, Doc) ->
     ?assertEqual(TotalSize, fabric2_util:rev_size(Doc));
 
-combine([{Elems, UpdateFun} | Rest], TotalSize, Doc) ->
+doc_combine([{Elems, UpdateFun} | Rest], TotalSize, Doc) ->
     lists:foreach(fun({Size, Elem}) ->
-        combine(Rest, TotalSize + Size, UpdateFun(Doc, Elem))
+        doc_combine(Rest, TotalSize + Size, UpdateFun(Doc, Elem))
     end, Elems).
 
 
+local_doc_combinatorics_test() ->
+    Elements = [
+        {?LDOC_IDS, fun(Doc, DocId) -> Doc#doc{id = DocId} end},
+        {?LDOC_REVS, fun(Doc, Rev) -> Doc#doc{revs = {0, [Rev]}} end},
+        {?BODIES, fun(Doc, Body) -> Doc#doc{body = Body} end}
+    ],
+    local_doc_combine(Elements, 0, #doc{}).
+
+
+local_doc_combine([], TotalSize, Doc) ->
+    ?assertEqual(TotalSize, fabric2_util:ldoc_size(Doc));
+
+local_doc_combine([{Elems, UpdateFun} | Rest], TotalSize, Doc) ->
+    lists:foreach(fun({Size, Elem}) ->
+        local_doc_combine(Rest, TotalSize + Size, UpdateFun(Doc, Elem))
+    end, Elems).
+
 random_docs_test() ->
     lists:foreach(fun(_) ->
         {DocIdSize, DocId} = choose(?DOC_IDS),
@@ -269,6 +323,18 @@ mk_att(Name, Type, Data, AddMd5, Headers) ->
     ]).
 
 
+mk_ldoc(DocId, Rev) ->
+    mk_ldoc(DocId, Rev, {[]}).
+
+
+mk_ldoc(DocId, Rev, Body) ->
+    #doc{
+        id = DocId,
+        revs = {0, [Rev]},
+        body = Body
+    }.
+
+
 choose(Options) ->
     Pos = rand:uniform(length(Options)),
     lists:nth(Pos, Options).

Reply via email to