My scenario is that batch job should read data from 1 DB (H2) and dump data into another DB (postgres).Hence I have configured multiple datasources
I have written batch job using spring batch 4.2 and Spring boot 2.2.5.RELEASE. Now I need to write testcase for end to end testing.
I have used custom Batch Configurer using ResourcelessTransactionManager to avoid saving of batch table meta data in in-memory and actual database and it's working. However,I am unable to save business data in H2 in-memory database in junit by calling readerRepository.save(randomReader); and same is working if I replace H2 in-memory database with postgres testconatiner in junit.
Sample junit of repository test
@Slf4j
@SpringBootTest
@Import(LiquibaseConfigReader.class)
class ReaderRepositoryTest {
@Autowired
private ReaderRepository readerRepository;
@BeforeEach
void setUp() {
readerRepository.deleteAll();
}
@Test
void shouldFetchAllRecords() {
var randomReader = RandomDataGenerator.randomReader();
assertThat(readerRepository.findAll()).hasSize(0);
readerRepository.save(randomReader);
assertThat(readerRepository.findAll()).hasSize(1);
}
}
I am unable to understand why I am able to save data in postgres test container but not in in-memory H2 database while running Junit Test.
To save batch table meta-data in in-memory map, i tried below solutions and now batch table meta data is not being saved anywhere in DB.However, I started facing spring data jpa issue in junit as mentioned above.
Java Spring Batch using embedded database for metadata and a second database for other data
Spring boot + spring batch without DataSource
Is it because of ResourcelessTransactionManager? If yes, how could I avoid saving batch table metadata in any database including in-memory.
I have scrolled through multiple questions given here but none is able to save business data in h2 database.