register op name sanity: write and _read_
This commit is contained in:
parent
921d90a69b
commit
b443a15542
2 changed files with 8 additions and 8 deletions
|
@ -3,7 +3,7 @@
|
||||||
-behaviour(gen_server).
|
-behaviour(gen_server).
|
||||||
|
|
||||||
-export([start_link/1, stop/1,
|
-export([start_link/1, stop/1,
|
||||||
write/3, get/2, trim/2,
|
write/3, read/2, trim/2,
|
||||||
proj_write/3, proj_read/2, proj_get_latest_num/1, proj_read_latest/1]).
|
proj_write/3, proj_read/2, proj_get_latest_num/1, proj_read_latest/1]).
|
||||||
-ifdef(TEST).
|
-ifdef(TEST).
|
||||||
-compile(export_all).
|
-compile(export_all).
|
||||||
|
@ -41,8 +41,8 @@ start_link(Name) when is_list(Name) ->
|
||||||
stop(Pid) ->
|
stop(Pid) ->
|
||||||
gen_server:call(Pid, stop, infinity).
|
gen_server:call(Pid, stop, infinity).
|
||||||
|
|
||||||
get(Pid, ProjNum) ->
|
read(Pid, ProjNum) ->
|
||||||
gen_server:call(Pid, {reg_op, ProjNum, get}, ?LONG_TIME).
|
gen_server:call(Pid, {reg_op, ProjNum, read}, ?LONG_TIME).
|
||||||
|
|
||||||
write(Pid, ProjNum, Bin) when is_binary(Bin) ->
|
write(Pid, ProjNum, Bin) when is_binary(Bin) ->
|
||||||
gen_server:call(Pid, {reg_op, ProjNum, {write, Bin}}, ?LONG_TIME).
|
gen_server:call(Pid, {reg_op, ProjNum, {write, Bin}}, ?LONG_TIME).
|
||||||
|
@ -88,10 +88,10 @@ handle_call({reg_op, _ProjNum, {write, _Bin}}, _From,
|
||||||
#state{register=trimmed} = S) ->
|
#state{register=trimmed} = S) ->
|
||||||
{reply, error_trimmed, S};
|
{reply, error_trimmed, S};
|
||||||
|
|
||||||
handle_call({reg_op, ProjNum, get}, _From, #state{proj_num=MyProjNum} = S)
|
handle_call({reg_op, ProjNum, read}, _From, #state{proj_num=MyProjNum} = S)
|
||||||
when ProjNum /= MyProjNum ->
|
when ProjNum /= MyProjNum ->
|
||||||
{reply, {error_stale_projection, MyProjNum}, S};
|
{reply, {error_stale_projection, MyProjNum}, S};
|
||||||
handle_call({reg_op, _ProjNum, get}, _From, #state{register=Reg} = S) ->
|
handle_call({reg_op, _ProjNum, read}, _From, #state{register=Reg} = S) ->
|
||||||
{reply, {ok, Reg}, S};
|
{reply, {ok, Reg}, S};
|
||||||
|
|
||||||
handle_call({reg_op, _ProjNum, trim}, _From, #state{register=unwritten} = S) ->
|
handle_call({reg_op, _ProjNum, trim}, _From, #state{register=unwritten} = S) ->
|
||||||
|
|
|
@ -45,7 +45,7 @@ concuerror4_test() ->
|
||||||
TrimPids = [spawn(TrimFun), spawn(TrimFun), spawn(TrimFun)],
|
TrimPids = [spawn(TrimFun), spawn(TrimFun), spawn(TrimFun)],
|
||||||
TrimExpected = [error_trimmed,error_trimmed,ok],
|
TrimExpected = [error_trimmed,error_trimmed,ok],
|
||||||
|
|
||||||
GetFun = fun() -> Res = machi_flu0:get(F1, ProjNum),
|
GetFun = fun() -> Res = machi_flu0:read(F1, ProjNum),
|
||||||
Me ! {self(), Res}
|
Me ! {self(), Res}
|
||||||
end,
|
end,
|
||||||
GetPids = [spawn(GetFun)],
|
GetPids = [spawn(GetFun)],
|
||||||
|
@ -92,13 +92,13 @@ wedge_test() ->
|
||||||
{error_stale_projection, ProjNum1} = machi_flu0:write(F1, ProjNum1 - 1, Val),
|
{error_stale_projection, ProjNum1} = machi_flu0:write(F1, ProjNum1 - 1, Val),
|
||||||
error_wedged = machi_flu0:write(F1, ProjNum1 + 1, Val),
|
error_wedged = machi_flu0:write(F1, ProjNum1 + 1, Val),
|
||||||
%% Until we write a newer/bigger projection, all ops are error_wedged
|
%% Until we write a newer/bigger projection, all ops are error_wedged
|
||||||
error_wedged = machi_flu0:get(F1, ProjNum1),
|
error_wedged = machi_flu0:read(F1, ProjNum1),
|
||||||
error_wedged = machi_flu0:write(F1, ProjNum1, Val),
|
error_wedged = machi_flu0:write(F1, ProjNum1, Val),
|
||||||
error_wedged = machi_flu0:trim(F1, ProjNum1),
|
error_wedged = machi_flu0:trim(F1, ProjNum1),
|
||||||
|
|
||||||
ProjNum2 = ProjNum1 + 1,
|
ProjNum2 = ProjNum1 + 1,
|
||||||
ok = machi_flu0:proj_write(F1, ProjNum2, dontcare),
|
ok = machi_flu0:proj_write(F1, ProjNum2, dontcare),
|
||||||
{ok, Val} = machi_flu0:get(F1, ProjNum2),
|
{ok, Val} = machi_flu0:read(F1, ProjNum2),
|
||||||
error_written = machi_flu0:write(F1, ProjNum2, Val),
|
error_written = machi_flu0:write(F1, ProjNum2, Val),
|
||||||
ok = machi_flu0:trim(F1, ProjNum2),
|
ok = machi_flu0:trim(F1, ProjNum2),
|
||||||
error_trimmed = machi_flu0:trim(F1, ProjNum2),
|
error_trimmed = machi_flu0:trim(F1, ProjNum2),
|
||||||
|
|
Loading…
Reference in a new issue