mirror of
https://github.com/valitydev/riak_test.git
synced 2024-11-06 08:35:22 +00:00
Add additional utility functions
Add update_app_config/2 utility function that changes a node's app.config file. Add utility functions that return HTTP/PBC connection info.
This commit is contained in:
parent
a6aec227cd
commit
1b8db5e84d
@ -1,4 +1,4 @@
|
|||||||
{require_otp_vsn, "R13B04|R14"}.
|
{require_otp_vsn, "R13B04|R14|R15"}.
|
||||||
{cover_enabled, true}.
|
{cover_enabled, true}.
|
||||||
{edoc_opts, [{preprocess, true}]}.
|
{edoc_opts, [{preprocess, true}]}.
|
||||||
%%{edoc_opts, [{doclet, edown_doclet}, {pretty_printer, erl_pp}]}.
|
%%{edoc_opts, [{doclet, edown_doclet}, {pretty_printer, erl_pp}]}.
|
||||||
|
@ -19,7 +19,8 @@ main(Args) ->
|
|||||||
erlang:set_cookie(node(), Cookie),
|
erlang:set_cookie(node(), Cookie),
|
||||||
|
|
||||||
application:start(lager),
|
application:start(lager),
|
||||||
lager:set_loglevel(lager_console_backend, debug),
|
LagerLevel = rt:config(rt_lager_level, debug),
|
||||||
|
lager:set_loglevel(lager_console_backend, LagerLevel),
|
||||||
|
|
||||||
%% rt:set_config(rtdev_path, Path),
|
%% rt:set_config(rtdev_path, Path),
|
||||||
%% rt:set_config(rt_max_wait_time, 180000),
|
%% rt:set_config(rt_max_wait_time, 180000),
|
||||||
|
30
src/rt.erl
30
src/rt.erl
@ -38,6 +38,14 @@
|
|||||||
|
|
||||||
-define(HARNESS, (rt:config(rt_harness))).
|
-define(HARNESS, (rt:config(rt_harness))).
|
||||||
|
|
||||||
|
%% @doc Rewrite the given node's app.config file, overriding the varialbes
|
||||||
|
%% in the existing app.config with those in Config.
|
||||||
|
update_app_config(Node, Config) ->
|
||||||
|
stop(Node),
|
||||||
|
?assertEqual(ok, rt:wait_until_unpingable(Node)),
|
||||||
|
?HARNESS:update_app_config(Node, Config),
|
||||||
|
start(Node).
|
||||||
|
|
||||||
%% @doc Deploy a set of freshly installed Riak nodes, returning a list of the
|
%% @doc Deploy a set of freshly installed Riak nodes, returning a list of the
|
||||||
%% nodes deployed.
|
%% nodes deployed.
|
||||||
-spec deploy_nodes(NumNodes :: integer()) -> [node()].
|
-spec deploy_nodes(NumNodes :: integer()) -> [node()].
|
||||||
@ -57,17 +65,20 @@ join(Node, PNode) ->
|
|||||||
R = rpc:call(Node, riak_core, join, [PNode]),
|
R = rpc:call(Node, riak_core, join, [PNode]),
|
||||||
lager:debug("[join] ~p to (~p): ~p", [Node, PNode, R]),
|
lager:debug("[join] ~p to (~p): ~p", [Node, PNode, R]),
|
||||||
%% wait_until_ready(Node),
|
%% wait_until_ready(Node),
|
||||||
|
?assertEqual(ok, R),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%% @doc Have the specified node leave the cluster
|
%% @doc Have the specified node leave the cluster
|
||||||
leave(Node) ->
|
leave(Node) ->
|
||||||
R = rpc:call(Node, riak_core, leave, []),
|
R = rpc:call(Node, riak_core, leave, []),
|
||||||
lager:debug("[leave] ~p: ~p", [Node, R]),
|
lager:debug("[leave] ~p: ~p", [Node, R]),
|
||||||
|
?assertEqual(ok, R),
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
%% @doc Have `Node' remove `OtherNode' from the cluster
|
%% @doc Have `Node' remove `OtherNode' from the cluster
|
||||||
remove(Node, OtherNode) ->
|
remove(Node, OtherNode) ->
|
||||||
rpc:call(Node, riak_kv_console, remove, [[atom_to_list(OtherNode)]]).
|
?assertEqual(ok,
|
||||||
|
rpc:call(Node, riak_kv_console, remove, [[atom_to_list(OtherNode)]])).
|
||||||
|
|
||||||
%% @doc Have `Node' mark `OtherNode' as down
|
%% @doc Have `Node' mark `OtherNode' as down
|
||||||
down(Node, OtherNode) ->
|
down(Node, OtherNode) ->
|
||||||
@ -287,3 +298,20 @@ build_cluster(NumNodes) ->
|
|||||||
[?assertEqual(Nodes, owners_according_to(Node)) || Node <- Nodes],
|
[?assertEqual(Nodes, owners_according_to(Node)) || Node <- Nodes],
|
||||||
lager:info("Cluster built: ~p", [Nodes]),
|
lager:info("Cluster built: ~p", [Nodes]),
|
||||||
Nodes.
|
Nodes.
|
||||||
|
|
||||||
|
connection_info(Nodes) ->
|
||||||
|
[begin
|
||||||
|
{ok, PB_IP} = rpc:call(Node, application, get_env, [riak_kv, pb_ip]),
|
||||||
|
{ok, PB_Port} = rpc:call(Node, application, get_env, [riak_kv, pb_port]),
|
||||||
|
{ok, [{HTTP_IP, HTTP_Port}]} =
|
||||||
|
rpc:call(Node, application, get_env, [riak_core, http]),
|
||||||
|
{Node, [{http, {HTTP_IP, HTTP_Port}}, {pb, {PB_IP, PB_Port}}]}
|
||||||
|
end || Node <- Nodes].
|
||||||
|
|
||||||
|
http_url(Nodes) when is_list(Nodes) ->
|
||||||
|
[begin
|
||||||
|
{Host, Port} = orddict:fetch(http, Connections),
|
||||||
|
lists:flatten(io_lib:format("http://~s:~b", [Host, Port]))
|
||||||
|
end || {_Node, Connections} <- connection_info(Nodes)];
|
||||||
|
http_url(Node) ->
|
||||||
|
hd(http_url([Node])).
|
||||||
|
@ -31,6 +31,24 @@ setup_harness(_Test, _Args) ->
|
|||||||
cleanup_harness() ->
|
cleanup_harness() ->
|
||||||
ok.
|
ok.
|
||||||
|
|
||||||
|
update_app_config(Node, Config) ->
|
||||||
|
N = node_id(Node),
|
||||||
|
ConfigFile = io_lib:format("~s/dev/dev~b/etc/app.config", [?PATH, N]),
|
||||||
|
{ok, [BaseConfig]} = file:consult(ConfigFile),
|
||||||
|
MergeA = orddict:from_list(Config),
|
||||||
|
MergeB = orddict:from_list(BaseConfig),
|
||||||
|
NewConfig =
|
||||||
|
orddict:merge(fun(_, VarsA, VarsB) ->
|
||||||
|
MergeC = orddict:from_list(VarsA),
|
||||||
|
MergeD = orddict:from_list(VarsB),
|
||||||
|
orddict:merge(fun(_, ValA, _ValB) ->
|
||||||
|
ValA
|
||||||
|
end, MergeC, MergeD)
|
||||||
|
end, MergeA, MergeB),
|
||||||
|
NewConfigOut = io_lib:format("~p.", [NewConfig]),
|
||||||
|
?assertEqual(ok, file:write_file(ConfigFile, NewConfigOut)),
|
||||||
|
ok.
|
||||||
|
|
||||||
deploy_nodes(NumNodes) ->
|
deploy_nodes(NumNodes) ->
|
||||||
Path = ?PATH,
|
Path = ?PATH,
|
||||||
lager:info("Riak path: ~p", [Path]),
|
lager:info("Riak path: ~p", [Path]),
|
||||||
|
Loading…
Reference in New Issue
Block a user