Skip to content

Commit bb051fc

Browse files
committed
Fix broken and disabled tests
Spring Batch made some fixes and task test needed repair
1 parent ec1e001 commit bb051fc

File tree

1 file changed

+14
-9
lines changed

1 file changed

+14
-9
lines changed

spring-cloud-task-batch/src/test/java/org/springframework/cloud/task/batch/handler/TaskJobLauncherApplicationRunnerCoreTests.java

Lines changed: 14 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -21,15 +21,13 @@
2121

2222
import javax.sql.DataSource;
2323

24-
import org.junit.jupiter.api.Disabled;
2524
import org.junit.jupiter.api.Test;
2625

2726
import org.springframework.batch.core.configuration.annotation.EnableBatchProcessing;
2827
import org.springframework.batch.core.configuration.annotation.EnableJdbcJobRepository;
2928
import org.springframework.batch.core.job.Job;
3029
import org.springframework.batch.core.job.JobExecutionException;
3130
import org.springframework.batch.core.job.JobInstance;
32-
import org.springframework.batch.core.job.UnexpectedJobExecutionException;
3331
import org.springframework.batch.core.job.builder.JobBuilder;
3432
import org.springframework.batch.core.job.builder.SimpleJobBuilder;
3533
import org.springframework.batch.core.job.parameters.JobParameters;
@@ -55,7 +53,7 @@
5553
import org.springframework.transaction.PlatformTransactionManager;
5654

5755
import static org.assertj.core.api.Assertions.assertThat;
58-
import static org.assertj.core.api.Assertions.assertThatThrownBy;
56+
import static org.assertj.core.api.AssertionsForClassTypes.assertThatExceptionOfType;
5957

6058
/**
6159
* @author Glenn Renfro
@@ -78,7 +76,6 @@ void basicExecution() {
7876
});
7977
}
8078

81-
@Disabled("Disabled until Spring Batch allows a incrementer to set identifyable to true.")
8279
@Test
8380
void incrementExistingExecution() {
8481
this.contextRunner.run((context) -> {
@@ -122,10 +119,18 @@ void retryFailedExecutionOnNonRestartableJob() {
122119
.incrementer(new RunIdIncrementer())
123120
.build();
124121
runFailedJob(jobLauncherContext, job, new JobParameters());
125-
assertThatThrownBy(() -> runFailedJob(jobLauncherContext, job, new JobParameters()))
126-
.isInstanceOf(UnexpectedJobExecutionException.class)
127-
.hasMessageContaining(
128-
"Illegal state (only happens on a race condition): job not restartable with name=job and parameters=");
122+
123+
// A failed job that is not restartable does not re-use the job params of
124+
// the last execution, but creates a new job instance when running it again.
125+
assertThat(jobLauncherContext.jobInstances()).hasSize(1);
126+
assertThatExceptionOfType(TaskException.class).isThrownBy(() -> {
127+
// try to re-run a failed execution
128+
// In this case the change from the previous behavior is that a new job
129+
// instance is created
130+
// https://github.com/spring-projects/spring-batch/issues/4910
131+
jobLauncherContext.runner.execute(job,
132+
new JobParametersBuilder().addLong("run.id", 1L).toJobParameters());
133+
}).withMessageContaining("Job job failed during execution for job instance id 2 with jobExecutionId of 2 ");
129134
});
130135
}
131136

@@ -148,7 +153,7 @@ void retryFailedExecutionWithNonIdentifyingParameters() {
148153
// https://github.com/spring-projects/spring-batch/issues/4910
149154
runFailedJob(jobLauncherContext, job,
150155
new JobParametersBuilder(jobParameters).addLong("run.id", 1L).toJobParameters());
151-
assertThat(jobLauncherContext.jobInstances()).hasSize(1);
156+
assertThat(jobLauncherContext.jobInstances()).hasSize(2);
152157
});
153158
}
154159

0 commit comments

Comments
 (0)