Add test for append and repair with partition simulator #33
1 changed files with 24 additions and 8 deletions
|
@ -114,7 +114,7 @@
|
||||||
-include_lib("eunit/include/eunit.hrl").
|
-include_lib("eunit/include/eunit.hrl").
|
||||||
-endif. % TEST.
|
-endif. % TEST.
|
||||||
|
|
||||||
-export([start_link/1]).
|
-export([start_link/1, start_link/2]).
|
||||||
%% FLU1 API
|
%% FLU1 API
|
||||||
-export([
|
-export([
|
||||||
%% File API
|
%% File API
|
||||||
|
@ -146,7 +146,8 @@
|
||||||
proxies_dict :: orddict:orddict(),
|
proxies_dict :: orddict:orddict(),
|
||||||
epoch_id,
|
epoch_id,
|
||||||
proj,
|
proj,
|
||||||
bad_proj
|
bad_proj,
|
||||||
|
opts :: proplists:proplist()
|
||||||
}).
|
}).
|
||||||
|
|
||||||
%% @doc Start a local, long-lived process that will be our steady
|
%% @doc Start a local, long-lived process that will be our steady
|
||||||
|
@ -154,7 +155,10 @@
|
||||||
%% remote Machi server.
|
%% remote Machi server.
|
||||||
|
|
||||||
start_link(P_srvr_list) ->
|
start_link(P_srvr_list) ->
|
||||||
gen_server:start_link(?MODULE, [P_srvr_list], []).
|
gen_server:start_link(?MODULE, [P_srvr_list, []], []).
|
||||||
|
|
||||||
|
start_link(P_srvr_list, Opts) ->
|
||||||
|
gen_server:start_link(?MODULE, [P_srvr_list, Opts], []).
|
||||||
|
|
||||||
%% @doc Append a chunk (binary- or iolist-style) of data to a file
|
%% @doc Append a chunk (binary- or iolist-style) of data to a file
|
||||||
%% with `Prefix'.
|
%% with `Prefix'.
|
||||||
|
@ -254,10 +258,10 @@ quit(PidSpec) ->
|
||||||
|
|
||||||
%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
%%%%%%%%%%%%%%%%%%%%%%%%%%%
|
||||||
|
|
||||||
init([P_srvr_list]) ->
|
init([P_srvr_list, Opts]) ->
|
||||||
MembersDict = orddict:from_list([{P#p_srvr.name, P} || P <- P_srvr_list]),
|
MembersDict = orddict:from_list([{P#p_srvr.name, P} || P <- P_srvr_list]),
|
||||||
ProxiesDict = ?FLU_PC:start_proxies(MembersDict),
|
ProxiesDict = ?FLU_PC:start_proxies(MembersDict),
|
||||||
{ok, #state{members_dict=MembersDict, proxies_dict=ProxiesDict}}.
|
{ok, #state{members_dict=MembersDict, proxies_dict=ProxiesDict, opts=Opts}}.
|
||||||
|
|
||||||
handle_call({req, Req}, From, S) ->
|
handle_call({req, Req}, From, S) ->
|
||||||
handle_call2(Req, From, update_proj(S));
|
handle_call2(Req, From, update_proj(S));
|
||||||
|
@ -923,10 +927,22 @@ update_proj(#state{proj=undefined}=S) ->
|
||||||
update_proj(S) ->
|
update_proj(S) ->
|
||||||
S.
|
S.
|
||||||
|
|
||||||
update_proj2(Count, #state{bad_proj=BadProj, proxies_dict=ProxiesDict}=S) ->
|
update_proj2(Count, #state{bad_proj=BadProj, proxies_dict=ProxiesDict,
|
||||||
|
opts=Opts}=S) ->
|
||||||
Timeout = 2*1000,
|
Timeout = 2*1000,
|
||||||
WTimeout = 2*Timeout,
|
WTimeout = 2*Timeout,
|
||||||
Proxies = orddict:to_list(ProxiesDict),
|
SimName = proplists:get_value(simulator_self_name, Opts, cr_client),
|
||||||
|
ExcludedFLUs =
|
||||||
|
case proplists:get_value(use_partition_simulator, Opts, false) of
|
||||||
|
true ->
|
||||||
|
Members = proplists:get_value(simulator_members, Opts, []),
|
||||||
|
{Partitions, _Islands} = machi_partition_simulator:get(Members),
|
||||||
|
[B || {A, B} <- Partitions, A =:= SimName];
|
||||||
|
false -> []
|
||||||
|
end,
|
||||||
|
Proxies = lists:foldl(fun(Name, Dict) ->
|
||||||
|
orddict:erase(Name, Dict)
|
||||||
|
end, ProxiesDict, ExcludedFLUs),
|
||||||
Work = fun({_K, Proxy}) ->
|
Work = fun({_K, Proxy}) ->
|
||||||
?FLU_PC:read_latest_projection(Proxy, private, Timeout)
|
?FLU_PC:read_latest_projection(Proxy, private, Timeout)
|
||||||
end,
|
end,
|
||||||
|
@ -950,7 +966,7 @@ update_proj2(Count, #state{bad_proj=BadProj, proxies_dict=ProxiesDict}=S) ->
|
||||||
NewProxiesDict = ?FLU_PC:start_proxies(NewMembersDict),
|
NewProxiesDict = ?FLU_PC:start_proxies(NewMembersDict),
|
||||||
S#state{bad_proj=undefined, proj=P, epoch_id=EpochID,
|
S#state{bad_proj=undefined, proj=P, epoch_id=EpochID,
|
||||||
members_dict=NewMembersDict, proxies_dict=NewProxiesDict};
|
members_dict=NewMembersDict, proxies_dict=NewProxiesDict};
|
||||||
_ ->
|
_P ->
|
||||||
sleep_a_while(Count),
|
sleep_a_while(Count),
|
||||||
update_proj2(Count + 1, S)
|
update_proj2(Count + 1, S)
|
||||||
end.
|
end.
|
||||||
|
|
Loading…
Reference in a new issue