Permalink
Browse files

dialyzer: riak_core fixes

  • Loading branch information...
argv0 committed Apr 4, 2011
1 parent 0582d08 commit ec82f3a7a7dee77748e9741a52f7c3c960560aef
Showing with 36 additions and 26 deletions.
  1. +4 −3 src/riak_core_apl.erl
  2. +32 −23 src/vclock.erl
View
@@ -28,13 +28,14 @@
get_primary_apl/3, get_primary_apl/4
]).
+-export_type([preflist/0, preflist2/0]).
-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
-endif.
-type index() :: non_neg_integer().
-type n_val() :: non_neg_integer().
--type ring() :: term().
+-type ring() :: riak_core_ring:riak_core_ring().
-type preflist() :: [{index(), node()}].
-type preflist2() :: [{{index(), node()}, primary|fallback}].
@@ -93,7 +94,7 @@ get_primary_apl(DocIdx, N, Ring, UpNodes) ->
lists:reverse(Up).
%% Split a preference list into up and down lists
--spec check_up(preflist(), [node()], preflist(), preflist()) -> {preflist(), preflist()}.
+-spec check_up(preflist(), [node()], preflist2(), preflist()) -> {preflist2(), preflist()}.
check_up([], _UpNodes, Up, Pangs) ->
{Up, Pangs};
check_up([{Partition,Node}|Rest], UpNodes, Up, Pangs) ->
@@ -105,7 +106,7 @@ check_up([{Partition,Node}|Rest], UpNodes, Up, Pangs) ->
end.
%% Find fallbacks for downed nodes in the preference list
--spec find_fallbacks(preflist(), preflist(), [node()], preflist()) -> preflist().
+-spec find_fallbacks(preflist(), preflist(), [node()], preflist2()) -> preflist2().
find_fallbacks(_Pangs, [], _UpNodes, Secondaries) ->
Secondaries;
find_fallbacks([], _Fallbacks, _UpNodes, Secondaries) ->
View
@@ -37,9 +37,13 @@
-export([fresh/0,descends/2,merge/1,get_counter/2,get_timestamp/2,
increment/2,increment/3,all_nodes/1,equal/2,prune/3,timestamp/0]).
+-ifdef(TEST).
-include_lib("eunit/include/eunit.hrl").
+-endif.
--type vclock() :: [vc_entry()].
+-export_type([vclock/0, timestamp/0, vclock_node/0]).
+
+-opaque vclock() :: [vc_entry()].
% The timestamp is present but not used, in case a client wishes to inspect it.
-type vc_entry() :: {vclock_node(), {counter(), timestamp()}}.
@@ -53,28 +57,8 @@
fresh() ->
[].
-%% @todo Use common_test or other good test framework, and write more tests.
-%
-% @doc Serves as both a trivial test and some example code.
-example_test() ->
- A = vclock:fresh(),
- B = vclock:fresh(),
- A1 = vclock:increment(a, A),
- B1 = vclock:increment(b, B),
- true = vclock:descends(A1,A),
- true = vclock:descends(B1,B),
- false = vclock:descends(A1,B1),
- A2 = vclock:increment(a, A1),
- C = vclock:merge([A2, B1]),
- C1 = vclock:increment(c, C),
- true = vclock:descends(C1, A2),
- true = vclock:descends(C1, B1),
- false = vclock:descends(B1, C1),
- false = vclock:descends(B1, A1),
- ok.
-
% @doc Return true if Va is a direct descendant of Vb, else false -- remember, a vclock is its own descendant!
--spec descends(Va :: vclock(), Vb :: vclock()) -> boolean().
+-spec descends(Va :: vclock()|[], Vb :: vclock()|[]) -> boolean().
descends(_, []) ->
% all vclocks descend from the empty vclock
true;
@@ -99,7 +83,7 @@ descends(Va, Vb) ->
% @doc Combine all VClocks in the input list into their least possible
% common descendant.
--spec merge(VClocks :: [vclock()]) -> vclock().
+-spec merge(VClocks :: [vclock()]) -> vclock() | [].
merge([]) -> [];
merge([SingleVclock]) -> SingleVclock;
merge([First|Rest]) -> merge(Rest, lists:keysort(1, First)).
@@ -213,6 +197,29 @@ prune_vclock1(V,Now,BProps,HeadTime) ->
end
end.
+%% ===================================================================
+%% EUnit tests
+%% ===================================================================
+-ifdef(TEST).
+
+% @doc Serves as both a trivial test and some example code.
+example_test() ->
+ A = vclock:fresh(),
+ B = vclock:fresh(),
+ A1 = vclock:increment(a, A),
+ B1 = vclock:increment(b, B),
+ true = vclock:descends(A1,A),
+ true = vclock:descends(B1,B),
+ false = vclock:descends(A1,B1),
+ A2 = vclock:increment(a, A1),
+ C = vclock:merge([A2, B1]),
+ C1 = vclock:increment(c, C),
+ true = vclock:descends(C1, A2),
+ true = vclock:descends(C1, B1),
+ false = vclock:descends(B1, C1),
+ false = vclock:descends(B1, A1),
+ ok.
+
prune_small_test() ->
% vclock with less entries than small_vclock will be untouched
Now = riak_core_util:moment(),
@@ -290,3 +297,5 @@ merge_test() ->
?assertEqual([], merge(vclock:fresh())),
?assertEqual([{<<"1">>,{1,1}},{<<"2">>,{2,2}},{<<"3">>,{3,3}},{<<"4">>,{4,4}}],
merge([VC1, VC2])).
+
+-endif.

0 comments on commit ec82f3a

Please sign in to comment.