Skip to content

Commit e55eb67

Browse files
committed
Add -spec as appropriate, and style improvements
1 parent b695998 commit e55eb67

File tree

2 files changed

+21
-15
lines changed

2 files changed

+21
-15
lines changed

src/riak_repl2_rtq.erl

Lines changed: 13 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@
8888
}).
8989

9090
-type name() :: term().
91+
-type seq() :: non_neg_integer().
9192

9293
%% API
9394
%% @doc Start linked, registered to module name.
@@ -238,13 +239,15 @@ dumpq() ->
238239

239240
%% @doc Return summary data for the objects currently in the queue.
240241
%% The return value is a list of tuples of the form {SequenceNum, Key, Size}.
241-
-spec summarize() -> [{integer(), string(), integer()}].
242+
-spec summarize() -> [{seq(), riak_object:key(), non_neg_integer()}].
242243
summarize() ->
243-
gen_server:call(?SERVER, summarize, infinity).
244+
gen_server:call(?SERVER, summarize, infinity).
244245

245246
%% @doc If an object with the given Seq number is currently in the queue,
246247
%% evict it and return ok.
247-
evict(Seq) -> gen_server:call(?SERVER, {evict, Seq}, infinity).
248+
-spec evict(Seq :: seq()) -> 'ok'.
249+
evict(Seq) ->
250+
gen_server:call(?SERVER, {evict, Seq}, infinity).
248251

249252
%% @doc If an object with the given Seq number is currently in the queue and it
250253
%% also matches the given Key, then evict it and return ok. This is a safer
@@ -254,7 +257,10 @@ evict(Seq) -> gen_server:call(?SERVER, {evict, Seq}, infinity).
254257
%% given `Seq' number, then {not_found, Seq} is returned, whereas if the
255258
%% object with the given `Seq' number is present but does not match the
256259
%% provided `Key', then {wrong_key, Seq, Key} is returned.
257-
evict(Seq, Key) -> gen_server:call(?SERVER, {evict, Seq, Key}, infinity).
260+
-spec evict(Seq :: seq(), Key :: riak_object:key()) ->
261+
'ok' | {'not_found', integer()} | {'wrong_key', integer(), riak_object:key()}.
262+
evict(Seq, Key) ->
263+
gen_server:call(?SERVER, {evict, Seq, Key}, infinity).
258264

259265
%% @doc Signal that this node is doing down, and so a proxy process needs to
260266
%% start to avoid dropping, or aborting unacked results.
@@ -359,9 +365,9 @@ handle_call(dumpq, _From, State = #state{qtab = QTab}) ->
359365

360366
handle_call(summarize, _From, State = #state{qtab = QTab}) ->
361367
Fun = fun({Seq, _NumItems, Bin, _Meta}, Acc) ->
362-
Obj = riak_repl_util:from_wire(Bin),
363-
{Key, Size} = summarize_object(Obj),
364-
Acc ++ [{Seq, Key, Size}]
368+
Obj = riak_repl_util:from_wire(Bin),
369+
{Key, Size} = summarize_object(Obj),
370+
Acc ++ [{Seq, Key, Size}]
365371
end,
366372
{reply, ets:foldl(Fun, [], QTab), State};
367373

test/riak_repl2_rtq_tests.erl

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,12 @@
22
-compile(export_all).
33
-include_lib("eunit/include/eunit.hrl").
44

5-
-define(set_env, application:set_env(riak_repl, rtq_max_bytes, 10*1024*1024)).
6-
-define(unset_env, application:unset_env(riak_repl, rtq_max_bytes)).
5+
-define(setup_env, application:set_env(riak_repl, rtq_max_bytes, 10*1024*1024)).
6+
-define(clean_env, application:unset_env(riak_repl, rtq_max_bytes)).
77

88
rtq_trim_test() ->
99
%% make sure the queue is 10mb
10-
?set_env,
10+
?setup_env,
1111
{ok, Pid} = riak_repl2_rtq:start_test(),
1212
try
1313
gen_server:call(Pid, {register, rtq_test}),
@@ -22,7 +22,7 @@ rtq_trim_test() ->
2222
%% the queue is now empty
2323
?assert(gen_server:call(Pid, {is_empty, rtq_test}))
2424
after
25-
?unset_env,
25+
?clean_env,
2626
exit(Pid, kill)
2727
end.
2828

@@ -48,12 +48,12 @@ accumulate(Pid, Acc, C) ->
4848

4949
status_test_() ->
5050
{setup, fun() ->
51-
?set_env,
51+
?setup_env,
5252
{ok, QPid} = riak_repl2_rtq:start_link(),
5353
QPid
5454
end,
5555
fun(QPid) ->
56-
?unset_env,
56+
?clean_env,
5757
riak_repl_test_util:kill_and_wait(QPid)
5858
end,
5959
fun(_QPid) -> [
@@ -275,15 +275,15 @@ overload_test_() ->
275275
]}.
276276

277277
start_rtq() ->
278-
?set_env,
278+
?setup_env,
279279
%% application:start(lager),
280280
%% lager:set_loglevel(lager_console_backend, debug),
281281
{ok, Pid} = riak_repl2_rtq:start_link(),
282282
gen_server:call(Pid, {register, rtq_test}),
283283
Pid.
284284

285285
kill_rtq(QPid) ->
286-
?unset_env,
286+
?clean_env,
287287
riak_repl_test_util:kill_and_wait(QPid).
288288

289289
object_format() -> riak_core_capability:get({riak_kv, object_format}, v0).

0 commit comments

Comments
 (0)