spring-batch icon indicating copy to clipboard operation
spring-batch copied to clipboard

Reintroduce in-memory repositories

Open marschall opened this issue 3 years ago • 0 comments
trafficstars

Expected Behavior

It should be possible to run Spring Batch integration tests without having to set up a database or if one is present without the tests committing to the database.

Current Behavior

The map based repositories were deprecated in v4 and removed in v5. However even they had the issue that they would commit to the database due to a transactional advice. This necessitates things like JobRepositoryTestUtils#removeJobExecutions.

Using an embedded database like H2, HSQL, etc does not solve the issue. The repositories still commit. In addition this only works when no other JDBC access is used. Otherwise multiple DataSource and DataSourceTransactionManager have to be juggled or the "real" database has to be used.

Context

I have implemented two custom JobRepository and JobExplorer implementations in marschall/spring-batch-inmemory.

  • Null implementations that do not save any data and therefore do not require any cleanup. This is ideal for integration tests where you don't want to have to clean up previous job executions. Additionally a NullDataSource is provided so that JobRepositoryTestUtils can be used.
  • In memory implementations that save all data in memory. These are intended as replacements for the deprecated the map based DAO implementations (MapJobInstanceDao, MapJobExecutionDao, MapStepExecutionDao and MapExecutionContextDao). These require clean up of previous job executions, the annotation @ClearJobRepository is provided to help with this. These avoid the performance problems of the map implementations by using copy constructors instead of Java serialization, this does not work if mutable objects are stored in contexts.

I would be willing to work on a PR.

See #4016, #3834

marschall avatar Jan 28 '22 12:01 marschall