|
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; |
36 | 35 | import org.springframework.batch.core.job.parameters.JobParameters; |
37 | 36 | import org.springframework.batch.core.job.parameters.JobParametersIncrementer; |
38 | 37 | import org.springframework.batch.core.step.Step; |
|
56 | 55 | import org.springframework.batch.support.PropertiesConverter; |
57 | 56 | import org.springframework.lang.Nullable; |
58 | 57 |
|
59 | | -import static org.junit.jupiter.api.Assertions.assertEquals; |
60 | | -import static org.junit.jupiter.api.Assertions.assertNotNull; |
61 | | -import static org.junit.jupiter.api.Assertions.assertThrows; |
62 | | -import static org.junit.jupiter.api.Assertions.assertTrue; |
| 58 | +import static org.junit.jupiter.api.Assertions.*; |
63 | 59 | import static org.mockito.ArgumentMatchers.any; |
64 | | -import static org.mockito.Mockito.mock; |
65 | | -import static org.mockito.Mockito.verify; |
66 | | -import static org.mockito.Mockito.when; |
| 60 | +import static org.mockito.Mockito.*; |
67 | 61 |
|
68 | 62 | /** |
69 | 63 | * @author Dave Syer |
@@ -429,49 +423,51 @@ void testAbortNonStopping() { |
429 | 423 | } |
430 | 424 |
|
431 | 425 | @Test |
432 | | - void testRecover() { |
| 426 | + void testRecoverStartedJob() { |
433 | 427 | JobInstance jobInstance = new JobInstance(123L, job.getName()); |
434 | 428 | JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters); |
435 | 429 | jobExecution.setStatus(BatchStatus.STARTED); |
436 | 430 | jobExecution.createStepExecution("step1").setStatus(BatchStatus.STARTED); |
437 | 431 | when(jobRepository.getJobExecution(111L)).thenReturn(jobExecution); |
438 | | - when(jobRepository.getLastJobExecution(jobInstance)).thenReturn(jobExecution); |
439 | 432 | JobExecution recover = jobOperator.recover(jobExecution); |
440 | 433 | assertEquals(BatchStatus.FAILED, recover.getStatus()); |
| 434 | + assertNotNull(recover.getEndTime()); |
441 | 435 | assertTrue(recover.getExecutionContext().containsKey("recovered")); |
442 | 436 | } |
443 | 437 |
|
444 | 438 | @Test |
445 | | - void testRecoverStepStopping() { |
| 439 | + void testRecoverStoppingStep() { |
446 | 440 | JobInstance jobInstance = new JobInstance(123L, job.getName()); |
447 | 441 | JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters); |
448 | 442 | jobExecution.setStatus(BatchStatus.STARTED); |
449 | 443 | jobExecution.createStepExecution("step1").setStatus(BatchStatus.STOPPING); |
450 | 444 | when(jobRepository.getJobExecution(111L)).thenReturn(jobExecution); |
451 | | - when(jobRepository.getLastJobExecution(jobInstance)).thenReturn(jobExecution); |
452 | 445 | JobExecution recover = jobOperator.recover(jobExecution); |
453 | 446 | assertEquals(BatchStatus.FAILED, recover.getStatus()); |
| 447 | + assertNotNull(recover.getEndTime()); |
454 | 448 | assertTrue(recover.getExecutionContext().containsKey("recovered")); |
455 | 449 | } |
456 | 450 |
|
457 | 451 | @Test |
458 | | - void testRecoverJobAbandon() { |
| 452 | + void testRecoverAbandonedJob() { |
459 | 453 | JobInstance jobInstance = new JobInstance(123L, job.getName()); |
460 | 454 | JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters); |
461 | 455 | jobExecution.setStatus(BatchStatus.ABANDONED); |
462 | 456 | when(jobRepository.getJobExecution(111L)).thenReturn(jobExecution); |
463 | | - when(jobRepository.getLastJobExecution(jobInstance)).thenReturn(jobExecution); |
464 | | - assertThrows(UnexpectedJobExecutionException.class, () -> jobOperator.recover(jobExecution)); |
| 457 | + JobExecution recover = jobOperator.recover(jobExecution); |
| 458 | + assertSame(recover, jobExecution); |
| 459 | + verifyNoInteractions(jobRepository); |
465 | 460 | } |
466 | 461 |
|
467 | 462 | @Test |
468 | | - void testRecoverJobCompleted() { |
| 463 | + void testRecoverCompletedJob() { |
469 | 464 | JobInstance jobInstance = new JobInstance(123L, job.getName()); |
470 | 465 | JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters); |
471 | 466 | jobExecution.setStatus(BatchStatus.COMPLETED); |
472 | 467 | when(jobRepository.getJobExecution(111L)).thenReturn(jobExecution); |
473 | | - when(jobRepository.getLastJobExecution(jobInstance)).thenReturn(jobExecution); |
474 | | - assertThrows(UnexpectedJobExecutionException.class, () -> jobOperator.recover(jobExecution)); |
| 468 | + JobExecution recover = jobOperator.recover(jobExecution); |
| 469 | + assertSame(recover, jobExecution); |
| 470 | + verifyNoInteractions(jobRepository); |
475 | 471 | } |
476 | 472 |
|
477 | 473 | static class MockJob extends AbstractJob { |
|
0 commit comments