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 2018/04/13 14:09:47 UTC

[GitHub] eiri closed pull request #1273: Adopt fake_db to PSE changes

eiri closed pull request #1273: Adopt fake_db to PSE changes
URL: https://github.com/apache/couchdb/pull/1273
 
 
   

This is a PR merged from a forked repository.
As GitHub hides the original diff on merge, it is displayed below for
the sake of provenance:

As this is a foreign pull request (from a fork), the diff is supplied
below (as it won't show otherwise due to GitHub magic):

diff --git a/src/couch/src/test_util.erl b/src/couch/src/test_util.erl
index e0a53a6f77..738e9a3fb1 100644
--- a/src/couch/src/test_util.erl
+++ b/src/couch/src/test_util.erl
@@ -15,6 +15,7 @@
 -include_lib("couch/include/couch_eunit.hrl").
 -include("couch_db.hrl").
 -include("couch_db_int.hrl").
+-include("couch_bt_engine.hrl").
 
 -export([init_code_path/0]).
 -export([source_file/1, build_file/1]).
@@ -234,7 +235,8 @@ stop(#test_context{mocked = Mocked, started = Apps}) ->
     meck:unload(Mocked),
     stop_applications(Apps).
 
-fake_db(Fields) ->
+fake_db(Fields0) ->
+    {ok, Db, Fields} = maybe_set_engine(Fields0),
     Indexes = lists:zip(
             record_info(fields, db),
             lists:seq(2, record_info(size, db))
@@ -242,7 +244,27 @@ fake_db(Fields) ->
     lists:foldl(fun({FieldName, Value}, Acc) ->
         Idx = couch_util:get_value(FieldName, Indexes),
         setelement(Idx, Acc, Value)
-    end, #db{}, Fields).
+    end, Db, Fields).
+
+maybe_set_engine(Fields0) ->
+    case lists:member(engine, Fields0) of
+        true ->
+            {ok, #db{}, Fields0};
+        false ->
+            {ok, Header, Fields} = get_engine_header(Fields0),
+            Db = #db{engine = {couch_bt_engine, #st{header = Header}}},
+            {ok, Db, Fields}
+    end.
+
+get_engine_header(Fields) ->
+    Keys = [disk_version, update_seq, unused, id_tree_state,
+        seq_tree_state, local_tree_state, purge_seq, purged_docs,
+        security_ptr, revs_limit, uuid, epochs, compacted_seq],
+    {HeadFields, RestFields} = lists:partition(
+        fun({K, _}) -> lists:member(K, Keys) end, Fields),
+    Header0 = couch_bt_engine_header:new(),
+    Header = couch_bt_engine_header:set(Header0, HeadFields),
+    {ok, Header, RestFields}.
 
 now_us() ->
     {MegaSecs, Secs, MicroSecs} = os:timestamp(),


 

----------------------------------------------------------------
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