-
Notifications
You must be signed in to change notification settings - Fork 1.1k
MockIntegrationContext.reset() does not behave as expected #3182
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
Comments
Yeah... Confirmed. This is a bug: we have to stop endpoints and start them again to apply replacement. Of course, a workaround is to |
@hgarus , any thoughts that you can contribute a fix while we are out for President Day today: https://github.com/spring-projects/spring-integration/blob/master/CONTRIBUTING.adoc ? Thanks |
no President's Day for me, but I'll take a stab at a PR. |
I'm afraid just stopping and starting the endpoint, in I currently see two ways around that:
I noticed |
Yes, of course we need some logic over there. And yes, good catch about So, if you are good with all of that don't hesitate to raise a Pull Request and we continue a discussion from the code lines. Thanks |
Fixes spring-projects#3182 The `MockIntegrationContext.resetBeans()` doesn't really restore a state of endpoint beans: the handle/source is applied only after start for that endpoint * Stop endpoints in the `MockIntegrationContext.resetBeans()` is they are running currently * Start them back only if their `autoStartup == true` * Clear only those beans which names are provided for the `resetBeans()` **Cherry-pick to 5.2.x**
* GH-3182: Properly reset bean in the MockIntCtx Fixes #3182 The `MockIntegrationContext.resetBeans()` doesn't really restore a state of endpoint beans: the handle/source is applied only after start for that endpoint * Stop endpoints in the `MockIntegrationContext.resetBeans()` is they are running currently * Start them back only if their `autoStartup == true` * Clear only those beans which names are provided for the `resetBeans()` **Cherry-pick to 5.2.x** * * Ensure that only provided beans are reset
* GH-3182: Properly reset bean in the MockIntCtx Fixes #3182 The `MockIntegrationContext.resetBeans()` doesn't really restore a state of endpoint beans: the handle/source is applied only after start for that endpoint * Stop endpoints in the `MockIntegrationContext.resetBeans()` is they are running currently * Start them back only if their `autoStartup == true` * Clear only those beans which names are provided for the `resetBeans()` **Cherry-pick to 5.2.x** * * Ensure that only provided beans are reset
Affects Version(s): 5.2.3.RELEASE using spring-boot 2.2.4.RELEASE
I am developing an application containing multiple IntegrationFlows passing messages to each other using DirectChannels.
I have created several small tests which are testing a single IntegrationFlow each. I have used MockIntegrationContext.substituteMessageHandlerFor() to capture the message once it is passed to the "output channel" of a flow.
However even though I'm calling MockIntegrationContext.reset() in an @AfterEach method, the substituted MockMessageHandlers seem to stick around until the ApplicationContext is torn down.
I have created a minimal gist demonstrating the behavior: https://gist.github.com/hgarus/0ec9714f1d381bd8404c08ddc88f55e3
The assertEquals in line 80 fails because the ArgumentCaptor receives the second message. Even though I called
reset()
beforehand.I did some debugging and it seems the substitution only works, when the IntegrationConsumer is stopped before the replacement MessageHandler is assigned to the it - which is done in
substituteMessageHandlerFor()
(with the defaultautoStartup = true
), but not inreset()
.The text was updated successfully, but these errors were encountered: