Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Transactional testing with JMS #32499

Open
djechelon opened this issue Mar 20, 2024 · 1 comment
Open

Transactional testing with JMS #32499

djechelon opened this issue Mar 20, 2024 · 1 comment
Labels
in: messaging Issues in messaging modules (jms, messaging) in: test Issues in the test module type: enhancement A general enhancement

Comments

@djechelon
Copy link
Contributor

I am working on a project heavily based on Spring Integration and JMS. One of the greatest deals with MockMvc is that you can wrap your data-driven test in a @Transactional annotation and have Spring revert your data back to the original state in order not to pollute data and fail subsequent tests.

Example

@SpringBootTest
@Transactional
@Sql
class MyDataDrivenTest {

    void doTest(){
        mockMvc.perform(...)
    }
}

The above code will populate data using an SQL file, the programmer can add as many JDBC/JPA changes before and during the test, and the Transaction will be rolled back at the end restoring the database.

The above cannot be applied in a JMS project. I'll provide a POC on demand, but it's pretty evident that with the following setup the JmsTemplate won't work as desired:

  • Application declares an IntegrationFlow using a messageDrivenChannelAdapter
  • Connection factory can be provided by Artemis Embedded in JUnit tests
  • Use JmsTemplate the way you use MockMvc

(see also)

If you start a transaction in the test, it will be pending during the execution of JMS interactions and since they occur in another thread, data written in the "main" transaction is not visible by the spawned transaction.

The idea is to discuss the opportunity to use a MockJms facility, inspired by MockMvc, that allows invoking JMS listeners (annotated or DSL-configured) from the same thread for testing purposes, in order to retain every desirable property of MockMvc. In my own case, I require transactionality.

Currently, I am adding a number of boilerplate components to handle cleanup, up to the point that I have to manually delete from the database the records I expect to have written after the test. This can be painful just up to the point you want to identify and list all records to remove (when you can't just truncate the related table).

I wanted to ask if this will be possible in the future, and if it is possible to start discussing it

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Mar 20, 2024
@jhoeller
Copy link
Contributor

On a related note, we are planning a broader revision of spring-jms in 6.2: see #32501, #26840, #22999.

While we may be able to address testability as well, I am not sure about how this will turn out. A fully-fleshed MockJms sounds rather tough to swallow but addressing transactional testing with JMS can certainly be a goal, one way or the other. I'll rephrase the scope of this issue accordingly.

@jhoeller jhoeller changed the title Feature request: MockJms like MockMvc Transactional testing with JMS Mar 20, 2024
@jhoeller jhoeller added in: messaging Issues in messaging modules (jms, messaging) type: enhancement A general enhancement and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Mar 20, 2024
@jhoeller jhoeller added this to the 6.2.x milestone Mar 20, 2024
@sbrannen sbrannen added the in: test Issues in the test module label Mar 20, 2024
@jhoeller jhoeller modified the milestones: 6.2.x, General Backlog Sep 26, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: messaging Issues in messaging modules (jms, messaging) in: test Issues in the test module type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

4 participants