-
Notifications
You must be signed in to change notification settings - Fork 1.6k
java.lang.IllegalStateException: Only one 'RetryTopicConfigurationSupport' is allowed when Spring context is reloaded #2477
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
We handle this in the framework tests by subclassing this class in all retry topic test classes: Lines 29 to 41 in 2ad36bd
|
If you have a better suggestion, please submit a PR. |
Are you suggesting every consumer of this library should do the same? I would suggest we remove this field entirely since static state causes issues with testing. Do you know the reason for having this field/check in the first place? |
Also to be clear this is not specific to unit testing. This can happen any time you restart the Spring context, which could happen on a live production app as well. |
Good point. We should change it to ensure there is only one instance in each application context. |
Resolves spring-projects#2477 Previously, a static field was used to detect/prevent multiple instances of `RetryTopicConfigurationSupport`. This causes problems in test suites or when an application context might be destroyed and re-created in the same class loader. Instead, detect and warn when multiple instances are found in an application context. **cherry-pick to 2.9.x**
Resolves spring-projects#2477 Previously, a static field was used to detect/prevent multiple instances of `RetryTopicConfigurationSupport`. This causes problems in test suites or when an application context might be destroyed and re-created in the same class loader. Instead, detect and warn when multiple instances are found in an application context. **cherry-pick to 2.9.x**
Resolves #2477 Previously, a static field was used to detect/prevent multiple instances of `RetryTopicConfigurationSupport`. This causes problems in test suites or when an application context might be destroyed and re-created in the same class loader. Instead, detect and warn when multiple instances are found in an application context. **cherry-pick to 2.9.x** * Fix test.
Resolves #2477 Previously, a static field was used to detect/prevent multiple instances of `RetryTopicConfigurationSupport`. This causes problems in test suites or when an application context might be destroyed and re-created in the same class loader. Instead, detect and warn when multiple instances are found in an application context. **cherry-pick to 2.9.x** * Fix test. # Conflicts: # spring-kafka/src/test/java/org/springframework/kafka/retrytopic/RetryTopicIntegrationTests.java
In what version(s) of Spring for Apache Kafka are you seeing this issue?
Since 2.9
Describe the bug
RetryTopicConfigurationSupport
has a static variable to keep track of whether or not the class has been instantiated more than once. This breaks unit tests whenever the Spring context is refreshed.To Reproduce
Setup a Kafka listener with a retry topic configuration. Then create a unit test where the Spring context is refreshed. I forced it by using the DirtiesContext annotation, but this can occur anytime the context is reloaded.
Expected behavior
You should be able to reset the Spring context without any unexpected side effects.
Sample
https://github.com/jrenzullo/spring-kafka-test-bug
The text was updated successfully, but these errors were encountered: