Test refactoring
This commit is contained in:
parent
c5b4bf8d7b
commit
9d2f494db0
3 changed files with 34 additions and 28 deletions
|
@ -27,6 +27,7 @@
|
||||||
latest_projection_epoch_number/1]).
|
latest_projection_epoch_number/1]).
|
||||||
-export([write_page/3, read_page/2, scan_forward/3,
|
-export([write_page/3, read_page/2, scan_forward/3,
|
||||||
fill_page/2, trim_page/2]).
|
fill_page/2, trim_page/2]).
|
||||||
|
-export([simple_test_setup/5]).
|
||||||
|
|
||||||
-include("corfurl.hrl").
|
-include("corfurl.hrl").
|
||||||
|
|
||||||
|
@ -351,3 +352,21 @@ project_to_chain(LPN, P) ->
|
||||||
I = ((LPN - Start) rem tuple_size(Chains)) + 1,
|
I = ((LPN - Start) rem tuple_size(Chains)) + 1,
|
||||||
element(I, Chains)
|
element(I, Chains)
|
||||||
end.
|
end.
|
||||||
|
|
||||||
|
simple_test_setup(RootDir, BaseDirName, PageSize, NumPages, NumFLUs) ->
|
||||||
|
PDir = RootDir ++ "/" ++ BaseDirName ++ ".projection",
|
||||||
|
filelib:ensure_dir(PDir),
|
||||||
|
BaseDir = RootDir ++ "/flu." ++ BaseDirName ++ ".",
|
||||||
|
MyDir = fun(X) -> BaseDir ++ integer_to_list(X) end,
|
||||||
|
DeleteFLUData = fun() -> [ok = corfurl_util:delete_dir(MyDir(X)) ||
|
||||||
|
X <- lists:seq(1, NumFLUs)] end,
|
||||||
|
DeleteFLUData(),
|
||||||
|
FLUs = [begin
|
||||||
|
element(2, corfurl_flu:start_link(MyDir(X),
|
||||||
|
PageSize, NumPages*PageSize))
|
||||||
|
end || X <- lists:seq(1, NumFLUs)],
|
||||||
|
|
||||||
|
{ok, Seq} = corfurl_sequencer:start_link(FLUs),
|
||||||
|
P0 = corfurl:new_simple_projection(PDir, 1, 1, 1*100, [FLUs]),
|
||||||
|
P1 = P0#proj{seq={Seq, unused, unused}},
|
||||||
|
{FLUs, Seq, P1, DeleteFLUData}.
|
||||||
|
|
|
@ -123,7 +123,7 @@ init({Dir, ExpPageSize, ExpMaxMem}) ->
|
||||||
lclock_init(),
|
lclock_init(),
|
||||||
|
|
||||||
MemFile = memfile_path(Dir),
|
MemFile = memfile_path(Dir),
|
||||||
filelib:ensure_dir(MemFile),
|
ok = filelib:ensure_dir(MemFile),
|
||||||
{ok, FH} = file:open(MemFile, [read, write, raw, binary]),
|
{ok, FH} = file:open(MemFile, [read, write, raw, binary]),
|
||||||
|
|
||||||
{_Version, MinEpoch, PageSize, MaxMem, TrimWatermark} =
|
{_Version, MinEpoch, PageSize, MaxMem, TrimWatermark} =
|
||||||
|
|
|
@ -48,37 +48,22 @@ pack_v1_test() ->
|
||||||
Term <- [foo, {bar, baz, <<"yo">>}],
|
Term <- [foo, {bar, baz, <<"yo">>}],
|
||||||
Size <- lists:seq(100, 5000, 500)].
|
Size <- lists:seq(100, 5000, 500)].
|
||||||
|
|
||||||
run_test(Name, PageSize, NumPages, NumFLUs, FUN) ->
|
run_test(RootDir, BaseDirName, PageSize, NumPages, NumFLUs, FUN) ->
|
||||||
PDir = "./tmp." ++ Name,
|
{FLUs, Seq, P1, Del} = corfurl:simple_test_setup(
|
||||||
BaseDir = "/tmp/" ++ atom_to_list(?MODULE) ++ ".",
|
RootDir, BaseDirName, PageSize, NumPages, NumFLUs),
|
||||||
MyDir = fun(X) -> BaseDir ++ integer_to_list(X) end,
|
|
||||||
Del = fun() -> [ok = corfurl_util:delete_dir(MyDir(X)) ||
|
|
||||||
X <- lists:seq(1, NumFLUs)] end,
|
|
||||||
|
|
||||||
Del(),
|
|
||||||
FLUs = [begin
|
|
||||||
element(2, corfurl_flu:start_link(MyDir(X),
|
|
||||||
PageSize, NumPages*PageSize))
|
|
||||||
end || X <- lists:seq(1, NumFLUs)],
|
|
||||||
|
|
||||||
try
|
try
|
||||||
{ok, Seq} = ?SEQ:start_link(FLUs),
|
|
||||||
try
|
|
||||||
P0 = corfurl:new_simple_projection(PDir, 1, 1, 1*100, [FLUs]),
|
|
||||||
P1 = P0#proj{seq={Seq, unused, unused}},
|
|
||||||
FUN(PageSize, Seq, P1)
|
FUN(PageSize, Seq, P1)
|
||||||
after
|
after
|
||||||
?SEQ:stop(Seq)
|
?SEQ:stop(Seq),
|
||||||
end
|
|
||||||
after
|
|
||||||
[ok = corfurl_flu:stop(FLU) || FLU <- FLUs],
|
[ok = corfurl_flu:stop(FLU) || FLU <- FLUs],
|
||||||
Del()
|
Del()
|
||||||
end.
|
end.
|
||||||
|
|
||||||
smoke_test() ->
|
smoke_test() ->
|
||||||
ok = run_test("projection", 4096, 5*1024, 1, fun smoke_test_fun/3).
|
ok = run_test("/tmp", "projection",
|
||||||
|
4096, 5*1024, 1, fun smoke_test_int/3).
|
||||||
|
|
||||||
smoke_test_fun(PageSize, Seq, P1) ->
|
smoke_test_int(PageSize, Seq, P1) ->
|
||||||
ok = ?SEQ:set_tails(Seq, [{42,4242}, {43,4343}]),
|
ok = ?SEQ:set_tails(Seq, [{42,4242}, {43,4343}]),
|
||||||
{ok, [4242, 4343]} = ?SEQ:get_tails(Seq, [42, 43]),
|
{ok, [4242, 4343]} = ?SEQ:get_tails(Seq, [42, 43]),
|
||||||
|
|
||||||
|
@ -94,9 +79,10 @@ smoke_test_fun(PageSize, Seq, P1) ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
write_forward_test() ->
|
write_forward_test() ->
|
||||||
ok = run_test("write_forward", 4096, 5*1024, 1, fun write_forward_test_fun/3).
|
ok = run_test("/tmp", "write_forward",
|
||||||
|
4096, 5*1024, 1, fun write_forward_test_int/3).
|
||||||
|
|
||||||
write_forward_test_fun(PageSize, _Seq, P1) ->
|
write_forward_test_int(PageSize, _Seq, P1) ->
|
||||||
StreamNum = 0,
|
StreamNum = 0,
|
||||||
NumPages = 10,
|
NumPages = 10,
|
||||||
Pages = [term_to_binary({smoke, X}) || X <- lists:seq(1, NumPages)],
|
Pages = [term_to_binary({smoke, X}) || X <- lists:seq(1, NumPages)],
|
||||||
|
@ -118,9 +104,10 @@ write_stream_pages(Proj0, Pages, PageSize, InitialBackPs, StreamNum) ->
|
||||||
Res.
|
Res.
|
||||||
|
|
||||||
scan_backward_test() ->
|
scan_backward_test() ->
|
||||||
ok = run_test("scan_backward", 4096, 5*1024, 1, fun scan_backward_test_fun/3).
|
ok = run_test("/tmp", "scan_backward",
|
||||||
|
4096, 5*1024, 1, fun scan_backward_test_int/3).
|
||||||
|
|
||||||
scan_backward_test_fun(PageSize, _Seq, P1) ->
|
scan_backward_test_int(PageSize, _Seq, P1) ->
|
||||||
StreamNum = 0,
|
StreamNum = 0,
|
||||||
NumPages = 10,
|
NumPages = 10,
|
||||||
PageSeq = lists:seq(1, NumPages),
|
PageSeq = lists:seq(1, NumPages),
|
||||||
|
|
Loading…
Reference in a new issue