question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Embedded / Integration Testing Support

See original GitHub issue

This is more of a question, which may lead to a request. It is quite difficult to do JMS testing with IBM MQ. I find this spring boot dependency extremely useful, but during testing the application chooses to connect to IBM MQ instead of a broker with embedded support like AMQ.

Looking for a way to test JMS classes, either embedded or integration testing against, say, a docker container spun up when the test is triggered.

  • Java version : 1.8

  • MQ JMS Spring Boot Starter Version :

<dependency>
    <groupId>com.ibm.mq</groupId>
    <artifactId>mq-jms-spring-boot-starter</artifactId>
    <version>2.1.1</version>
</dependency>
  • Exception :
org.springframework.jms.IllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'QM1' with connection mode 'Client' and host name 'localhost(1414)'.; nested exception is com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'QM1' with connection mode 'Client' and host name 'localhost(1414)'.
Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2538' ('MQRC_HOST_NOT_AVAILABLE').
	...
Caused by: com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ0018: Failed to connect to queue manager 'QM1' with connection mode 'Client' and host name 'localhost(1414)'.
Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.
	...
Caused by: com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode '2' ('MQCC_FAILED') reason '2538' ('MQRC_HOST_NOT_AVAILABLE').
	...
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2538;AMQ9204: Connection to host 'localhost(1414)' rejected. [1=com.ibm.mq.jmqi.JmqiException[CC=2;RC=2538;AMQ9213: A communications error for 'TCP' occurred. [1=java.net.ConnectException[Connection refused (Connection refused)],3=connnectUsingLocalAddress,4=TCP,5=Socket.connect]],3=localhost(1414),5=RemoteTCPConnection.connnectUsingLocalAddress]
	...
Caused by: com.ibm.mq.jmqi.JmqiException: CC=2;RC=2538;AMQ9213: A communications error for 'TCP' occurred. [1=java.net.ConnectException[Connection refused (Connection refused)],3=connnectUsingLocalAddress,4=TCP,5=Socket.connect]
	...
Caused by: java.net.ConnectException: Connection refused (Connection refused)
	...

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Comments:9 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
Manfred73commented, Feb 8, 2022

Update:

Looking at the source code I found there is an MQAutoConfiguration class which tries to configure MQ on startup of the application.

Stackoverflow mentions you can add spring.autoconfigure.exclude=com.ibm.mq.spring.boot.MQAutoConfiguration to your application.properties or yaml, but this only worked for me if I added it to application.yaml and not if I added it to application-test.yaml. That’s not desireable, since I do want to use mq when the application is run normally, only not for integration tests with SpringBootTest.

A better solution I found at baeldung was to add the following annotation to the SpringBootTest class, excluding the MQAutoConfiguration.class: @EnableAutoConfiguration(exclude=MQAutoConfiguration.class)

This way Spring doesn’t configure MQ at startup and you can just include spring active mq depencency with scope test. Your SpringBootTest will than work again using active mq instead of mq.

1reaction
vmhaskar1commented, Mar 27, 2020

If I try using “MQ Docker container for developers”, however I am getting exactly same issue as that mentioned by james-r-smith on April 9th 2019 in my spring boot code. Any idea how this issues was solved/closed ? I am stuck totally…

I am running MQ on docker within Ububtu in VMbox. Here is the docker command I used -

sudo docker run --env LICENSE=accept --env MQ_QMGR_NAME=QM1 --publish 1414:1414 --publish 9443:9443 --detach ibmcom/mq

I get below error, when I try to put message ->

vinay@vinay-VirtualBox:~$ sudo docker run -p 8084:8084 mqspring

. ____ _ __ _ _ /\ / __ _ () __ __ _ \ \ \
( ( )_
_ | '_ | '| | ’ / ` | \ \ \
\/ )| |)| | | | | || (| | ) ) ) ) ’ |
| .__|| ||| |_, | / / / / =========||==============|/=//// :: Spring Boot :: (v2.2.6.RELEASE)

2020-03-27 15:29:22.429 INFO 1 — [ main] c.example.mqspring.MqspringApplication : Starting MqspringApplication v0.0.1-SNAPSHOT on 59c59e3c5ce5 with PID 1 (/mqspring-0.0.1-SNAPSHOT.jar started by root in /) 2020-03-27 15:29:22.434 INFO 1 — [ main] c.example.mqspring.MqspringApplication : No active profile set, falling back to default profiles: default 2020-03-27 15:29:26.366 INFO 1 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat initialized with port(s): 8084 (http) 2020-03-27 15:29:26.437 INFO 1 — [ main] o.apache.catalina.core.StandardService : Starting service [Tomcat] 2020-03-27 15:29:26.438 INFO 1 — [ main] org.apache.catalina.core.StandardEngine : Starting Servlet engine: [Apache Tomcat/9.0.33] 2020-03-27 15:29:26.703 INFO 1 — [ main] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring embedded WebApplicationContext 2020-03-27 15:29:26.704 INFO 1 — [ main] o.s.web.context.ContextLoader : Root WebApplicationContext: initialization completed in 4024 ms 2020-03-27 15:29:28.834 INFO 1 — [ main] o.s.s.concurrent.ThreadPoolTaskExecutor : Initializing ExecutorService ‘applicationTaskExecutor’ 2020-03-27 15:29:29.523 INFO 1 — [ main] o.s.b.w.embedded.tomcat.TomcatWebServer : Tomcat started on port(s): 8084 (http) with context path ‘’ 2020-03-27 15:29:29.532 INFO 1 — [ main] c.example.mqspring.MqspringApplication : Started MqspringApplication in 8.263 seconds (JVM running for 9.95) 2020-03-27 15:30:16.388 INFO 1 — [nio-8084-exec-1] o.a.c.c.C.[Tomcat].[localhost].[/] : Initializing Spring DispatcherServlet ‘dispatcherServlet’ 2020-03-27 15:30:16.388 INFO 1 — [nio-8084-exec-1] o.s.web.servlet.DispatcherServlet : Initializing Servlet ‘dispatcherServlet’ 2020-03-27 15:30:16.415 INFO 1 — [nio-8084-exec-1] o.s.web.servlet.DispatcherServlet : Completed initialization in 27 ms org.springframework.jms.IllegalStateException: JMSWMQ0018: Failed to connect to queue manager ‘QM1’ with connection mode ‘Client’ and host name ‘localhost(1414)’.; nested exception is com.ibm.msg.client.jms.DetailedIllegalStateException: JMSWMQ0018: Failed to connect to queue manager ‘QM1’ with connection mode ‘Client’ and host name ‘localhost(1414)’. Check the queue manager is started and if running in client mode, check there is a listener running. Please see the linked exception for more information.; nested exception is com.ibm.mq.MQException: JMSCMQ0001: IBM MQ call failed with compcode ‘2’ (‘MQCC_FAILED’) reason ‘2538’ (‘MQRC_HOST_NOT_AVAILABLE’). at org.springframework.jms.support.JmsUtils.convertJmsAccessException(JmsUtils.java:274) at org.springframework.jms.support.JmsAccessor.convertJmsAccessException(JmsAccessor.java:185) at org.springframework.jms.core.JmsTemplate.execute(JmsTemplate.java:507)

Having simple Spring Boot application - with below POM ->

<?xml version="1.0" encoding="UTF-8"?>

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 https://maven.apache.org/xsd/maven-4.0.0.xsd"> <modelVersion>4.0.0</modelVersion> <parent> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-parent</artifactId> <version>2.2.6.RELEASE</version> <relativePath /> </parent> <groupId>com.example</groupId> <artifactId>mqspring</artifactId> <version>0.0.1-SNAPSHOT</version> <name>mqspring</name> <description>Demo project for Spring Boot</description>

<properties>
	<java.version>1.8</java.version>
	<maven-jar-plugin.version>3.1.1</maven-jar-plugin.version>
</properties>

<dependencies>
	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-web</artifactId>
	</dependency>

	<dependency>
		<groupId>org.springframework.boot</groupId>
		<artifactId>spring-boot-starter-test</artifactId>
		<scope>test</scope>
	</dependency>

	<dependency>
		<groupId>com.fasterxml.jackson.core</groupId>
		<artifactId>jackson-databind</artifactId>
	</dependency>
	<dependency>
		<groupId>com.ibm.mq</groupId>
		<artifactId>mq-jms-spring-boot-starter</artifactId>
		<version>2.0.0</version>
	</dependency>

</dependencies>

<build>
	<plugins>
		<plugin>
			<groupId>org.springframework.boot</groupId>
			<artifactId>spring-boot-maven-plugin</artifactId>
		</plugin>
	</plugins>
</build>
</project>
Read more comments on GitHub >

github_iconTop Results From Across the Web

Embedded Software Testing | Embunit
Integration testing follows unit testing. Two or more modules are brought together and their combined functionality is tested. At this level, the challenges...
Read more >
Embedded System Software Unit, System & Integration Testing
Embedded system unit testing is a software development test process that isolates and tests units for compliance with requirements. Other objectives often ...
Read more >
Integration testing for embedded systems: what setup ... - Reddit
How do you guys do integration/acceptance tests of embedded products? Wondering for both Embedded Linux and bare metal/RTOS based products.
Read more >
What is Embedded Testing in Software Testing? - Guru99
Embedded Testing. Embedded Testing is a testing process for checking functional and non-functional attributes of both software and hardware ...
Read more >
Integration Test - Hitex
Thus Hitex tests the interfaces between the functions and modules as well as the time dependency between the different functions. This way you...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found