Skip to content
Browse files

More tests, less races, less shelling out complexity.

  • Loading branch information...
1 parent 5579ef0 commit d5146d95b53534e2d3c2d36b01279ad4e95db683 Simon MacMullen committed
Showing with 57 additions and 20 deletions.
  1. +0 −1 etc/rabbit-test.config
  2. +0 −2 package.mk
  3. +57 −17 test/src/rabbit_shovel_test_dyn.erl
View
1 etc/rabbit-test.config
@@ -1 +0,0 @@
-[].
View
2 package.mk
@@ -1,5 +1,3 @@
RELEASABLE:=true
DEPS:=rabbitmq-erlang-client
WITH_BROKER_TEST_COMMANDS:=rabbit_shovel_test_all:all_tests()
-# To make test_dyn:plugin_dir() work - TODO could this be better?
-WITH_BROKER_TEST_CONFIG:=$(PACKAGE_DIR)/etc/rabbit-test
View
74 test/src/rabbit_shovel_test_dyn.erl
@@ -19,6 +19,8 @@
-include_lib("eunit/include/eunit.hrl").
-include_lib("amqp_client/include/amqp_client.hrl").
+-import(rabbit_misc, [pget/2]).
+
simple_test() ->
with_ch(
fun (Ch) ->
@@ -33,6 +35,40 @@ simple_test() ->
expect_empty(Ch, <<"dest">>)
end).
+exchange_test() ->
+ with_ch(
+ fun (Ch) ->
+ amqp_channel:call(Ch, #'queue.declare'{queue = <<"queue">>,
+ durable = true}),
+ amqp_channel:call(
+ Ch, #'queue.bind'{queue = <<"queue">>,
+ exchange = <<"amq.topic">>,
+ routing_key = <<"test-key">>}),
+ set_param("shovel", "test",
+ [{"src-uri", "amqp://"},
+ {"src-exchange", "amq.direct"},
+ {"src-exchange-key", "test-key"},
+ {"dest-uri", "amqp://"},
+ {"dest-exchange", "amq.topic"}]),
+ publish_expect(Ch, <<"amq.direct">>, <<"test-key">>,
+ <<"queue">>, <<"hello">>),
+ set_param("shovel", "test",
+ [{"src-uri", "amqp://"},
+ {"src-exchange", "amq.direct"},
+ {"src-exchange-key", "test-key"},
+ {"dest-uri", "amqp://"},
+ {"dest-exchange", "amq.topic"},
+ {"dest-exchange-key", "new-key"}]),
+ publish(Ch, <<"amq.direct">>, <<"test-key">>, <<"hello">>),
+ expect_empty(Ch, <<"queue">>),
+ amqp_channel:call(
+ Ch, #'queue.bind'{queue = <<"queue">>,
+ exchange = <<"amq.topic">>,
+ routing_key = <<"new-key">>}),
+ publish_expect(Ch, <<"amq.direct">>, <<"test-key">>,
+ <<"queue">>, <<"hello">>)
+ end).
+
%%----------------------------------------------------------------------------
with_ch(Fun) ->
@@ -40,6 +76,7 @@ with_ch(Fun) ->
{ok, Ch} = amqp_connection:open_channel(Conn),
Fun(Ch),
amqp_connection:close(Conn),
+ cleanup(),
ok.
publish(Ch, X, Key, Payload) when is_binary(Payload) ->
@@ -72,24 +109,27 @@ expect_empty(Ch, Q) ->
amqp_channel:call(Ch, #'basic.get'{ queue = Q })).
set_param(Component, Name, Value) ->
- rabbitmqctl(
- fmt("set_parameter ~s ~s '~s'", [Component, Name, json(Value)])).
+ ok = rabbit_runtime_parameters:set(
+ <<"/">>, list_to_binary(Component), list_to_binary(Name),
+ [{list_to_binary(K), list_to_binary(V)} || {K, V} <- Value]),
+ await_shovel(list_to_binary(Name)).
+
+await_shovel(Name) ->
+ S = rabbit_shovel_status:status(),
+ case lists:member(Name, [N || {N, dynamic, {running, _, _}, _} <- S]) of
+ true -> ok;
+ false -> timer:sleep(100),
+ await_shovel(Name)
+ end.
clear_param(Component, Name) ->
- rabbitmqctl(fmt("clear_parameter ~s ~s", [Component, Name])).
-
-fmt(Fmt, Args) ->
- string:join(string:tokens(rabbit_misc:format(Fmt, Args), [$\n]), " ").
-
-rabbitmqctl(Args) ->
- ?assertCmd(
- plugin_dir() ++ "/../rabbitmq-server/scripts/rabbitmqctl " ++ Args),
- timer:sleep(100).
+ rabbit_runtime_parameters:clear(
+ <<"/">>, list_to_binary(Component), list_to_binary(Name)).
-plugin_dir() ->
- {ok, [[File]]} = init:get_argument(config),
- filename:dirname(filename:dirname(File)).
+cleanup() ->
+ [rabbit_runtime_parameters:clear(pget(vhost, P),
+ pget(component, P),
+ pget(name, P)) ||
+ P <- rabbit_runtime_parameters:list()],
+ [rabbit_amqqueue:delete(Q, false, false) || Q <- rabbit_amqqueue:list()].
-json(List) ->
- "{" ++ string:join([quote(K, V) || {K, V} <- List], ",") ++ "}".
-quote(K, V) -> rabbit_misc:format("\"~s\":\"~s\"", [K, V]).

0 comments on commit d5146d9

Please sign in to comment.
Something went wrong with that request. Please try again.