Skip to content

Fix to get parameters correctly when multiple job executions exist #4364

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,7 @@
* @author Mahmoud Ben Hassine
* @author Dimitrios Liapis
* @author Philippe Marschall
* @author Jinwoo Bae
*/
public class JdbcJobExecutionDao extends AbstractJdbcBatchMetadataDao implements JobExecutionDao, InitializingBean {

Expand Down Expand Up @@ -492,8 +493,6 @@ private final class JobExecutionRowMapper implements RowMapper<JobExecution> {

private JobInstance jobInstance;

private JobParameters jobParameters;

public JobExecutionRowMapper() {
}

Expand All @@ -505,9 +504,7 @@ public JobExecutionRowMapper(JobInstance jobInstance) {
public JobExecution mapRow(ResultSet rs, int rowNum) throws SQLException {
Long id = rs.getLong(1);
JobExecution jobExecution;
if (jobParameters == null) {
jobParameters = getJobParameters(id);
}
JobParameters jobParameters = getJobParameters(id);

if (jobInstance == null) {
jobExecution = new JobExecution(id, jobParameters);
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
Expand Down Expand Up @@ -40,6 +40,7 @@
import org.springframework.batch.core.JobInstance;
import org.springframework.batch.core.JobInterruptedException;
import org.springframework.batch.core.JobParameters;
import org.springframework.batch.core.JobParametersBuilder;
import org.springframework.batch.core.Step;
import org.springframework.batch.core.StepExecution;
import org.springframework.batch.core.UnexpectedJobExecutionException;
Expand Down Expand Up @@ -68,6 +69,7 @@
* @author Lucas Ward
* @author Will Schipp
* @author Mahmoud Ben Hassine
* @author Jinwoo Bae
*/
class SimpleJobTests {

Expand Down Expand Up @@ -483,6 +485,43 @@ void testGetStepNotExists() {
assertNull(step);
}

@Test
void testGetMultipleJobParameters() throws Exception {
StubStep failStep = new StubStep("failStep", jobRepository);

failStep.setCallback(new Runnable() {
@Override
public void run() {
throw new RuntimeException("An error occurred.");
}
});

job.setName("parametersTestJob");
job.setSteps(Arrays.asList(new Step[] { failStep }));

JobParameters firstJobParameters = new JobParametersBuilder().addString("JobExecutionParameter", "first", false)
.toJobParameters();
JobExecution jobexecution = jobRepository.createJobExecution(job.getName(), firstJobParameters);
job.execute(jobexecution);

List<JobExecution> jobExecutionList = jobExplorer.getJobExecutions(jobexecution.getJobInstance());

assertEquals(jobExecutionList.size(), 1);
assertEquals(jobExecutionList.get(0).getJobParameters().getString("JobExecutionParameter"), "first");

JobParameters secondJobParameters = new JobParametersBuilder()
.addString("JobExecutionParameter", "second", false).toJobParameters();
jobexecution = jobRepository.createJobExecution(job.getName(), secondJobParameters);
job.execute(jobexecution);

jobExecutionList = jobExplorer.getJobExecutions(jobexecution.getJobInstance());

assertEquals(jobExecutionList.size(), 2);
assertEquals(jobExecutionList.get(0).getJobParameters().getString("JobExecutionParameter"), "second");
assertEquals(jobExecutionList.get(1).getJobParameters().getString("JobExecutionParameter"), "first");

}

/*
* Check JobRepository to ensure status is being saved.
*/
Expand Down