Make JobParametersBuilder#getNextJobParameters consistent with CommandLineJobRunner and JobOperator
Before this commit, JobParametersBuilder#getNextJobParameters was checking for restartability conditions. This is not only already done by the JobLauncher, but also makes it inconsistent with the behaviour of CommandLineJobRunner when used with "-next" option and JobOperator#startNextInstance, which is starting the next instance in sequence based on the incrementer without dealing with restartability. This commit fixes the JobParametersBuilder#getNextJobParameters to behave like the CommandLineJobRunner and JobOperator in regards to starting the next instance. Resolves BATCH-2711
This commit is contained in:
committed by
Michael Minella
parent
f8f8a02a4d
commit
ebf156d529
@@ -23,7 +23,9 @@ import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.ExpectedException;
|
||||
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.job.SimpleJob;
|
||||
@@ -56,6 +58,9 @@ public class JobParametersBuilderTests {
|
||||
|
||||
private Date date = new Date(System.currentTimeMillis());
|
||||
|
||||
@Rule
|
||||
public ExpectedException expectedException = ExpectedException.none();
|
||||
|
||||
@Before
|
||||
public void initialize() {
|
||||
this.job = new SimpleJob("simpleJob");
|
||||
@@ -198,9 +203,10 @@ public class JobParametersBuilderTests {
|
||||
|
||||
@Test
|
||||
public void testGetNextJobParametersNoIncrementer(){
|
||||
expectedException.expect(IllegalArgumentException.class);
|
||||
expectedException.expectMessage("No job parameters incrementer found for job=simpleJob");
|
||||
initializeForNextJobParameters();
|
||||
this.parametersBuilder.getNextJobParameters(this.job);
|
||||
baseJobParametersVerify(this.parametersBuilder.toJobParameters(), 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -226,14 +232,13 @@ public class JobParametersBuilderTests {
|
||||
initializeForNextJobParameters();
|
||||
this.parametersBuilder.addLong("NON_IDENTIFYING_LONG", new Long(1), false);
|
||||
this.parametersBuilder.getNextJobParameters(this.job);
|
||||
baseJobParametersVerify(this.parametersBuilder.toJobParameters(), 3);
|
||||
baseJobParametersVerify(this.parametersBuilder.toJobParameters(), 5);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetNextJobParametersNoPreviousExecution(){
|
||||
this.job.setJobParametersIncrementer(new RunIdIncrementer());
|
||||
this.jobInstanceList.add(new JobInstance(1L, "simpleJobInstance"));
|
||||
this.jobExecutionList.add(null);
|
||||
when(this.jobExplorer.getJobInstances("simpleJob",0,1)).thenReturn(this.jobInstanceList);
|
||||
when(this.jobExplorer.getJobExecutions(any())).thenReturn(this.jobExecutionList);
|
||||
initializeForNextJobParameters();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2013 the original author or authors.
|
||||
* Copyright 2006-2018 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.
|
||||
@@ -67,6 +67,7 @@ import static org.mockito.Mockito.when;
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Will Schipp
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
*/
|
||||
public class SimpleJobOperatorTests {
|
||||
@@ -153,6 +154,7 @@ public class SimpleJobOperatorTests {
|
||||
*/
|
||||
@Test
|
||||
public void testStartNextInstanceSunnyDay() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
JobInstance jobInstance = new JobInstance(321L, "foo");
|
||||
when(jobExplorer.getJobInstances("foo", 0, 1)).thenReturn(Collections.singletonList(jobInstance));
|
||||
when(jobExplorer.getJobExecutions(jobInstance)).thenReturn(Collections.singletonList(new JobExecution(jobInstance, new JobParameters())));
|
||||
|
||||
Reference in New Issue
Block a user