Skip to content

Commit

Permalink
ct_slave setup and ping test
Browse files Browse the repository at this point in the history
  • Loading branch information
facundoolano committed Feb 17, 2018
1 parent d78596f commit 1ff77a7
Show file tree
Hide file tree
Showing 2 changed files with 104 additions and 1 deletion.
5 changes: 4 additions & 1 deletion Makefile
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
.PHONY: dev1 dev2 dev3 dev4 clean_data
.PHONY: dev1 dev2 dev3 dev4 clean_data test

dev1:
./rebar3 as dev1 release && _build/dev1/rel/rc_example/bin/rc_example
Expand All @@ -14,3 +14,6 @@ dev4:

clean_data:
rm -rf _build/dev1/rel/rc_example/data* ; rm -rf _build/dev2/rel/rc_example/data* ; rm -rf _build/dev3/rel/rc_example/data*

test:
./rebar3 ct --name [email protected]
100 changes: 100 additions & 0 deletions test/key_value_SUITE.erl
Original file line number Diff line number Diff line change
@@ -0,0 +1,100 @@
-module(key_value_SUITE).

-include_lib("common_test/include/ct.hrl").

-compile(export_all).

all() ->
[ping_test,
key_value_test,
coverage_test].

init_per_suite(Config) ->
Node1 = '[email protected]',
Node2 = '[email protected]',
Node3 = '[email protected]',
start_node(Node1, 8198, 8199),
start_node(Node2, 8298, 8299),
start_node(Node3, 8398, 8399),

build_cluster(Node1, Node2, Node3),

[{node1, Node1},
{node2, Node2},
{node3, Node3} | Config].

end_per_suite(Config) ->
Node1 = ?config(node1, Config),
Node2 = ?config(node2, Config),
Node3 = ?config(node3, Config),
stop_node(Node1),
stop_node(Node2),
stop_node(Node3),
ok.

ping_test(Config) ->
Node1 = ?config(node1, Config),
Node2 = ?config(node2, Config),
Node3 = ?config(node3, Config),

{pong, _Partition1} = rc_command(Node1, ping),
{pong, _Partition2} = rc_command(Node2, ping),
{pong, _Partition3} = rc_command(Node3, ping),

ok.

key_value_test(_Config) ->
%% set three keys, retrieve them
%% replace one, retrieve it
%% delete one, retrieve it
%% set again, retrieve it
ok.

coverage_test(_Config) ->
%% set a range of keys
%% get all keys, ensure all present
%% get all values, ensure all present

ok.

%%% internal
start_node(NodeName, WebPort, HandoffPort) ->
CodePath = code:get_path(),
PathFlag = "-pa " ++ lists:concat(lists:join(" ", CodePath)),
{ok, _} = ct_slave:start(NodeName, [{erl_flags, PathFlag}]),

%% need to set the code path so the same modules are available in the slave
rpc:call(NodeName, code, set_path, [code:get_path()]),

%% set the required environment for riak core
DataDir = "./data/" ++ atom_to_list(NodeName),
rpc:call(NodeName, application, load, [riak_core]),
rpc:call(NodeName, application, set_env, [riak_core, ring_state_dir, DataDir]),
rpc:call(NodeName, application, set_env, [riak_core, platform_data_dir, DataDir]),
rpc:call(NodeName, application, set_env, [riak_core, web_port, WebPort]),
rpc:call(NodeName, application, set_env, [riak_core, handoff_port, HandoffPort]),
rpc:call(NodeName, application, set_env, [riak_core, schema_dirs, ["../../lib/rc_example/priv"]]),

%% Environment = [{ring_state_dir, "./data/ring"},
%% {web_port, WebPort},
%% {handoff_port, HandoffPort},
%% {schema_dirs, ["../../lib/rc_example/priv"]}],
%% rpc:call(NodeName, application, load, [{application, riak_core, [{env, Environment}]}]),

%% start the rc_example app
{ok, _} = rpc:call(NodeName, application, ensure_all_started, [rc_example]),

ok.

stop_node(NodeName) ->
ct_slave:stop(NodeName).

build_cluster(Node1, Node2, Node3) ->
rpc:call(Node2, riak_core, join, [Node1]),
rpc:call(Node3, riak_core, join, [Node1]),
ok.

rc_command(Node, Command) ->
rc_command(Node, Command, []).
rc_command(Node, Command, Arguments) ->
rpc:call(Node, rc_example, Command, Arguments).

0 comments on commit 1ff77a7

Please sign in to comment.