diff options
| author | Matthew Sackman <matthew@rabbitmq.com> | 2010-08-09 11:31:01 +0100 |
|---|---|---|
| committer | Matthew Sackman <matthew@rabbitmq.com> | 2010-08-09 11:31:01 +0100 |
| commit | 601fccb19f8ca8b16a8acdaa3fd9ec384054d117 (patch) | |
| tree | 3c3bce476fb300fcc807bf0af93930e95791b430 /src | |
| parent | b73f0e725a82b72b6d8d7bc17b764c46037a8a90 (diff) | |
| parent | 5c06e619889bc1708a6f182a1403d40099f1a8e8 (diff) | |
| download | rabbitmq-server-git-601fccb19f8ca8b16a8acdaa3fd9ec384054d117.tar.gz | |
Merging default into bug 15930
Diffstat (limited to 'src')
| -rw-r--r-- | src/rabbit_basic.erl | 5 | ||||
| -rw-r--r-- | src/rabbit_binary_generator.erl | 15 | ||||
| -rw-r--r-- | src/rabbit_binary_parser.erl | 16 | ||||
| -rw-r--r-- | src/rabbit_channel.erl | 3 | ||||
| -rw-r--r-- | src/rabbit_plugin_activator.erl | 7 | ||||
| -rw-r--r-- | src/rabbit_tests.erl | 46 |
6 files changed, 73 insertions, 19 deletions
diff --git a/src/rabbit_basic.erl b/src/rabbit_basic.erl index c1445a0c69..d62fc07cb0 100644 --- a/src/rabbit_basic.erl +++ b/src/rabbit_basic.erl @@ -110,9 +110,8 @@ from_content(Content) -> #content{class_id = ClassId, properties = Props, payload_fragments_rev = FragmentsRev} = - %% basic.publish hasn't changed so we can just hard-code amqp_0_9_1 - rabbit_binary_parser:ensure_content_decoded(Content, - rabbit_framing_amqp_0_9_1), + rabbit_binary_parser:ensure_content_decoded(Content), + %% basic.publish hasn't changed so we can just hard-code amqp_0_9_1 {ClassId, _MethodId} = rabbit_framing_amqp_0_9_1:method_id('basic.publish'), {Props, list_to_binary(lists:reverse(FragmentsRev))}. diff --git a/src/rabbit_binary_generator.erl b/src/rabbit_binary_generator.erl index f0ec618044..056ab1b574 100644 --- a/src/rabbit_binary_generator.erl +++ b/src/rabbit_binary_generator.erl @@ -279,11 +279,20 @@ check_empty_content_body_frame_size() -> ComputedSize, ?EMPTY_CONTENT_BODY_FRAME_SIZE}) end. -ensure_content_encoded(Content = #content{properties_bin = PropsBin, +ensure_content_encoded(Content = #content{properties_bin = PropBin, protocol = Protocol}, Protocol) - when PropsBin =/= 'none' -> + when PropBin =/= none -> Content; -ensure_content_encoded(Content = #content{properties = Props}, Protocol) -> +ensure_content_encoded(Content = #content{properties = none, + properties_bin = PropBin, + protocol = Protocol}, Protocol1) + when PropBin =/= none -> + Props = Protocol:decode_properties(Content#content.class_id, PropBin), + Content#content{properties = Props, + properties_bin = Protocol1:encode_properties(Props), + protocol = Protocol1}; +ensure_content_encoded(Content = #content{properties = Props}, Protocol) + when Props =/= none -> Content#content{properties_bin = Protocol:encode_properties(Props), protocol = Protocol}. diff --git a/src/rabbit_binary_parser.erl b/src/rabbit_binary_parser.erl index 1d0a62afe8..ebf063f031 100644 --- a/src/rabbit_binary_parser.erl +++ b/src/rabbit_binary_parser.erl @@ -34,7 +34,7 @@ -include("rabbit.hrl"). -export([parse_table/1, parse_properties/2]). --export([ensure_content_decoded/2, clear_decoded_content/1]). +-export([ensure_content_decoded/1, clear_decoded_content/1]). -import(lists). @@ -45,9 +45,8 @@ -spec(parse_table/1 :: (binary()) -> rabbit_framing:amqp_table()). -spec(parse_properties/2 :: ([rabbit_framing:amqp_property_type()], binary()) -> [any()]). --spec(ensure_content_decoded/2 :: - (rabbit_types:content(), rabbit_types:protocol()) - -> rabbit_types:decoded_content()). +-spec(ensure_content_decoded/1 :: + (rabbit_types:content()) -> rabbit_types:decoded_content()). -spec(clear_decoded_content/1 :: (rabbit_types:content()) -> rabbit_types:undecoded_content()). @@ -163,11 +162,12 @@ parse_property(bit, Rest) -> parse_property(table, <<Len:32/unsigned, Table:Len/binary, Rest/binary>>) -> {parse_table(Table), Rest}. -ensure_content_decoded(Content = #content{properties = Props}, _Protocol) - when Props =/= 'none' -> +ensure_content_decoded(Content = #content{properties = Props}) + when Props =/= none -> Content; -ensure_content_decoded(Content = #content{properties_bin = PropBin}, Protocol) - when is_binary(PropBin) -> +ensure_content_decoded(Content = #content{properties_bin = PropBin, + protocol = Protocol}) + when PropBin =/= none -> Content#content{properties = Protocol:decode_properties( Content#content.class_id, PropBin)}. diff --git a/src/rabbit_channel.erl b/src/rabbit_channel.erl index 8eb148c192..f8d4f3076f 100644 --- a/src/rabbit_channel.erl +++ b/src/rabbit_channel.erl @@ -426,8 +426,7 @@ handle_method(#'basic.publish'{exchange = ExchangeNameBin, Exchange = rabbit_exchange:lookup_or_die(ExchangeName), %% We decode the content's properties here because we're almost %% certain to want to look at delivery-mode and priority. - DecodedContent = rabbit_binary_parser:ensure_content_decoded( - Content, rabbit_framing_amqp_0_9_1), + DecodedContent = rabbit_binary_parser:ensure_content_decoded(Content), IsPersistent = is_message_persistent(DecodedContent), Message = #basic_message{exchange_name = ExchangeName, routing_key = RoutingKey, diff --git a/src/rabbit_plugin_activator.erl b/src/rabbit_plugin_activator.erl index ef3c5cc250..35b75a23a9 100644 --- a/src/rabbit_plugin_activator.erl +++ b/src/rabbit_plugin_activator.erl @@ -66,9 +66,8 @@ start() -> unpack_ez_plugins(PluginDir, UnpackedPluginDir), %% Build a list of required apps based on the fixed set, and any plugins - RequiredApps = ?BaseApps ++ - find_plugins(PluginDir) ++ - find_plugins(UnpackedPluginDir), + PluginApps = find_plugins(PluginDir) ++ find_plugins(UnpackedPluginDir), + RequiredApps = ?BaseApps ++ PluginApps, %% Build the entire set of dependencies - this will load the %% applications along the way @@ -132,6 +131,8 @@ start() -> ok -> ok; error -> error("failed to compile boot script file ~s", [ScriptFile]) end, + io:format("~n~w plugins activated.~n~n", [length(PluginApps)]), + [io:format("* ~w~n", [App]) || App <- PluginApps], halt(), ok. diff --git a/src/rabbit_tests.erl b/src/rabbit_tests.erl index 4b59844f76..55897679f8 100644 --- a/src/rabbit_tests.erl +++ b/src/rabbit_tests.erl @@ -63,6 +63,7 @@ all_tests() -> passed = test_supervisor_delayed_restart(), passed = test_parsing(), passed = test_content_framing(), + passed = test_content_transcoding(), passed = test_topic_matching(), passed = test_log_management(), passed = test_app_management(), @@ -536,6 +537,51 @@ test_content_framing() -> passed = test_content_framing(11, <<"More than one frame">>), passed. +test_content_transcoding() -> + %% there are no guarantees provided by 'clear' - it's just a hint + ClearDecoded = fun rabbit_binary_parser:clear_decoded_content/1, + ClearEncoded = fun rabbit_binary_generator:clear_encoded_content/1, + EnsureDecoded = + fun (C0) -> + C1 = rabbit_binary_parser:ensure_content_decoded(C0), + true = C1#content.properties =/= none, + C1 + end, + EnsureEncoded = + fun (Protocol) -> + fun (C0) -> + C1 = rabbit_binary_generator:ensure_content_encoded( + C0, Protocol), + true = C1#content.properties_bin =/= none, + C1 + end + end, + %% Beyond the assertions in Ensure*, the only testable guarantee + %% is that the operations should never fail. + %% + %% If we were using quickcheck we'd simply stuff all the above + %% into a generator for sequences of operations. In the absence of + %% quickcheck we pick particularly interesting sequences that: + %% + %% - execute every op twice since they are idempotent + %% - invoke clear_decoded, clear_encoded, decode and transcode + %% with one or both of decoded and encoded content present + [begin + sequence_with_content([Op]), + sequence_with_content([ClearEncoded, Op]), + sequence_with_content([ClearDecoded, Op]) + end || Op <- [ClearDecoded, ClearEncoded, EnsureDecoded, + EnsureEncoded(rabbit_framing_amqp_0_9_1), + EnsureEncoded(rabbit_framing_amqp_0_8)]], + passed. + +sequence_with_content(Sequence) -> + lists:foldl(fun (F, V) -> F(F(V)) end, + rabbit_binary_generator:ensure_content_encoded( + rabbit_basic:build_content(#'P_basic'{}, <<>>), + rabbit_framing_amqp_0_9_1), + Sequence). + test_topic_match(P, R) -> test_topic_match(P, R, true). |
