Skip to content

Commit 23c02d4

Browse files
MQTT: tests for #12707 #12708 #12710
1 parent d0b1aff commit 23c02d4

File tree

2 files changed

+64
-1
lines changed

2 files changed

+64
-1
lines changed

deps/rabbitmq_mqtt/test/mc_mqtt_SUITE.erl

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,8 @@ groups() ->
3333
mqtt_amqp,
3434
mqtt_amqp_alt,
3535
amqp_mqtt,
36-
is_persistent
36+
is_persistent,
37+
amqpl_to_mqtt_gh_12707
3738
]}
3839
].
3940

@@ -156,6 +157,34 @@ roundtrip_amqpl(_Config) ->
156157
ExpectedUserProperty = lists:keysort(1, UserProperty),
157158
?assertMatch(#{'User-Property' := ExpectedUserProperty}, Props).
158159

160+
amqpl_to_mqtt_gh_12707(_Config) ->
161+
Props = #'P_basic'{content_type = <<"text/plain">>,
162+
content_encoding = <<"gzip">>,
163+
headers = [],
164+
delivery_mode = 1,
165+
priority = 7,
166+
correlation_id = <<"gh_12707-corr">> ,
167+
reply_to = <<"reply-to">>,
168+
expiration = <<"12707">>,
169+
message_id = <<"msg-id">>,
170+
timestamp = 99,
171+
type = <<"45">>,
172+
user_id = <<"gh_12707">>,
173+
app_id = <<"rmq">>
174+
},
175+
Payload = [<<"gh_12707">>],
176+
Content = #content{properties = Props,
177+
payload_fragments_rev = Payload},
178+
Content = #content{properties = Props,
179+
payload_fragments_rev = Payload},
180+
Anns = #{
181+
?ANN_EXCHANGE => <<"amq.topic">>,
182+
?ANN_ROUTING_KEYS => [<<"dummy">>]
183+
},
184+
OriginalMsg = mc:init(mc_amqpl, Content, Anns),
185+
Converted = mc:convert(mc_mqtt, OriginalMsg),
186+
?assertEqual(12707, mc:get_annotation(ttl, Converted)).
187+
159188
%% Non-UTF-8 Correlation Data should also be converted (via AMQP 0.9.1 header x-correlation-id).
160189
roundtrip_amqpl_correlation(_Config) ->
161190
Msg0 = mqtt_msg(),

deps/rabbitmq_mqtt/test/protocol_interop_SUITE.erl

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,7 @@ groups() ->
3535
[{cluster_size_1, [shuffle],
3636
[
3737
mqtt_amqpl_mqtt,
38+
amqpl_mqtt_gh_12707,
3839
mqtt_amqp_mqtt,
3940
amqp_mqtt_amqp,
4041
mqtt_stomp_mqtt,
@@ -169,6 +170,39 @@ mqtt_amqpl_mqtt(Config) ->
169170

170171
ok = emqtt:disconnect(C).
171172

173+
amqpl_mqtt_gh_12707(Config) ->
174+
Q = ClientId = atom_to_binary(?FUNCTION_NAME),
175+
Ch = rabbit_ct_client_helpers:open_channel(Config),
176+
#'queue.declare_ok'{} = amqp_channel:call(Ch, #'queue.declare'{queue = Q, durable = true}),
177+
#'queue.bind_ok'{} = amqp_channel:call(Ch, #'queue.bind'{queue = Q,
178+
exchange = <<"amq.topic">>,
179+
routing_key = <<"gh12707">>}),
180+
C = connect(ClientId, Config),
181+
182+
Topic = <<"gh12707">>,
183+
Payload = <<"gh_12707">>,
184+
185+
{ok, _, [1]} = emqtt:subscribe(C, #{'Subscription-Identifier' => 676}, [{Topic, [{qos, 1}]}]),
186+
amqp_channel:call(Ch, #'basic.publish'{exchange = <<"amq.topic">>,
187+
routing_key = Topic},
188+
#amqp_msg{payload = Payload,
189+
props = #'P_basic'{content_type = <<"application/json">>,
190+
expiration = <<"12707">>,
191+
headers = []}}),
192+
193+
receive {publish,
194+
#{topic := MqttTopic,
195+
payload := MqttPayload}} ->
196+
?assertEqual(MqttTopic, Topic),
197+
?assertEqual(Payload, MqttPayload)
198+
after 1000 ->
199+
ct:fail("did not receive a delivery")
200+
end,
201+
202+
amqp_channel:call(Ch, #'queue.delete'{queue = Q}),
203+
rabbit_ct_client_helpers:close_channel(Ch),
204+
ok = emqtt:disconnect(C).
205+
172206
mqtt_amqp_mqtt(Config) ->
173207
Host = ?config(rmq_hostname, Config),
174208
Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_amqp),

0 commit comments

Comments
 (0)