Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Commit f7a36ff

Browse files
Merge pull request #1 from isanghaessi/_GH-4755
Fix wrong behavior of JobRepository with empty identifying job parameters
2 parents 3bcc525 + 0ce9de6 commit f7a36ff

File tree

2 files changed

+12
-9
lines changed

2 files changed

+12
-9
lines changed

‎spring-batch-core/src/main/java/org/springframework/batch/core/repository/support/SimpleJobRepository.java

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,7 @@
5454
* @author Baris Cubukcuoglu
5555
* @author Parikshit Dutta
5656
* @author Mark John Moreno
57+
* @author Seungyong Hong
5758
* @see JobRepository
5859
* @see JobInstanceDao
5960
* @see JobExecutionDao
@@ -109,10 +110,8 @@ public JobExecution createJobExecution(String jobName, JobParameters jobParamete
109110
+ "The last execution ended with a failure that could not be rolled back, "
110111
+ "so it may be dangerous to proceed. Manual intervention is probably necessary.");
111112
}
112-
JobParameters allJobParameters = execution.getJobParameters();
113-
JobParameters identifyingJobParameters = new JobParameters(allJobParameters.getIdentifyingParameters());
114-
if (!identifyingJobParameters.isEmpty()
115-
&& (status == BatchStatus.COMPLETED || status == BatchStatus.ABANDONED)) {
113+
if (status == BatchStatus.COMPLETED || status == BatchStatus.ABANDONED) {
114+
JobParameters identifyingJobParameters = new JobParameters(execution.getJobParameters().getIdentifyingParameters());
116115
throw new JobInstanceAlreadyCompleteException(
117116
"A job instance already exists and is complete for identifying parameters="
118117
+ identifyingJobParameters + ". If you want to run this job again, "

‎spring-batch-core/src/test/java/org/springframework/batch/core/repository/support/SimpleJobRepositoryTests.java

Lines changed: 9 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2023 the original author or authors.
2+
* Copyright 2006-2025 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -33,6 +33,8 @@
3333

3434
import org.junit.jupiter.api.BeforeEach;
3535
import org.junit.jupiter.api.Test;
36+
import org.junit.jupiter.params.ParameterizedTest;
37+
import org.junit.jupiter.params.provider.EnumSource;
3638
import org.springframework.batch.core.BatchStatus;
3739
import org.springframework.batch.core.job.JobExecution;
3840
import org.springframework.batch.core.job.JobInstance;
@@ -61,6 +63,7 @@
6163
* @author Baris Cubukcuoglu
6264
* @author Mahmoud Ben Hassine
6365
* @author Parikshit Dutta
66+
* @author Seungyong Hong
6467
*
6568
*/
6669
class SimpleJobRepositoryTests {
@@ -103,7 +106,7 @@ void setUp() {
103106

104107
jobRepository = new SimpleJobRepository(jobInstanceDao, jobExecutionDao, stepExecutionDao, ecDao);
105108

106-
jobParameters = new JobParametersBuilder().addString("bar", "test").toJobParameters();
109+
jobParameters = new JobParametersBuilder().addString("bar", "test", false).toJobParameters();
107110

108111
job = new JobSupport();
109112
job.setBeanName("RepositoryTest");
@@ -289,9 +292,10 @@ void testCreateJobExecutionStatusUnknown() {
289292
assertThrows(JobRestartException.class, () -> jobRepository.createJobExecution("foo", new JobParameters()));
290293
}
291294

292-
@Test
293-
void testCreateJobExecutionAlreadyComplete() {
294-
jobExecution.setStatus(BatchStatus.COMPLETED);
295+
@ParameterizedTest
296+
@EnumSource(mode = EnumSource.Mode.INCLUDE, names = {"COMPLETED", "ABANDONED"})
297+
void testCreateJobExecutionAlreadyComplete(BatchStatus batchStatus) {
298+
jobExecution.setStatus(batchStatus);
295299
jobExecution.setEndTime(LocalDateTime.now());
296300

297301
when(jobInstanceDao.getJobInstance("foo", new JobParameters())).thenReturn(jobInstance);

0 commit comments

Comments
(0)

AltStyle によって変換されたページ (->オリジナル) /