|
32 | 32 | import org.springframework.batch.core.job.JobExecution; |
33 | 33 | import org.springframework.batch.core.job.JobExecutionException; |
34 | 34 | import org.springframework.batch.core.job.JobInstance; |
| 35 | +import org.springframework.batch.core.job.UnexpectedJobExecutionException; |
35 | 36 | import org.springframework.batch.core.job.parameters.JobParameters; |
36 | 37 | import org.springframework.batch.core.job.parameters.JobParametersIncrementer; |
37 | 38 | import org.springframework.batch.core.step.Step; |
|
69 | 70 | * @author Will Schipp |
70 | 71 | * @author Mahmoud Ben Hassine |
71 | 72 | * @author Jinwoo Bae |
72 | | - * |
| 73 | + * @author Yejeong Ham |
73 | 74 | */ |
74 | 75 | @SuppressWarnings("removal") |
75 | 76 | class TaskExecutorJobOperatorTests { |
@@ -427,6 +428,54 @@ void testAbortNonStopping() { |
427 | 428 | assertThrows(JobExecutionAlreadyRunningException.class, () -> jobOperator.abandon(123L)); |
428 | 429 | } |
429 | 430 |
|
| 431 | + @Test |
| 432 | + void testRecover() { |
| 433 | + JobInstance jobInstance = new JobInstance(123L, job.getName()); |
| 434 | + JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters); |
| 435 | + jobExecution.setStatus(BatchStatus.STARTED); |
| 436 | + jobExecution.createStepExecution("step1").setStatus(BatchStatus.STARTED); |
| 437 | + when(jobRepository.getJobExecution(111L)).thenReturn(jobExecution); |
| 438 | + when(jobRepository.getLastJobExecution(jobInstance)).thenReturn(jobExecution); |
| 439 | + JobExecution recover = jobOperator.recover(jobExecution); |
| 440 | + assertEquals(BatchStatus.FAILED, recover.getStatus()); |
| 441 | + assertTrue(recover.getExecutionContext().containsKey("recovered")); |
| 442 | + } |
| 443 | + |
| 444 | + @Test |
| 445 | + void testRecoverStepStopping() { |
| 446 | + JobInstance jobInstance = new JobInstance(123L, job.getName()); |
| 447 | + JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters); |
| 448 | + jobExecution.setStatus(BatchStatus.STARTED); |
| 449 | + jobExecution.createStepExecution("step1").setStatus(BatchStatus.STOPPING); |
| 450 | + when(jobRepository.getJobExecution(111L)).thenReturn(jobExecution); |
| 451 | + when(jobRepository.getLastJobExecution(jobInstance)).thenReturn(jobExecution); |
| 452 | + JobExecution recover = jobOperator.recover(jobExecution); |
| 453 | + assertEquals(BatchStatus.FAILED, recover.getStatus()); |
| 454 | + assertTrue(recover.getExecutionContext().containsKey("recovered")); |
| 455 | + } |
| 456 | + |
| 457 | + @Test |
| 458 | + void testRecoverJobAbandon() { |
| 459 | + jobParameters = new JobParameters(); |
| 460 | + JobInstance jobInstance = new JobInstance(123L, job.getName()); |
| 461 | + JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters); |
| 462 | + jobExecution.setStatus(BatchStatus.ABANDONED); |
| 463 | + when(jobRepository.getJobExecution(111L)).thenReturn(jobExecution); |
| 464 | + when(jobRepository.getLastJobExecution(jobInstance)).thenReturn(jobExecution); |
| 465 | + assertThrows(UnexpectedJobExecutionException.class, () -> jobOperator.recover(jobExecution)); |
| 466 | + } |
| 467 | + |
| 468 | + @Test |
| 469 | + void testRecoverJobCompleted() { |
| 470 | + jobParameters = new JobParameters(); |
| 471 | + JobInstance jobInstance = new JobInstance(123L, job.getName()); |
| 472 | + JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters); |
| 473 | + jobExecution.setStatus(BatchStatus.COMPLETED); |
| 474 | + when(jobRepository.getJobExecution(111L)).thenReturn(jobExecution); |
| 475 | + when(jobRepository.getLastJobExecution(jobInstance)).thenReturn(jobExecution); |
| 476 | + assertThrows(UnexpectedJobExecutionException.class, () -> jobOperator.recover(jobExecution)); |
| 477 | + } |
| 478 | + |
430 | 479 | static class MockJob extends AbstractJob { |
431 | 480 |
|
432 | 481 | private TaskletStep taskletStep; |
|
0 commit comments