Skip to content

Commit 2591bb6

Browse files
Add test case for ibm mq
1 parent 5739411 commit 2591bb6

File tree

3 files changed

+239
-1
lines changed

3 files changed

+239
-1
lines changed
Lines changed: 101 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,101 @@
1+
2+
%% This Source Code Form is subject to the terms of the Mozilla Public
3+
%% License, v. 2.0. If a copy of the MPL was not distributed with this
4+
%% file, You can obtain one at https://mozilla.org/MPL/2.0/.
5+
%%
6+
%% Copyright (c) 2007-2024 Broadcom. All Rights Reserved. The term “Broadcom” refers to Broadcom Inc. and/or its subsidiaries. All rights reserved.
7+
%%
8+
9+
-module(ibmmq_ct_helpers).
10+
11+
-include_lib("common_test/include/ct.hrl").
12+
13+
-export([setup_steps/0,
14+
teardown_steps/0,
15+
init_config/1,
16+
capture_logs/1,
17+
start_ibmmq_server/1,
18+
stop_ibmmq_server/1]).
19+
20+
setup_steps() ->
21+
[fun init_config/1,
22+
fun start_ibmmq_server/1
23+
].
24+
25+
teardown_steps() ->
26+
[
27+
fun stop_ibmmq_server/1
28+
].
29+
30+
init_config(Config) ->
31+
NodeConfig = [{tcp_port_amqp, 5672}],
32+
rabbit_ct_helpers:set_config(Config, [ {rmq_nodes, [NodeConfig]},
33+
{rmq_hostname, "localhost"},
34+
{tcp_hostname_amqp, "localhost"},
35+
{sasl, {plain, <<"app">>, <<"passw0rd">>}} ]).
36+
37+
start_ibmmq_server(Config) ->
38+
IBMmqCmd = filename:join([?config(data_dir, Config), "ibmmq_runner"]),
39+
Cmd = [IBMmqCmd, "start"],
40+
ct:log("Running command ~p", [Cmd]),
41+
case rabbit_ct_helpers:exec(Cmd, []) of
42+
{ok, _} -> wait_for_ibmmq_nodes(Config);
43+
Error -> ct:pal("Error: ~tp", [Error]),
44+
{skip, "Failed to start IBM MQ"}
45+
end.
46+
47+
wait_for_ibmmq_nodes(Config) ->
48+
Hostname = ?config(rmq_hostname, Config),
49+
Ports = rabbit_ct_broker_helpers:get_node_configs(Config, tcp_port_amqp),
50+
wait_for_ibmmq_ports(Config, Hostname, Ports).
51+
52+
wait_for_ibmmq_ports(Config, Hostname, [Port | Rest]) ->
53+
ct:log("Waiting for IBM MQ on port ~b", [Port]),
54+
case wait_for_ibmmq_port(Hostname, Port, 60) of
55+
ok ->
56+
ct:log("IBM MQ ready on port ~b", [Port]),
57+
wait_for_ibmmq_ports(Config, Hostname, Rest);
58+
{error, _} ->
59+
Msg = lists:flatten(
60+
io_lib:format(
61+
"Failed to start IBM MQ on port ~b; see IBM MQ logs",
62+
[Port])),
63+
ct:pal(?LOW_IMPORTANCE, Msg, []),
64+
{skip, Msg}
65+
end;
66+
wait_for_ibmmq_ports(Config, _, []) ->
67+
Config.
68+
69+
wait_for_ibmmq_port(_, _, 0) ->
70+
{error, econnrefused};
71+
wait_for_ibmmq_port(Hostname, Port, Retries) ->
72+
case gen_tcp:connect(Hostname, Port, []) of
73+
{ok, Connection} ->
74+
gen_tcp:close(Connection),
75+
ok;
76+
{error, econnrefused} ->
77+
timer:sleep(1000),
78+
wait_for_ibmmq_port(Hostname, Port, Retries - 1);
79+
Error ->
80+
Error
81+
end.
82+
83+
capture_logs(Config) ->
84+
IBMmqCmd = filename:join([?config(data_dir, Config), "ibmmq_runner"]),
85+
Cmd = [IBMmqCmd, "logs", "/tmp/ibmmq.log"],
86+
ct:log("Running command ~p", [Cmd]),
87+
case rabbit_ct_helpers:exec(Cmd, []) of
88+
{ok, _} -> Config;
89+
Error -> ct:pal("Error: ~tp", [Error]),
90+
{skip, "Failed to stop IBM MQ"}
91+
end.
92+
93+
stop_ibmmq_server(Config) ->
94+
IBMmqCmd = filename:join([?config(data_dir, Config), "ibmmq_runner"]),
95+
Cmd = [IBMmqCmd, "stop"],
96+
ct:log("Running command ~p", [Cmd]),
97+
case rabbit_ct_helpers:exec(Cmd, []) of
98+
{ok, _} -> Config;
99+
Error -> ct:pal("Error: ~tp", [Error]),
100+
{skip, "Failed to stop IBM MQ"}
101+
end.

deps/amqp10_client/test/system_SUITE.erl

Lines changed: 34 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ all() ->
2525
{group, rabbitmq_strict},
2626
{group, activemq},
2727
{group, activemq_no_anon},
28+
{group, ibmmq},
2829
{group, mock}
2930
].
3031

@@ -45,6 +46,11 @@ groups() ->
4546
open_connection_plain_sasl_parse_uri,
4647
open_connection_plain_sasl_failure
4748
]},
49+
{ibmmq, [], [
50+
open_close_connection
51+
%basic_roundtrip_with_sender_and_receiver_capabilities
52+
%basic_roundtrip_with_non_binary_capability
53+
]},
4854
{azure, [],
4955
[
5056
basic_roundtrip_service_bus,
@@ -129,6 +135,12 @@ init_per_group(activemq_no_anon, Config0) ->
129135
Config0, {sasl, {plain, <<"user">>, <<"password">>}}),
130136
rabbit_ct_helpers:run_steps(Config,
131137
activemq_ct_helpers:setup_steps("activemq_no_anon.xml"));
138+
init_per_group(ibmmq, Config) ->
139+
ct:log("Found arch: ~p", [erlang:system_info(system_architecture)]),
140+
case string:find(erlang:system_info(system_architecture), "x86_64") of
141+
nomatch -> {skip, no_arm64_docker_image_for_ibmmq};
142+
_ -> rabbit_ct_helpers:run_steps(Config, ibmmq_ct_helpers:setup_steps())
143+
end;
132144
init_per_group(azure, Config) ->
133145
rabbit_ct_helpers:set_config(Config,
134146
[
@@ -150,6 +162,8 @@ end_per_group(activemq, Config) ->
150162
rabbit_ct_helpers:run_steps(Config, activemq_ct_helpers:teardown_steps());
151163
end_per_group(activemq_no_anon, Config) ->
152164
rabbit_ct_helpers:run_steps(Config, activemq_ct_helpers:teardown_steps());
165+
end_per_group(ibmmq, Config) ->
166+
rabbit_ct_helpers:run_steps(Config, ibmmq_ct_helpers:teardown_steps());
153167
end_per_group(_, Config) ->
154168
Config.
155169

@@ -331,11 +345,16 @@ roundtrip_large_messages(Config) ->
331345
ok = roundtrip(OpenConf, Data64Mb).
332346

333347
roundtrip(OpenConf) ->
334-
roundtrip(OpenConf, <<"banana">>).
348+
roundtrip(OpenConf, <<"banana">>, [], []).
335349

336350
roundtrip(OpenConf, Body) ->
351+
roundtrip(OpenConf, Body, [], []).
352+
353+
roundtrip(OpenConf, Body, Args, DoNotAssertMessageProperties) ->
337354
{ok, Connection} = amqp10_client:open_connection(OpenConf),
338355
{ok, Session} = amqp10_client:begin_session(Connection),
356+
% SenderCapabilities = proplists:get_value(sender_capabilities, Args, <<>>),
357+
339358
{ok, Sender} = amqp10_client:attach_sender_link(
340359
Session, <<"banana-sender">>, <<"test1">>, settled, unsettled_state),
341360
await_link(Sender, credited, link_credit_timeout),
@@ -424,6 +443,20 @@ filtered_roundtrip(OpenConf, Body) ->
424443
ok = amqp10_client:close_connection(Connection),
425444
ok.
426445

446+
basic_roundtrip_with_sender_and_receiver_capabilities(Config) ->
447+
application:start(sasl),
448+
Hostname = ?config(rmq_hostname, Config),
449+
Port = rabbit_ct_broker_helpers:get_node_config(Config, 0, tcp_port_amqp),
450+
OpenConf = #{address => Hostname, port => Port, sasl => ?config(sasl, Config)},
451+
roundtrip(OpenConf, [
452+
{body, <<"banana">>},
453+
{destination, <<"DEV.QUEUE.3">>},
454+
{sender_capabilities, <<"queue">>},
455+
{receiver_capabilities, <<"queue">>},
456+
{message_annotations, #{}}
457+
], [creation_time]),
458+
timer:sleep(20000).
459+
427460
%% Assert that implementations respect the difference between transfer-id and delivery-id.
428461
transfer_id_vs_delivery_id(Config) ->
429462
Hostname = ?config(rmq_hostname, Config),
Lines changed: 104 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,104 @@
1+
#!/bin/bash
2+
3+
SCRIPT="$( cd "$( dirname "${BASH_SOURCE[0]}" )" && pwd )"
4+
5+
set -u
6+
7+
IMAGE=pivotalrabbitmq/ibm-mqadvanced-server-dev
8+
IMAGE_TAG=9.4.0.5-amd64
9+
10+
kill_container_if_exist() {
11+
if docker stop $1 &> /dev/null; then
12+
docker rm $1 &> /dev/null
13+
fi
14+
}
15+
16+
ensure_docker_image_exists() {
17+
TAG=`docker images --filter reference=$IMAGE | grep $IMAGE_TAG`
18+
if [ -z ${TAG+x} ]
19+
then
20+
echo "Docker image ${IMAGE}:${IMAGE_TAG} does not exist"
21+
exit 1
22+
else
23+
echo "Docker image ${IMAGE}:${IMAGE_TAG} ready"
24+
fi
25+
}
26+
27+
wait_for_message() {
28+
attemps_left=10
29+
while ! docker logs $1 2>&1 | grep -q "$2";
30+
do
31+
sleep 5
32+
print "Waiting 5sec for $1 to start ($attemps_left attempts left )..."
33+
((attemps_left--))
34+
if [[ "$attemps_left" -lt 1 ]]; then
35+
print "Timed out waiting"
36+
save_container_log $1
37+
exit 1
38+
fi
39+
done
40+
}
41+
declare -i PADDING_LEVEL=0
42+
43+
print() {
44+
tabbing=""
45+
if [[ $PADDING_LEVEL -gt 0 ]]; then
46+
for i in $(seq $PADDING_LEVEL); do
47+
tabbing="$tabbing\t"
48+
done
49+
fi
50+
echo -e "$tabbing$1"
51+
}
52+
53+
invoke_start(){
54+
kill_container_if_exist ibmmq
55+
ensure_docker_image_exists
56+
57+
docker run --name ibmmq \
58+
--env LICENSE=accept \
59+
--env MQ_QMGR_NAME=QM1 \
60+
--env MQ_APP_PASSWORD=passw0rd \
61+
--env MQ_ADMIN_PASSWORD=passw0rd \
62+
--env LICENSE=accept \
63+
--publish 1414:1414 \
64+
--publish 9443:9443 \
65+
--publish 5672:5672 \
66+
--detach \
67+
$IMAGE:$IMAGE_TAG
68+
wait_for_message ibmmq "The listener 'SYSTEM.LISTENER.TCP.1' has started."
69+
wait_for_message ibmmq "Successfully loaded default keystore"
70+
71+
docker exec ibmmq bash -c 'echo "SET CHLAUTH(SYSTEM.DEF.AMQP) TYPE(ADDRESSMAP) ADDRESS(*) MCAUSER(app)" | /opt/mqm/bin/runmqsc QM1'
72+
docker exec ibmmq bash -c 'echo "STOP SERVICE(SYSTEM.AMQP.SERVICE)" | /opt/mqm/bin/runmqsc QM1'
73+
docker exec ibmmq bash -c 'echo "START SERVICE(SYSTEM.AMQP.SERVICE)" | /opt/mqm/bin/runmqsc QM1'
74+
docker exec ibmmq bash -c 'echo "START CHANNEL(SYSTEM.DEF.AMQP)" | /opt/mqm/bin/runmqsc QM1'
75+
wait_for_message ibmmq "The Server 'SYSTEM.AMQP.SERVICE' has started"
76+
sleep 10
77+
print "Waited 10 seconds for container to start"
78+
}
79+
capture_logs() {
80+
print "Capturing ibmmq logs to $1"
81+
docker logs ibmmq > $1
82+
}
83+
invoke_stop(){
84+
kill_container_if_exist ibmmq
85+
}
86+
87+
case "$1" in
88+
version)
89+
echo "IBM MQ ${IMAGE}:${IMAGE_TAG}"
90+
;;
91+
build)
92+
build_docker_image
93+
;;
94+
logs)
95+
capture_logs "$2"
96+
;;
97+
start)
98+
invoke_start
99+
;;
100+
stop)
101+
invoke_stop
102+
exit $?
103+
;;
104+
esac

0 commit comments

Comments
 (0)