diff options
| author | Michael Klishin <michael@clojurewerkz.org> | 2020-07-03 10:37:52 +0700 |
|---|---|---|
| committer | Michael Klishin <michael@clojurewerkz.org> | 2020-07-03 10:37:52 +0700 |
| commit | dc53b23824f611541ae42ad0f6977929308e7e20 (patch) | |
| tree | 8c01df657dc73d4dba8c86c4399b51a0d589fcbf | |
| parent | dd6915ad86bc11d02bc1ebec5dd681c2da7d19ca (diff) | |
| download | rabbitmq-server-git-dc53b23824f611541ae42ad0f6977929308e7e20.tar.gz | |
rabbit_definitions: format exchange, queue and binding arguments the same way HTTP API would
this makes them JSON serialisation-safe without any post-processing
of the returned data structure.
| -rw-r--r-- | src/rabbit_definitions.erl | 6 | ||||
| -rw-r--r-- | test/definition_import_SUITE.erl | 41 |
2 files changed, 36 insertions, 11 deletions
diff --git a/src/rabbit_definitions.erl b/src/rabbit_definitions.erl index 9133ed1392..e9121580b9 100644 --- a/src/rabbit_definitions.erl +++ b/src/rabbit_definitions.erl @@ -656,7 +656,7 @@ exchange_definition(#exchange{name = #resource{virtual_host = VHost, name = Name <<"type">> => Type, <<"durable">> => Durable, <<"auto_delete">> => AD, - <<"arguments">> => Args}. + <<"arguments">> => rabbit_misc:amqp_table(Args)}. list_queues() -> %% exclude exclusive queues, they cannot be restored @@ -679,7 +679,7 @@ queue_definition(Q) -> <<"type">> => Type, <<"durable">> => amqqueue:is_durable(Q), <<"auto_delete">> => amqqueue:is_auto_delete(Q), - <<"arguments">> => maps:from_list(Arguments) + <<"arguments">> => rabbit_misc:amqp_table(Arguments) }. list_bindings() -> @@ -696,7 +696,7 @@ binding_definition(#binding{source = S, <<"destination">> => D#resource.name, <<"destination_type">> => D#resource.kind, <<"routing_key">> => RoutingKey, - <<"arguments">> => maps:from_list(Arguments) + <<"arguments">> => rabbit_misc:amqp_table(Arguments) }. list_vhosts() -> diff --git a/test/definition_import_SUITE.erl b/test/definition_import_SUITE.erl index 063b1de46a..e319c6d588 100644 --- a/test/definition_import_SUITE.erl +++ b/test/definition_import_SUITE.erl @@ -26,7 +26,8 @@ all() -> [ {group, import_on_a_running_node}, - {group, import_on_a_booting_node} + {group, import_on_a_booting_node}, + {group, roundtrip} ]. groups() -> @@ -51,6 +52,10 @@ groups() -> ]}, {import_on_a_booting_node, [], [ import_on_boot_case1 + ]}, + + {roundtrip, [], [ + export_import_round_trip_case1 ]} ]. @@ -61,23 +66,23 @@ groups() -> init_per_suite(Config) -> rabbit_ct_helpers:log_environment(), inets:start(), + Config. +end_per_suite(Config) -> + Config. + +init_per_group(_, Config) -> Config1 = rabbit_ct_helpers:set_config(Config, [ {rmq_nodename_suffix, ?MODULE} ]), rabbit_ct_helpers:run_setup_steps(Config1, rabbit_ct_broker_helpers:setup_steps() ++ rabbit_ct_client_helpers:setup_steps()). -end_per_suite(Config) -> + +end_per_group(_, Config) -> rabbit_ct_helpers:run_teardown_steps(Config, rabbit_ct_client_helpers:teardown_steps() ++ rabbit_ct_broker_helpers:teardown_steps()). -init_per_group(_, Config) -> - Config. - -end_per_group(_, Config) -> - Config. - init_per_testcase(import_on_boot_case1 = Testcase, Config) -> CasePath = filename:join(?config(data_dir, Config), "case5.json"), Config1 = rabbit_ct_helpers:set_config(Config, [ @@ -126,6 +131,12 @@ import_case5(Config) -> import_case11(Config) -> import_file_case(Config, "case11"). import_case12(Config) -> import_invalid_file_case(Config, "failing_case12"). +export_import_round_trip_case1(Config) -> + %% case 6 has runtime parameters that do not depend on any plugins + import_file_case(Config, "case6"), + Defs = export(Config), + import_raw(Config, rabbit_json:encode(Defs)). + import_on_boot_case1(Config) -> %% see case5.json VHost = <<"vhost2">>, @@ -163,6 +174,20 @@ import_from_directory_case_expect(Config, CaseName, Expected) -> [CasePath, Expected]), ok. +import_raw(Config, Body) -> + case rabbit_ct_broker_helpers:rpc(Config, 0, rabbit_definitions, import_raw, [Body]) of + ok -> ok; + {error, E} -> + ct:pal("Import of definitions ~p failed: ~p~n", [Body, E]), + ct:fail({failure, Body, E}) + end. + +export(Config) -> + rabbit_ct_broker_helpers:rpc(Config, 0, ?MODULE, run_export, []). + +run_export() -> + rabbit_definitions:all_definitions(). + run_directory_import_case(Path, Expected) -> ct:pal("Will load definitions from files under ~p~n", [Path]), Result = rabbit_definitions:maybe_load_definitions_from(true, Path), |
