mirror of
https://github.com/valitydev/riak_test.git
synced 2024-11-07 08:58:52 +00:00
Add utility functions for testing object deletion
This adds the `rt:systest_delete` and `rt:systest_verify_delete` functions, which behave similarly to the `rt:systest_write` and `rt:systest_read` functions which already exist.
This commit is contained in:
parent
fd7f191f0a
commit
d331c718a5
57
src/rt.erl
57
src/rt.erl
@ -1229,6 +1229,63 @@ versions() ->
|
||||
%%% Basic Read/Write Functions
|
||||
%%%===================================================================
|
||||
|
||||
systest_delete(Node, Size) ->
|
||||
systest_delete(Node, Size, 2).
|
||||
|
||||
systest_delete(Node, Size, W) ->
|
||||
systest_delete(Node, 1, Size, <<"systest">>, W).
|
||||
|
||||
%% @doc Delete `(End-Start)+1' objects on `Node'. Keys deleted will be
|
||||
%% `Start', `Start+1' ... `End', each key being encoded as a 32-bit binary
|
||||
%% (`<<Key:32/integer>>').
|
||||
%%
|
||||
%% The return value of this function is a list of errors
|
||||
%% encountered. If all deletes were successful, return value is an
|
||||
%% empty list. Each error has the form `{N :: integer(), Error :: term()}',
|
||||
%% where `N' is the unencoded key of the object that failed to store.
|
||||
systest_delete(Node, Start, End, Bucket, W) ->
|
||||
rt:wait_for_service(Node, riak_kv),
|
||||
{ok, C} = riak:client_connect(Node),
|
||||
F = fun(N, Acc) ->
|
||||
Key = <<N:32/integer>>,
|
||||
try C:delete(Bucket, Key, W) of
|
||||
ok ->
|
||||
Acc;
|
||||
Other ->
|
||||
[{N, Other} | Acc]
|
||||
catch
|
||||
What:Why ->
|
||||
[{N, {What, Why}} | Acc]
|
||||
end
|
||||
end,
|
||||
lists:foldl(F, [], lists:seq(Start, End)).
|
||||
|
||||
systest_verify_delete(Node, Size) ->
|
||||
systest_verify_delete(Node, Size, 2).
|
||||
|
||||
systest_verify_delete(Node, Size, R) ->
|
||||
systest_verify_delete(Node, 1, Size, <<"systest">>, R).
|
||||
|
||||
%% @doc Read a series of keys on `Node' and verify that the objects
|
||||
%% do not exist. This could, for instance, be used as a followup to
|
||||
%% `systest_delete' to ensure that the objects were actually deleted.
|
||||
systest_verify_delete(Node, Start, End, Bucket, R) ->
|
||||
rt:wait_for_service(Node, riak_kv),
|
||||
{ok, C} = riak:client_connect(Node),
|
||||
F = fun(N, Acc) ->
|
||||
Key = <<N:32/integer>>,
|
||||
try C:get(Bucket, Key, R) of
|
||||
{error, notfound} ->
|
||||
[];
|
||||
Other ->
|
||||
[{N, Other} | Acc]
|
||||
catch
|
||||
What:Why ->
|
||||
[{N, {What, Why}} | Acc]
|
||||
end
|
||||
end,
|
||||
lists:foldl(F, [], lists:seq(Start, End)).
|
||||
|
||||
systest_write(Node, Size) ->
|
||||
systest_write(Node, Size, 2).
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user