You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Bug description
When using @SpringBatchTest, the BatchTestContextCustomizer is added to each test's MergedContextConfiguration. BatchTestContextCustomizer does not implement hashCode()/equals(), causing each new instance to have a different hash code. This leads to unnecessary cache misses and context creations, slowing down test execution.
The ContextCustomizer Javadoc clearly demands implementing these methods.
Environment
Spring Batch 4.3.2
Steps to reproduce
Create multiple test classes with identical context configuration, annotate them with @SpringBatchTest.
A new application context will be created for each test class.
Expected behavior BatchTestContextCustomizer should return stable hash codes to not break context caching.
The first test succeeds (ok), the second test fails (nok).
The project contains two test classes, both extending BaseTest and thus its configuration. BaseTest is annotated with @SpringBatchTest and @SpringBootTest.
The application context is injected, and @BeforeEach records its start date in a static set.
The test method asserts that the set of context start dates contains only one value.
Removing @SpringBatchTest fixes the test, because the same application context instance is injected into both tests.
Possible Fix
Return stable hash codes in the same way for example ExcludeFilterContextCustomizer does it:
Thank you for reporting this issue and for providing a minimal example! Indeed, BatchTestContextCustomizer must implement equals()/hashCode() as requested by the ContextCustomizer contract.
Bug description
When using
@SpringBatchTest
, theBatchTestContextCustomizer
is added to each test'sMergedContextConfiguration
.BatchTestContextCustomizer
does not implementhashCode()/equals()
, causing each new instance to have a different hash code. This leads to unnecessary cache misses and context creations, slowing down test execution.The
ContextCustomizer
Javadoc clearly demands implementing these methods.Environment
Spring Batch 4.3.2
Steps to reproduce
Create multiple test classes with identical context configuration, annotate them with
@SpringBatchTest
.A new application context will be created for each test class.
Expected behavior
BatchTestContextCustomizer
should return stable hash codes to not break context caching.Minimal Complete Reproducible example
demo.zip
./mvnw test
The project contains two test classes, both extending
BaseTest
and thus its configuration.BaseTest
is annotated with@SpringBatchTest
and@SpringBootTest
.The application context is injected, and
@BeforeEach
records its start date in a static set.The test method asserts that the set of context start dates contains only one value.
Removing
@SpringBatchTest
fixes the test, because the same application context instance is injected into both tests.Possible Fix
Return stable hash codes in the same way for example
ExcludeFilterContextCustomizer
does it:The text was updated successfully, but these errors were encountered: