summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/mem3.erl22
-rw-r--r--test/mem3_test.erl7
2 files changed, 29 insertions, 0 deletions
diff --git a/src/mem3.erl b/src/mem3.erl
index 584a2a14..5de00826 100644
--- a/src/mem3.erl
+++ b/src/mem3.erl
@@ -28,39 +28,60 @@
-export([init/1, handle_call/3, handle_cast/2, handle_info/2,
terminate/2, code_change/3]).
+
%% includes
-include("../include/config.hrl").
-include("../include/common.hrl").
+%% types
+-type join_type() :: first | new | replace.
+-type join_order() :: non_neg_integer().
+-type options() :: list().
+-type mem_node() :: {join_order(), node(), options()}.
+-type mem_node_list() :: [mem_node()].
+-type arg_options() :: {test, boolean()} | {config, #config{}}.
+-type args() :: [] | [arg_options()].
+-type mem_state() :: #mem{}.
+-type epoch() :: float().
+-type clock() :: {node(), epoch()}.
+-type vector_clock() :: [clock()].
+
%%====================================================================
%% API
%%====================================================================
+-spec start_link() -> {ok, pid()}.
start_link() ->
start_link([]).
+-spec start_link(args()) -> {ok, pid()}.
start_link(Args) ->
gen_server:start_link({local, ?MODULE}, ?MODULE, Args, []).
+-spec stop() -> ok.
stop() ->
stop(?MODULE).
+-spec stop(atom()) -> ok.
stop(Server) ->
gen_server:cast(Server, stop).
+-spec join(join_type(), mem_node_list()) -> ok.
join(JoinType, Nodes) ->
gen_server:call(?MODULE, {join, JoinType, Nodes}).
+-spec clock() -> vector_clock().
clock() ->
gen_server:call(?MODULE, clock).
+-spec state() -> mem_state().
state() ->
gen_server:call(?MODULE, state).
@@ -82,6 +103,7 @@ fullmap() ->
%%====================================================================
%% start up membership server
+-spec init(args()) -> {ok, mem_state()}.
init(Args) ->
process_flag(trap_exit,true),
Config = get_config(Args),
diff --git a/test/mem3_test.erl b/test/mem3_test.erl
index 99f32ff9..8747cf02 100644
--- a/test/mem3_test.erl
+++ b/test/mem3_test.erl
@@ -16,6 +16,7 @@ all_tests_test_() ->
{with, Pid,
[
fun init/1,
+ fun clock/1,
fun join_first/1
]}
end}
@@ -42,6 +43,12 @@ init(_Pid) ->
?assertEqual(true, Test).
+clock(_Pid) ->
+ Node = node(),
+ Clock = mem3:clock(),
+ ?assertMatch([{Node, _}], Clock).
+
+
join_first(_Pid) ->
mem3:join(first, [{1, a, []}, {2, b, []}]),
Fullmap = mem3:fullmap(),