문서의 선택한 두 판 사이의 차이를 보여줍니다.
|
springframework:batch:batch_test [2021/04/09 17:32] kwon37xi 만듦 |
springframework:batch:batch_test [2021/04/09 18:00] (현재) kwon37xi |
||
|---|---|---|---|
| 줄 2: | 줄 2: | ||
| * [[springframework: | * [[springframework: | ||
| + | |||
| + | |||
| + | ===== JobReporitoryTestUtils ===== | ||
| + | * 원칙적으로 Job 관련 테스트 실행 후에는 '' | ||
| + | <code java> | ||
| + | @Autowired | ||
| + | private JobRepositoryTestUtils jobRepositoryTestUtils; | ||
| + | |||
| + | @AfterEach | ||
| + | void tearDown() { | ||
| + | jobRepositoryTestUtils.removeJobExecutions(); | ||
| + | } | ||
| + | </ | ||
| + | * 헌데, 이게 작동하지 않는 경우가 있는데 그것은, JDBC Connection Pool 에서 '' | ||
| + | * 이 경우 저 메소드가 삭제하는 테이블들이 제대로 삭제가 안되고 롤백이 돼 버리는데, | ||
| + | * 1차 시도 : '' | ||
| + | * 2차 시도 : '' | ||
| + | * Spring Batch 용 Datasource 와 애플리케이션 데이터소스를 분리하고 애플리케이션 데이터소스는 '' | ||
| + | * 3차 시도 : 강제 트랜잭션주기. 성공 | ||
| + | |||
| + | <code java> | ||
| + | @Autowired | ||
| + | private JobRepositoryTestUtils jobRepositoryTestUtils; | ||
| + | |||
| + | @Autowired | ||
| + | private PlatformTransactionManager platformTransactionManager; | ||
| + | |||
| + | /** | ||
| + | * {@link JobRepositoryTestUtils# | ||
| + | * 이 메소드 내부의 update 쿼리가 rollback 되는 현상이 발생해서 강제로 트랜잭션을 설정해준다. | ||
| + | */ | ||
| + | @AfterEach | ||
| + | void tearDown() { | ||
| + | TransactionTemplate transactionTemplate = new TransactionTemplate(platformTransactionManager); | ||
| + | transactionTemplate.afterPropertiesSet(); | ||
| + | transactionTemplate.execute(status -> { | ||
| + | jobRepositoryTestUtils.removeJobExecutions(); | ||
| + | return null; | ||
| + | }); | ||
| + | } | ||
| + | </ | ||
| ===== 참조 ===== | ===== 참조 ===== | ||