Improve tests.

This commit is contained in:
Gregory Burd 2012-06-14 18:15:47 +01:00
parent 95a133c7cc
commit fb01a7dd29

View file

@ -61,7 +61,8 @@ full_test_() ->
?_test(test_tree_simple_1()),
?_test(test_tree_simple_2()),
?_test(test_tree_simple_4()),
% {timeout, 300, ?_test(test_tree())},
?_test(test_tree_simple_5()),
{timeout, 300, ?_test(test_tree())},
{timeout, 120, ?_test(test_qc())}
]}.
@ -283,12 +284,14 @@ test_tree_simple_1() ->
{ok, Tree} = hanoidb:open("simple"),
ok = hanoidb:put(Tree, <<>>, <<"data", 77:128>>),
{ok, <<"data", 77:128>>} = hanoidb:get(Tree, <<>>),
ok = hanoidb:destroy(Tree),
ok = hanoidb:close(Tree).
test_tree_simple_2() ->
{ok, Tree} = hanoidb:open("simple"),
ok = hanoidb:put(Tree, <<"ã">>, <<"µ">>),
ok = hanoidb:delete(Tree, <<"ã">>),
ok = hanoidb:destroy(Tree),
ok = hanoidb:close(Tree).
test_tree_simple_4() ->
@ -299,6 +302,16 @@ test_tree_simple_4() ->
{ok, Tree} = hanoidb:open("simple"),
ok = hanoidb:put(Tree, Key, Value),
?assertEqual({ok, Value}, hanoidb:get(Tree, Key)),
ok = hanoidb:destroy(Tree),
ok = hanoidb:close(Tree).
test_tree_simple_5() ->
{ok, Tree} = hanoidb:open("simple"),
ok = hanoidb:put(Tree, <<"foo">>, <<"bar">>, 2),
{ok, <<"bar">>} = hanoidb:get(Tree, <<"foo">>),
ok = timer:sleep(3000),
not_found = hanoidb:get(Tree, <<"foo">>),
ok = hanoidb:destroy(Tree),
ok = hanoidb:close(Tree).
test_tree() ->
@ -309,7 +322,7 @@ test_tree() ->
end,
ok,
lists:seq(2,10000,1)),
io:format(user, "INSERT DONE 1~n", []),
% io:format(user, "INSERT DONE 1~n", []),
lists:foldl(fun(N,_) ->
ok = hanoidb:put(Tree,
@ -318,21 +331,24 @@ test_tree() ->
ok,
lists:seq(4000,6000,1)),
io:format(user, "INSERT DONE 2~n", []),
% io:format(user, "INSERT DONE 2~n", []),
hanoidb:delete(Tree, <<1500:128>>),
io:format(user, "INSERT DONE 3~n", []),
% io:format(user, "INSERT DONE 3~n", []),
{Time,{ok,Count}} = timer:tc(?MODULE, run_fold, [Tree,1000,2000]),
{Time,{ok,Count}} = timer:tc(?MODULE, run_fold, [Tree,1000,2000,5]),
error_logger:info_msg("time to fold: ~p/sec (time=~p, count=~p)~n", [1000000/(Time/Count), Time/1000000, Count]),
{Time,{ok,Count}} = timer:tc(?MODULE, run_fold, [Tree,1000,2000,1000]),
error_logger:info_msg("time to fold: ~p/sec (time=~p, count=~p)~n", [1000000/(Time/Count), Time/1000000, Count]),
ok = hanoidb:close(Tree).
run_fold(Tree,From,To) ->
run_fold(Tree,From,To,Limit) ->
{_, Count} = hanoidb:fold_range(Tree,
fun(<<N:128>>,_Value, {N, C}) ->
{N + 1, C + 1};
@ -340,7 +356,7 @@ run_fold(Tree,From,To) ->
{1502, C + 1}
end,
{From, 0},
#key_range{from_key= <<From:128>>, to_key= <<(To+1):128>>}),
#key_range{from_key= <<From:128>>, to_key= <<(To+1):128>>, limit=Limit}),
{ok, Count}.