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}.
|
||||
{edoc_opts, [{preprocess, true}]}.
|
||||
%%{edoc_opts, [{doclet, edown_doclet}, {pretty_printer, erl_pp}]}.
|
||||
|
@ -19,7 +19,8 @@ main(Args) ->
|
||||
erlang:set_cookie(node(), Cookie),
|
||||
|
||||
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(rt_max_wait_time, 180000),
|
||||
|
30
src/rt.erl
30
src/rt.erl
@ -38,6 +38,14 @@
|
||||
|
||||
-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
|
||||
%% nodes deployed.
|
||||
-spec deploy_nodes(NumNodes :: integer()) -> [node()].
|
||||
@ -57,17 +65,20 @@ join(Node, PNode) ->
|
||||
R = rpc:call(Node, riak_core, join, [PNode]),
|
||||
lager:debug("[join] ~p to (~p): ~p", [Node, PNode, R]),
|
||||
%% wait_until_ready(Node),
|
||||
?assertEqual(ok, R),
|
||||
ok.
|
||||
|
||||
%% @doc Have the specified node leave the cluster
|
||||
leave(Node) ->
|
||||
R = rpc:call(Node, riak_core, leave, []),
|
||||
lager:debug("[leave] ~p: ~p", [Node, R]),
|
||||
?assertEqual(ok, R),
|
||||
ok.
|
||||
|
||||
%% @doc Have `Node' remove `OtherNode' from the cluster
|
||||
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
|
||||
down(Node, OtherNode) ->
|
||||
@ -287,3 +298,20 @@ build_cluster(NumNodes) ->
|
||||
[?assertEqual(Nodes, owners_according_to(Node)) || Node <- Nodes],
|
||||
lager:info("Cluster built: ~p", [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() ->
|
||||
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) ->
|
||||
Path = ?PATH,
|
||||
lager:info("Riak path: ~p", [Path]),
|
||||
|
Loading…
Reference in New Issue
Block a user