BATCH-1412: Implementing non-identifying job parameters
This commit is contained in:
committed by
Dave Syer
parent
3601c84164
commit
557515df45
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2013-2013 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.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
package org.springframework.batch.core;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class DefaultJobKeyGeneratorTests {
|
||||
|
||||
private JobKeyGenerator<JobParameters> jobKeyGenerator;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
jobKeyGenerator = new DefaultJobKeyGenerator();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testMixedParameters() {
|
||||
JobParameters jobParameters1 = new JobParametersBuilder().addString(
|
||||
"foo", "bar").addString("bar", "foo").toJobParameters();
|
||||
JobParameters jobParameters2 = new JobParametersBuilder().addString(
|
||||
"foo", "bar", true).addString("bar", "foo", true)
|
||||
.addString("ignoreMe", "irrelivant", false).toJobParameters();
|
||||
String key1 = jobKeyGenerator.generateKey(jobParameters1);
|
||||
String key2 = jobKeyGenerator.generateKey(jobParameters2);
|
||||
assertEquals(key1, key2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateJobKey() {
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString(
|
||||
"foo", "bar").addString("bar", "foo").toJobParameters();
|
||||
String key = jobKeyGenerator.generateKey(jobParameters);
|
||||
assertEquals(32, key.length());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateJobKeyWithNullParameter() {
|
||||
JobParameters jobParameters1 = new JobParametersBuilder().addString(
|
||||
"foo", "bar").addString("bar", null).toJobParameters();
|
||||
JobParameters jobParameters2 = new JobParametersBuilder().addString(
|
||||
"foo", "bar").addString("bar", "").toJobParameters();
|
||||
String key1 = jobKeyGenerator.generateKey(jobParameters1);
|
||||
String key2 = jobKeyGenerator.generateKey(jobParameters2);
|
||||
assertEquals(key1, key2);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testCreateJobKeyOrdering() {
|
||||
JobParameters jobParameters1 = new JobParametersBuilder().addString(
|
||||
"foo", "bar").addString("bar", "foo").toJobParameters();
|
||||
String key1 = jobKeyGenerator.generateKey(jobParameters1);
|
||||
JobParameters jobParameters2 = new JobParametersBuilder().addString(
|
||||
"bar", "foo").addString("foo", "bar").toJobParameters();
|
||||
String key2 = jobKeyGenerator.generateKey(jobParameters2);
|
||||
assertEquals(key1, key2);
|
||||
}
|
||||
}
|
||||
@@ -30,16 +30,16 @@ import org.springframework.batch.support.SerializationUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class JobExecutionTests {
|
||||
|
||||
private JobExecution execution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), "foo"),
|
||||
new Long(12));
|
||||
private JobExecution execution = new JobExecution(new JobInstance(new Long(11), "foo"),
|
||||
new Long(12), new JobParameters());
|
||||
|
||||
@Test
|
||||
public void testJobExecution() {
|
||||
assertNull(new JobExecution(new JobInstance(null, null, "foo")).getId());
|
||||
assertNull(new JobExecution(new JobInstance(null, "foo"), null).getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -126,7 +126,7 @@ public class JobExecutionTests {
|
||||
@Test
|
||||
public void testGetJobId() {
|
||||
assertEquals(11, execution.getJobId().longValue());
|
||||
execution = new JobExecution(new JobInstance(new Long(23), new JobParameters(), "testJob"), null);
|
||||
execution = new JobExecution(new JobInstance(new Long(23), "testJob"), null, new JobParameters());
|
||||
assertEquals(23, execution.getJobId().longValue());
|
||||
}
|
||||
|
||||
@@ -136,7 +136,7 @@ public class JobExecutionTests {
|
||||
*/
|
||||
@Test
|
||||
public void testGetJobIdForNullJob() {
|
||||
execution = new JobExecution(null, null);
|
||||
execution = new JobExecution((JobInstance) null, (JobParameters) null);
|
||||
assertEquals(null, execution.getJobId());
|
||||
}
|
||||
|
||||
@@ -213,7 +213,7 @@ public class JobExecutionTests {
|
||||
|
||||
@Test
|
||||
public void testToStringWithNullJob() throws Exception {
|
||||
execution = new JobExecution(new JobInstance(null, null, "foo"));
|
||||
execution = new JobExecution(new JobInstance(null, "foo"), null);
|
||||
assertTrue("JobExecution string does not contain id", execution.toString().indexOf("id=") >= 0);
|
||||
assertTrue("JobExecution string does not contain job: " + execution, execution.toString().indexOf("job=") >= 0);
|
||||
}
|
||||
|
||||
@@ -21,18 +21,18 @@ import org.springframework.batch.support.SerializationUtils;
|
||||
|
||||
/**
|
||||
* @author dsyer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class JobInstanceTests extends TestCase {
|
||||
|
||||
private JobInstance instance = new JobInstance(new Long(11), new JobParameters(), "job");
|
||||
private JobInstance instance = new JobInstance(new Long(11), "job");
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.JobInstance#getJobName()}.
|
||||
*/
|
||||
public void testGetName() {
|
||||
instance = new JobInstance(new Long(1), new JobParameters(), "foo");
|
||||
instance = new JobInstance(new Long(1), "foo");
|
||||
assertEquals("foo", instance.getJobName());
|
||||
}
|
||||
|
||||
@@ -42,24 +42,21 @@ public class JobInstanceTests extends TestCase {
|
||||
|
||||
public void testCreateWithNulls() {
|
||||
try {
|
||||
new JobInstance(null, null, null);
|
||||
new JobInstance(null, null);
|
||||
fail("job instance can't exist without job specified");
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
// expected
|
||||
}
|
||||
instance = new JobInstance(null, null, "testJob");
|
||||
instance = new JobInstance(null, "testJob");
|
||||
assertEquals("testJob", instance.getJobName());
|
||||
assertEquals(0, instance.getJobParameters().getParameters().size());
|
||||
}
|
||||
|
||||
public void testSerialization() {
|
||||
instance = new JobInstance(new Long(1), new JobParametersBuilder().addDouble("doubleKey", Double.valueOf(5.1))
|
||||
.toJobParameters(), "jobName");
|
||||
|
||||
byte[] serialized = SerializationUtils.serialize(instance);
|
||||
|
||||
assertEquals(instance, SerializationUtils.deserialize(serialized));
|
||||
instance = new JobInstance(new Long(1), "jobName");
|
||||
|
||||
byte[] serialized = SerializationUtils.serialize(instance);
|
||||
|
||||
assertEquals(instance, SerializationUtils.deserialize(serialized));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,9 +1,11 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.core;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
@@ -16,84 +18,84 @@ import org.junit.Test;
|
||||
public class JobParameterTests {
|
||||
|
||||
JobParameter jobParameter;
|
||||
|
||||
|
||||
@Test
|
||||
public void testStringParameter(){
|
||||
jobParameter = new JobParameter("test");
|
||||
jobParameter = new JobParameter("test", true);
|
||||
assertEquals("test", jobParameter.getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNullStringParameter(){
|
||||
jobParameter = new JobParameter((String)null);
|
||||
jobParameter = new JobParameter((String)null, true);
|
||||
assertEquals(null, jobParameter.getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLongParameter(){
|
||||
jobParameter = new JobParameter(1L);
|
||||
jobParameter = new JobParameter(1L, true);
|
||||
assertEquals(1L, jobParameter.getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDoubleParameter(){
|
||||
jobParameter = new JobParameter(1.1);
|
||||
jobParameter = new JobParameter(1.1, true);
|
||||
assertEquals(1.1, jobParameter.getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDateParameter(){
|
||||
Date epoch = new Date(0L);
|
||||
jobParameter = new JobParameter(epoch);
|
||||
jobParameter = new JobParameter(epoch, true);
|
||||
assertEquals(new Date(0L), jobParameter.getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testNullDateParameter(){
|
||||
jobParameter = new JobParameter((Date)null);
|
||||
jobParameter = new JobParameter((Date)null, true);
|
||||
assertEquals(null, jobParameter.getValue());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testDateParameterToString(){
|
||||
Date epoch = new Date(0L);
|
||||
jobParameter = new JobParameter(epoch);
|
||||
jobParameter = new JobParameter(epoch, true);
|
||||
assertEquals("0", jobParameter.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEquals(){
|
||||
jobParameter = new JobParameter("test");
|
||||
JobParameter testParameter = new JobParameter("test");
|
||||
jobParameter = new JobParameter("test", true);
|
||||
JobParameter testParameter = new JobParameter("test", true);
|
||||
assertTrue(jobParameter.equals(testParameter));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testHashcode(){
|
||||
jobParameter = new JobParameter("test");
|
||||
JobParameter testParameter = new JobParameter("test");
|
||||
jobParameter = new JobParameter("test", true);
|
||||
JobParameter testParameter = new JobParameter("test", true);
|
||||
assertEquals(testParameter.hashCode(), jobParameter.hashCode());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testEqualsWithNull(){
|
||||
jobParameter = new JobParameter((String)null);
|
||||
JobParameter testParameter = new JobParameter((String)null);
|
||||
jobParameter = new JobParameter((String)null, true);
|
||||
JobParameter testParameter = new JobParameter((String)null, true);
|
||||
assertTrue(jobParameter.equals(testParameter));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testEqualsWithNullAndDifferentType(){
|
||||
jobParameter = new JobParameter((String)null);
|
||||
JobParameter testParameter = new JobParameter((Date)null);
|
||||
jobParameter = new JobParameter((String)null, true);
|
||||
JobParameter testParameter = new JobParameter((Date)null, true);
|
||||
assertFalse(jobParameter.equals(testParameter));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHashcodeWithNull(){
|
||||
jobParameter = new JobParameter((String)null);
|
||||
JobParameter testParameter = new JobParameter((String)null);
|
||||
jobParameter = new JobParameter((String)null, true);
|
||||
JobParameter testParameter = new JobParameter((String)null, true);
|
||||
assertEquals(testParameter.hashCode(), jobParameter.hashCode());
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
@@ -1,25 +1,43 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.core;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
|
||||
import junit.framework.TestCase;
|
||||
import org.junit.Test;
|
||||
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
public class JobParametersBuilderTests extends TestCase {
|
||||
public class JobParametersBuilderTests {
|
||||
|
||||
JobParametersBuilder parametersBuilder = new JobParametersBuilder();
|
||||
|
||||
|
||||
Date date = new Date(System.currentTimeMillis());
|
||||
|
||||
public void testToJobRuntimeParamters(){
|
||||
|
||||
@Test
|
||||
public void testNonIdentifyingParameters() {
|
||||
parametersBuilder.addDate("SCHEDULE_DATE", date, false);
|
||||
parametersBuilder.addLong("LONG", new Long(1), false);
|
||||
parametersBuilder.addString("STRING", "string value", false);
|
||||
JobParameters parameters = parametersBuilder.toJobParameters();
|
||||
assertEquals(date, parameters.getDate("SCHEDULE_DATE"));
|
||||
assertEquals(1L, parameters.getLong("LONG"));
|
||||
assertEquals("string value", parameters.getString("STRING"));
|
||||
assertFalse(parameters.getParameters().get("SCHEDULE_DATE").isIdentifying());
|
||||
assertFalse(parameters.getParameters().get("LONG").isIdentifying());
|
||||
assertFalse(parameters.getParameters().get("STRING").isIdentifying());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToJobRuntimeParamters(){
|
||||
parametersBuilder.addDate("SCHEDULE_DATE", date);
|
||||
parametersBuilder.addLong("LONG", new Long(1));
|
||||
parametersBuilder.addString("STRING", "string value");
|
||||
@@ -29,7 +47,8 @@ public class JobParametersBuilderTests extends TestCase {
|
||||
assertEquals("string value", parameters.getString("STRING"));
|
||||
}
|
||||
|
||||
public void testNullRuntimeParamters(){
|
||||
@Test
|
||||
public void testNullRuntimeParamters(){
|
||||
parametersBuilder.addDate("SCHEDULE_DATE", null);
|
||||
parametersBuilder.addLong("LONG", null);
|
||||
parametersBuilder.addString("STRING", null);
|
||||
@@ -39,14 +58,16 @@ public class JobParametersBuilderTests extends TestCase {
|
||||
assertEquals(null, parameters.getString("STRING"));
|
||||
}
|
||||
|
||||
public void testCopy(){
|
||||
@Test
|
||||
public void testCopy(){
|
||||
parametersBuilder.addString("STRING", "string value");
|
||||
parametersBuilder = new JobParametersBuilder(parametersBuilder.toJobParameters());
|
||||
Iterator<String> parameters = parametersBuilder.toJobParameters().getParameters().keySet().iterator();
|
||||
assertEquals("STRING", parameters.next());
|
||||
}
|
||||
|
||||
public void testOrderedTypes(){
|
||||
@Test
|
||||
public void testOrderedTypes(){
|
||||
parametersBuilder.addDate("SCHEDULE_DATE", date);
|
||||
parametersBuilder.addLong("LONG", new Long(1));
|
||||
parametersBuilder.addString("STRING", "string value");
|
||||
@@ -56,7 +77,8 @@ public class JobParametersBuilderTests extends TestCase {
|
||||
assertEquals("STRING", parameters.next());
|
||||
}
|
||||
|
||||
public void testOrderedStrings(){
|
||||
@Test
|
||||
public void testOrderedStrings(){
|
||||
parametersBuilder.addString("foo", "value foo");
|
||||
parametersBuilder.addString("bar", "value bar");
|
||||
parametersBuilder.addString("spam", "value spam");
|
||||
@@ -65,7 +87,8 @@ public class JobParametersBuilderTests extends TestCase {
|
||||
assertEquals("bar", parameters.next());
|
||||
assertEquals("spam", parameters.next());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddJobParameter(){
|
||||
JobParameter jobParameter = new JobParameter("bar");
|
||||
parametersBuilder.addParameter("foo", jobParameter);
|
||||
|
||||
@@ -1,9 +1,12 @@
|
||||
/**
|
||||
*
|
||||
*
|
||||
*/
|
||||
package org.springframework.batch.core;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
@@ -18,7 +21,7 @@ import org.springframework.batch.support.SerializationUtils;
|
||||
/**
|
||||
* @author Lucas Ward
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class JobParametersTests {
|
||||
|
||||
@@ -36,14 +39,14 @@ public class JobParametersTests {
|
||||
private JobParameters getNewParameters() {
|
||||
|
||||
Map<String, JobParameter> parameterMap = new HashMap<String, JobParameter>();
|
||||
parameterMap.put("string.key1", new JobParameter("value1"));
|
||||
parameterMap.put("string.key2", new JobParameter("value2"));
|
||||
parameterMap.put("long.key1", new JobParameter(1L));
|
||||
parameterMap.put("long.key2", new JobParameter(2L));
|
||||
parameterMap.put("double.key1", new JobParameter(1.1));
|
||||
parameterMap.put("double.key2", new JobParameter(2.2));
|
||||
parameterMap.put("date.key1", new JobParameter(date1));
|
||||
parameterMap.put("date.key2", new JobParameter(date2));
|
||||
parameterMap.put("string.key1", new JobParameter("value1", true));
|
||||
parameterMap.put("string.key2", new JobParameter("value2", true));
|
||||
parameterMap.put("long.key1", new JobParameter(1L, true));
|
||||
parameterMap.put("long.key2", new JobParameter(2L, true));
|
||||
parameterMap.put("double.key1", new JobParameter(1.1, true));
|
||||
parameterMap.put("double.key2", new JobParameter(2.2, true));
|
||||
parameterMap.put("date.key1", new JobParameter(date1, true));
|
||||
parameterMap.put("date.key2", new JobParameter(date2, true));
|
||||
|
||||
return new JobParameters(parameterMap);
|
||||
}
|
||||
@@ -57,7 +60,7 @@ public class JobParametersTests {
|
||||
|
||||
@Test
|
||||
public void testGetNullString() {
|
||||
parameters = new JobParameters(Collections.singletonMap("string.key1", new JobParameter((String)null)));
|
||||
parameters = new JobParameters(Collections.singletonMap("string.key1", new JobParameter((String) null, true)));
|
||||
assertEquals(null, parameters.getDate("string.key1"));
|
||||
}
|
||||
|
||||
@@ -81,13 +84,13 @@ public class JobParametersTests {
|
||||
|
||||
@Test
|
||||
public void testGetNullDate() {
|
||||
parameters = new JobParameters(Collections.singletonMap("date.key1", new JobParameter((Date)null)));
|
||||
parameters = new JobParameters(Collections.singletonMap("date.key1", new JobParameter((Date)null, true)));
|
||||
assertEquals(null, parameters.getDate("date.key1"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetEmptyLong() {
|
||||
parameters = new JobParameters(Collections.singletonMap("long1", new JobParameter((Long)null)));
|
||||
parameters = new JobParameters(Collections.singletonMap("long1", new JobParameter((Long)null, true)));
|
||||
assertEquals(0L, parameters.getLong("long1"));
|
||||
}
|
||||
|
||||
@@ -149,15 +152,15 @@ public class JobParametersTests {
|
||||
String string1 = stringBuilder.toString();
|
||||
|
||||
Map<String, JobParameter> parameterMap = new HashMap<String, JobParameter>();
|
||||
parameterMap.put("string.key2", new JobParameter("value2"));
|
||||
parameterMap.put("string.key1", new JobParameter("value1"));
|
||||
parameterMap.put("long.key2", new JobParameter(2L));
|
||||
parameterMap.put("long.key1", new JobParameter(1L));
|
||||
parameterMap.put("double.key2", new JobParameter(2.2));
|
||||
parameterMap.put("double.key1", new JobParameter(1.1));
|
||||
parameterMap.put("date.key2", new JobParameter(date2));
|
||||
parameterMap.put("date.key1", new JobParameter(date1));
|
||||
|
||||
parameterMap.put("string.key2", new JobParameter("value2", true));
|
||||
parameterMap.put("string.key1", new JobParameter("value1", true));
|
||||
parameterMap.put("long.key2", new JobParameter(2L, true));
|
||||
parameterMap.put("long.key1", new JobParameter(1L, true));
|
||||
parameterMap.put("double.key2", new JobParameter(2.2, true));
|
||||
parameterMap.put("double.key1", new JobParameter(1.1, true));
|
||||
parameterMap.put("date.key2", new JobParameter(date2, true));
|
||||
parameterMap.put("date.key1", new JobParameter(date1, true));
|
||||
|
||||
JobParameters testProps = new JobParameters(parameterMap);
|
||||
|
||||
props = testProps.getParameters();
|
||||
@@ -187,28 +190,28 @@ public class JobParametersTests {
|
||||
JobParameters params = getNewParameters();
|
||||
|
||||
byte[] serialized =
|
||||
SerializationUtils.serialize(params);
|
||||
SerializationUtils.serialize(params);
|
||||
|
||||
assertEquals(params, SerializationUtils.deserialize(serialized));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLongReturns0WhenKeyDoesntExit(){
|
||||
assertEquals(0L,new JobParameters().getLong("keythatdoesntexist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringReturnsNullWhenKeyDoesntExit(){
|
||||
assertNull(new JobParameters().getString("keythatdoesntexist"));
|
||||
}
|
||||
@Test
|
||||
public void testLongReturns0WhenKeyDoesntExit(){
|
||||
assertEquals(0L,new JobParameters().getLong("keythatdoesntexist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDoubleReturns0WhenKeyDoesntExit(){
|
||||
assertEquals(0.0,new JobParameters().getLong("keythatdoesntexist"), 0.0001);
|
||||
}
|
||||
@Test
|
||||
public void testStringReturnsNullWhenKeyDoesntExit(){
|
||||
assertNull(new JobParameters().getString("keythatdoesntexist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateReturnsNullWhenKeyDoesntExit(){
|
||||
assertNull(new JobParameters().getDate("keythatdoesntexist"));
|
||||
}
|
||||
@Test
|
||||
public void testDoubleReturns0WhenKeyDoesntExit(){
|
||||
assertEquals(0.0,new JobParameters().getLong("keythatdoesntexist"), 0.0001);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDateReturnsNullWhenKeyDoesntExit(){
|
||||
assertNull(new JobParameters().getDate("keythatdoesntexist"));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -34,17 +34,17 @@ import org.springframework.batch.support.SerializationUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class StepExecutionTests {
|
||||
|
||||
private StepExecution execution = newStepExecution(new StepSupport("stepName"), new Long(23));
|
||||
|
||||
private StepExecution blankExecution = newStepExecution(new StepSupport("blank"), null);
|
||||
|
||||
|
||||
private ExecutionContext foobarEc = new ExecutionContext();
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -58,7 +58,7 @@ public class StepExecutionTests {
|
||||
|
||||
@Test
|
||||
public void testStepExecutionWithNullId() {
|
||||
assertNull(new StepExecution("stepName", new JobExecution(new JobInstance(null,null,"foo"))).getId());
|
||||
assertNull(new StepExecution("stepName", new JobExecution(new JobInstance(null,"foo"), null)).getId());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -161,7 +161,7 @@ public class StepExecutionTests {
|
||||
@Test
|
||||
public void testNullNameIsIllegal() throws Exception {
|
||||
try {
|
||||
new StepExecution(null, new JobExecution(new JobInstance(null, null, "job")));
|
||||
new StepExecution(null, new JobExecution(new JobInstance(null, "job"), null));
|
||||
fail();
|
||||
}
|
||||
catch (IllegalArgumentException e) {
|
||||
@@ -262,25 +262,25 @@ public class StepExecutionTests {
|
||||
execution.setExecutionContext(foobarEc);
|
||||
assertTrue(set.contains(execution));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSerialization() throws Exception {
|
||||
|
||||
|
||||
ExitStatus status = ExitStatus.NOOP;
|
||||
execution.setExitStatus(status);
|
||||
execution.setExecutionContext(foobarEc);
|
||||
|
||||
|
||||
byte[] serialized = SerializationUtils.serialize(execution);
|
||||
StepExecution deserialized = (StepExecution) SerializationUtils.deserialize(serialized);
|
||||
|
||||
|
||||
assertEquals(execution, deserialized);
|
||||
assertEquals(status, deserialized.getExitStatus());
|
||||
assertNotNull(deserialized.getFailureExceptions());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testAddException() throws Exception{
|
||||
|
||||
|
||||
RuntimeException exception = new RuntimeException();
|
||||
assertEquals(0, execution.getFailureExceptions().size());
|
||||
execution.addFailureException(exception);
|
||||
@@ -302,10 +302,10 @@ public class StepExecutionTests {
|
||||
private StepExecution newStepExecution(Step step, Long jobExecutionId) {
|
||||
return newStepExecution(step, jobExecutionId, 4);
|
||||
}
|
||||
|
||||
|
||||
private StepExecution newStepExecution(Step step, Long jobExecutionId, long stepExecutionId) {
|
||||
JobInstance job = new JobInstance(3L, new JobParameters(), "testJob");
|
||||
StepExecution execution = new StepExecution(step.getName(), new JobExecution(job, jobExecutionId), stepExecutionId);
|
||||
JobInstance job = new JobInstance(3L, "testJob");
|
||||
StepExecution execution = new StepExecution(step.getName(), new JobExecution(job, jobExecutionId, new JobParameters()), stepExecutionId);
|
||||
return execution;
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
@ContextConfiguration
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
public class JobStepParserTests {
|
||||
|
||||
|
||||
@Autowired
|
||||
@Qualifier("job1")
|
||||
private Job job1;
|
||||
@@ -58,7 +58,7 @@ public class JobStepParserTests {
|
||||
|
||||
@Autowired
|
||||
private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean;
|
||||
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
mapJobRepositoryFactoryBean.clear();
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2008 the original author or authors.
|
||||
* Copyright 2006-2013 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.
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.batch.core.converter;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
@@ -34,7 +35,8 @@ import org.springframework.util.StringUtils;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
* @author Michael Minella
|
||||
*
|
||||
*/
|
||||
public class DefaultJobParametersConverterTests {
|
||||
|
||||
@@ -42,6 +44,66 @@ public class DefaultJobParametersConverterTests {
|
||||
|
||||
DateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
|
||||
|
||||
@Test
|
||||
public void testGetParametersIdentifyingWithIdentifyingKey() throws Exception {
|
||||
String jobKey = "+job.key=myKey";
|
||||
String scheduleDate = "+schedule.date(date)=2008/01/23";
|
||||
String vendorId = "+vendor.id(long)=33243243";
|
||||
|
||||
String[] args = new String[] { jobKey, scheduleDate, vendorId };
|
||||
|
||||
JobParameters props = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
|
||||
assertNotNull(props);
|
||||
assertTrue(props.getParameters().get("job.key").isIdentifying());
|
||||
assertTrue(props.getParameters().get("schedule.date").isIdentifying());
|
||||
assertTrue(props.getParameters().get("vendor.id").isIdentifying());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParametersIdentifyingByDefault() throws Exception {
|
||||
String jobKey = "job.key=myKey";
|
||||
String scheduleDate = "schedule.date(date)=2008/01/23";
|
||||
String vendorId = "vendor.id(long)=33243243";
|
||||
|
||||
String[] args = new String[] { jobKey, scheduleDate, vendorId };
|
||||
|
||||
JobParameters props = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
|
||||
assertNotNull(props);
|
||||
assertTrue(props.getParameters().get("job.key").isIdentifying());
|
||||
assertTrue(props.getParameters().get("schedule.date").isIdentifying());
|
||||
assertTrue(props.getParameters().get("vendor.id").isIdentifying());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParametersNonIdentifying() throws Exception {
|
||||
String jobKey = "-job.key=myKey";
|
||||
String scheduleDate = "-schedule.date(date)=2008/01/23";
|
||||
String vendorId = "-vendor.id(long)=33243243";
|
||||
|
||||
String[] args = new String[] { jobKey, scheduleDate, vendorId };
|
||||
|
||||
JobParameters props = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
|
||||
assertNotNull(props);
|
||||
assertFalse(props.getParameters().get("job.key").isIdentifying());
|
||||
assertFalse(props.getParameters().get("schedule.date").isIdentifying());
|
||||
assertFalse(props.getParameters().get("vendor.id").isIdentifying());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParametersMixed() throws Exception {
|
||||
String jobKey = "+job.key=myKey";
|
||||
String scheduleDate = "schedule.date(date)=2008/01/23";
|
||||
String vendorId = "-vendor.id(long)=33243243";
|
||||
|
||||
String[] args = new String[] { jobKey, scheduleDate, vendorId };
|
||||
|
||||
JobParameters props = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
|
||||
assertNotNull(props);
|
||||
assertTrue(props.getParameters().get("job.key").isIdentifying());
|
||||
assertTrue(props.getParameters().get("schedule.date").isIdentifying());
|
||||
assertFalse(props.getParameters().get("vendor.id").isIdentifying());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParameters() throws Exception {
|
||||
|
||||
@@ -206,7 +268,7 @@ public class DefaultJobParametersConverterTests {
|
||||
public void testRoundTrip() throws Exception {
|
||||
|
||||
String[] args = new String[] { "schedule.date(date)=2008/01/23", "job.key=myKey", "vendor.id(long)=33243243",
|
||||
"double.key(double)=1.23" };
|
||||
"double.key(double)=1.23" };
|
||||
|
||||
JobParameters parameters = factory.getJobParameters(StringUtils.splitArrayElementsIntoProperties(args, "="));
|
||||
|
||||
@@ -222,7 +284,7 @@ public class DefaultJobParametersConverterTests {
|
||||
public void testRoundTripWithNumberFormat() throws Exception {
|
||||
|
||||
String[] args = new String[] { "schedule.date(date)=2008/01/23", "job.key=myKey", "vendor.id(long)=33243243",
|
||||
"double.key(double)=1,23" };
|
||||
"double.key(double)=1,23" };
|
||||
NumberFormat format = NumberFormat.getInstance(Locale.GERMAN);
|
||||
factory.setNumberFormat(format);
|
||||
|
||||
@@ -252,21 +314,21 @@ public class DefaultJobParametersConverterTests {
|
||||
private boolean contains(String str, String searchStr) {
|
||||
return str.indexOf(searchStr) != -1;
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetPropertiesWithNullValues() throws Exception {
|
||||
|
||||
|
||||
JobParameters parameters = new JobParametersBuilder().addDate("schedule.date", null)
|
||||
.addString("job.key", null).addLong("vendor.id", null).addDouble("double.key", null)
|
||||
.toJobParameters();
|
||||
|
||||
|
||||
Properties props = factory.getProperties(parameters);
|
||||
assertNotNull(props);
|
||||
|
||||
|
||||
final String NOT_FOUND = "NOT FOUND";
|
||||
assertEquals(NOT_FOUND, props.getProperty("schedule.date", NOT_FOUND));
|
||||
assertEquals(NOT_FOUND, props.getProperty("job.key", NOT_FOUND));
|
||||
assertEquals(NOT_FOUND, props.getProperty("vendor.id", NOT_FOUND));
|
||||
assertEquals(NOT_FOUND, props.getProperty("double.key", NOT_FOUND));
|
||||
assertEquals(NOT_FOUND, props.getProperty("schedule.date", NOT_FOUND));
|
||||
assertEquals(NOT_FOUND, props.getProperty("job.key", NOT_FOUND));
|
||||
assertEquals(NOT_FOUND, props.getProperty("vendor.id", NOT_FOUND));
|
||||
assertEquals(NOT_FOUND, props.getProperty("double.key", NOT_FOUND));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -39,9 +39,9 @@ import org.springframework.batch.core.repository.dao.StepExecutionDao;
|
||||
|
||||
/**
|
||||
* Test {@link SimpleJobExplorer}.
|
||||
*
|
||||
*
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SimpleJobExplorerTests {
|
||||
|
||||
@@ -53,12 +53,11 @@ public class SimpleJobExplorerTests {
|
||||
|
||||
private StepExecutionDao stepExecutionDao;
|
||||
|
||||
private JobInstance jobInstance = new JobInstance(111L,
|
||||
new JobParameters(), "job");
|
||||
private JobInstance jobInstance = new JobInstance(111L, "job");
|
||||
|
||||
private ExecutionContextDao ecDao;
|
||||
|
||||
private JobExecution jobExecution = new JobExecution(jobInstance, 1234L);
|
||||
private JobExecution jobExecution = new JobExecution(jobInstance, 1234L, new JobParameters());
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -98,7 +97,7 @@ public class SimpleJobExplorerTests {
|
||||
expect(jobExecutionDao.getJobExecution(jobExecution.getId())).andReturn(jobExecution);
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("foo");
|
||||
expect(stepExecutionDao.getStepExecution(jobExecution, 123L))
|
||||
.andReturn(stepExecution);
|
||||
.andReturn(stepExecution);
|
||||
expect(ecDao.getExecutionContext(stepExecution)).andReturn(null);
|
||||
expectLastCall();
|
||||
replay(jobExecutionDao, stepExecutionDao, ecDao);
|
||||
@@ -111,7 +110,7 @@ public class SimpleJobExplorerTests {
|
||||
expect(jobExecutionDao.getJobExecution(jobExecution.getId())).andReturn(jobExecution);
|
||||
expectLastCall();
|
||||
expect(stepExecutionDao.getStepExecution(jobExecution, 123L))
|
||||
.andReturn(null);
|
||||
.andReturn(null);
|
||||
replay(jobExecutionDao, stepExecutionDao, ecDao);
|
||||
assertNull(jobExplorer.getStepExecution(jobExecution.getId(), 123L));
|
||||
verify(jobExecutionDao, stepExecutionDao, ecDao);
|
||||
|
||||
@@ -10,9 +10,9 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.repository.dao.JdbcJobInstanceDao;
|
||||
import org.springframework.batch.core.repository.dao.JdbcJobExecutionDao;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -34,37 +34,40 @@ public class JobLauncherIntegrationTests {
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testLaunchAndRelaunch() throws Exception {
|
||||
|
||||
|
||||
int before = jdbcTemplate.queryForInt("select count(*) from BATCH_JOB_INSTANCE");
|
||||
|
||||
|
||||
JobExecution jobExecution = launch(true,0);
|
||||
launch(false, jobExecution.getJobId());
|
||||
launch(false, jobExecution.getJobId());
|
||||
launch(false, jobExecution.getId());
|
||||
launch(false, jobExecution.getId());
|
||||
|
||||
int after = jdbcTemplate.queryForInt("select count(*) from BATCH_JOB_INSTANCE");
|
||||
assertEquals(before+1, after);
|
||||
|
||||
}
|
||||
|
||||
private JobExecution launch(boolean start, long jobInstanceID) throws Exception {
|
||||
private JobExecution launch(boolean start, long jobExecutionId) throws Exception {
|
||||
|
||||
if (start) {
|
||||
|
||||
Calendar c = Calendar.getInstance();
|
||||
JobParametersBuilder builder = new JobParametersBuilder();
|
||||
builder.addDate("TIMESTAMP", c.getTime());
|
||||
return jobLauncher.run(job, builder.toJobParameters());
|
||||
JobParameters jobParameters = builder.toJobParameters();
|
||||
|
||||
return jobLauncher.run(job, jobParameters);
|
||||
|
||||
} else {
|
||||
|
||||
JdbcJobInstanceDao dao = new JdbcJobInstanceDao();
|
||||
JdbcJobExecutionDao dao = new JdbcJobExecutionDao();
|
||||
dao.setJdbcTemplate(jdbcTemplate);
|
||||
JobInstance instance = dao.getJobInstance(jobInstanceID);
|
||||
if (instance != null) {
|
||||
return jobLauncher.run(job, instance.getJobParameters());
|
||||
JobExecution execution = dao.getJobExecution(jobExecutionId);
|
||||
|
||||
if (execution != null) {
|
||||
return jobLauncher.run(job, execution.getJobParameters());
|
||||
}
|
||||
|
||||
return null;
|
||||
|
||||
@@ -116,9 +116,9 @@ public class SimpleJobLauncherTests {
|
||||
testRun();
|
||||
reset(jobRepository);
|
||||
expect(jobRepository.getLastJobExecution(job.getName(), jobParameters)).andReturn(
|
||||
new JobExecution(new JobInstance(1L, jobParameters, job.getName())));
|
||||
new JobExecution(new JobInstance(1L, job.getName()), jobParameters));
|
||||
expect(jobRepository.createJobExecution(job.getName(), jobParameters)).andReturn(
|
||||
new JobExecution(new JobInstance(1L, jobParameters, job.getName())));
|
||||
new JobExecution(new JobInstance(1L, job.getName()), jobParameters));
|
||||
replay(jobRepository);
|
||||
jobLauncher.run(job, jobParameters);
|
||||
verify(jobRepository);
|
||||
@@ -147,7 +147,7 @@ public class SimpleJobLauncherTests {
|
||||
try {
|
||||
reset(jobRepository);
|
||||
expect(jobRepository.getLastJobExecution(job.getName(), jobParameters)).andReturn(
|
||||
new JobExecution(new JobInstance(1L, jobParameters, job.getName())));
|
||||
new JobExecution(new JobInstance(1L, job.getName()), jobParameters));
|
||||
replay(jobRepository);
|
||||
jobLauncher.run(job, jobParameters);
|
||||
fail("Expected JobRestartException");
|
||||
@@ -184,7 +184,7 @@ public class SimpleJobLauncherTests {
|
||||
}
|
||||
});
|
||||
|
||||
JobExecution jobExecution = new JobExecution(null, null);
|
||||
JobExecution jobExecution = new JobExecution((JobInstance) null, (JobParameters) null);
|
||||
|
||||
expect(jobRepository.getLastJobExecution(job.getName(), jobParameters)).andReturn(null);
|
||||
expect(jobRepository.createJobExecution(job.getName(), jobParameters)).andReturn(jobExecution);
|
||||
@@ -263,7 +263,7 @@ public class SimpleJobLauncherTests {
|
||||
}
|
||||
|
||||
private void run(ExitStatus exitStatus) throws Exception {
|
||||
JobExecution jobExecution = new JobExecution(null, null);
|
||||
JobExecution jobExecution = new JobExecution((JobInstance) null, (JobParameters) null);
|
||||
|
||||
expect(jobRepository.getLastJobExecution(job.getName(), jobParameters)).andReturn(null);
|
||||
expect(jobRepository.createJobExecution(job.getName(), jobParameters)).andReturn(jobExecution);
|
||||
|
||||
@@ -69,7 +69,7 @@ public class CommandLineJobRunnerTests {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
JobExecution jobExecution = new JobExecution(null, new Long(1));
|
||||
JobExecution jobExecution = new JobExecution(null, new Long(1), null);
|
||||
ExitStatus exitStatus = ExitStatus.COMPLETED;
|
||||
jobExecution.setExitStatus(exitStatus);
|
||||
StubJobLauncher.jobExecution = jobExecution;
|
||||
@@ -213,8 +213,7 @@ public class CommandLineJobRunnerTests {
|
||||
@Test
|
||||
public void testStop() throws Throwable {
|
||||
String[] args = new String[] { jobPath, "-stop", jobName };
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(3L, jobParameters, jobName));
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(3L, jobName));
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(0, StubSystemExiter.status);
|
||||
}
|
||||
@@ -222,8 +221,7 @@ public class CommandLineJobRunnerTests {
|
||||
@Test
|
||||
public void testStopFailed() throws Throwable {
|
||||
String[] args = new String[] { jobPath, "-stop", jobName };
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(0L, jobParameters, jobName));
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(0L, jobName));
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(1, StubSystemExiter.status);
|
||||
}
|
||||
@@ -231,8 +229,7 @@ public class CommandLineJobRunnerTests {
|
||||
@Test
|
||||
public void testStopFailedAndRestarted() throws Throwable {
|
||||
String[] args = new String[] { jobPath, "-stop", jobName };
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(5L, jobParameters, jobName));
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(5L, jobName));
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(0, StubSystemExiter.status);
|
||||
}
|
||||
@@ -240,8 +237,7 @@ public class CommandLineJobRunnerTests {
|
||||
@Test
|
||||
public void testStopRestarted() throws Throwable {
|
||||
String[] args = new String[] { jobPath, "-stop", jobName };
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
JobInstance jobInstance = new JobInstance(3L, jobParameters, jobName);
|
||||
JobInstance jobInstance = new JobInstance(3L, jobName);
|
||||
StubJobExplorer.jobInstances = Arrays.asList(jobInstance);
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(0, StubSystemExiter.status);
|
||||
@@ -250,8 +246,7 @@ public class CommandLineJobRunnerTests {
|
||||
@Test
|
||||
public void testAbandon() throws Throwable {
|
||||
String[] args = new String[] { jobPath, "-abandon", jobName };
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(2L, jobParameters, jobName));
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(2L, jobName));
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(0, StubSystemExiter.status);
|
||||
}
|
||||
@@ -259,8 +254,7 @@ public class CommandLineJobRunnerTests {
|
||||
@Test
|
||||
public void testAbandonRunning() throws Throwable {
|
||||
String[] args = new String[] { jobPath, "-abandon", jobName };
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(3L, jobParameters, jobName));
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(3L, jobName));
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(1, StubSystemExiter.status);
|
||||
}
|
||||
@@ -268,8 +262,7 @@ public class CommandLineJobRunnerTests {
|
||||
@Test
|
||||
public void testAbandonAbandoned() throws Throwable {
|
||||
String[] args = new String[] { jobPath, "-abandon", jobName };
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(4L, jobParameters, jobName));
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(4L, jobName));
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(1, StubSystemExiter.status);
|
||||
}
|
||||
@@ -278,17 +271,20 @@ public class CommandLineJobRunnerTests {
|
||||
public void testRestart() throws Throwable {
|
||||
String[] args = new String[] { jobPath, "-restart", jobName };
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(0L, jobParameters, jobName));
|
||||
JobInstance jobInstance = new JobInstance(0L, jobName);
|
||||
StubJobExplorer.jobInstances = Arrays.asList(jobInstance);
|
||||
StubJobExplorer.jobParameters = jobParameters;
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(0, StubSystemExiter.status);
|
||||
assertEquals(jobParameters, StubJobLauncher.jobParameters);
|
||||
StubJobExplorer.jobParameters = new JobParameters();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestartExecution() throws Throwable {
|
||||
String[] args = new String[] { jobPath, "-restart", "11" };
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(0L, jobParameters, jobName), 11L);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(0L, jobName), 11L, jobParameters);
|
||||
jobExecution.setStatus(BatchStatus.FAILED);
|
||||
StubJobExplorer.jobExecution = jobExecution;
|
||||
CommandLineJobRunner.main(args);
|
||||
@@ -300,7 +296,7 @@ public class CommandLineJobRunnerTests {
|
||||
public void testRestartExecutionNotFailed() throws Throwable {
|
||||
String[] args = new String[] { jobPath, "-restart", "11" };
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(0L, jobParameters, jobName), 11L);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(0L, jobName), 11L, jobParameters);
|
||||
jobExecution.setStatus(BatchStatus.COMPLETED);
|
||||
StubJobExplorer.jobExecution = jobExecution;
|
||||
CommandLineJobRunner.main(args);
|
||||
@@ -311,8 +307,7 @@ public class CommandLineJobRunnerTests {
|
||||
@Test
|
||||
public void testRestartNotFailed() throws Throwable {
|
||||
String[] args = new String[] { jobPath, "-restart", jobName };
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(123L, jobParameters, jobName));
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(123L, jobName));
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(1, StubSystemExiter.status);
|
||||
String errorMessage = CommandLineJobRunner.getErrorMessage();
|
||||
@@ -325,7 +320,7 @@ public class CommandLineJobRunnerTests {
|
||||
String[] args = new String[] { jobPath, "-next", jobName, "bar=foo" };
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").addString("bar", "foo")
|
||||
.toJobParameters();
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(2L, jobParameters, jobName));
|
||||
StubJobExplorer.jobInstances = Arrays.asList(new JobInstance(2L, jobName));
|
||||
CommandLineJobRunner.main(args);
|
||||
assertEquals(0, StubSystemExiter.status);
|
||||
jobParameters = new JobParametersBuilder().addString("foo", "spam").addString("bar", "foo").toJobParameters();
|
||||
@@ -416,6 +411,8 @@ public class CommandLineJobRunnerTests {
|
||||
|
||||
static JobExecution jobExecution;
|
||||
|
||||
static JobParameters jobParameters = new JobParameters();
|
||||
|
||||
@Override
|
||||
public Set<JobExecution> findRunningJobExecutions(String jobName) {
|
||||
throw new UnsupportedOperationException();
|
||||
@@ -454,7 +451,7 @@ public class CommandLineJobRunnerTests {
|
||||
}
|
||||
|
||||
private JobExecution createJobExecution(JobInstance jobInstance, BatchStatus status) {
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 1L);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 1L, jobParameters);
|
||||
jobExecution.setStatus(status);
|
||||
jobExecution.setStartTime(new Date());
|
||||
if (status != BatchStatus.STARTED) {
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
package org.springframework.batch.core.launch.support;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
@@ -113,7 +114,7 @@ public class SimpleJobOperatorTests {
|
||||
@Override
|
||||
public JobExecution run(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException,
|
||||
JobRestartException, JobInstanceAlreadyCompleteException {
|
||||
return new JobExecution(new JobInstance(123L, jobParameters, job.getName()), 999L);
|
||||
return new JobExecution(new JobInstance(123L, job.getName()), 999L, jobParameters);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -161,9 +162,9 @@ public class SimpleJobOperatorTests {
|
||||
*/
|
||||
@Test
|
||||
public void testStartNextInstanceSunnyDay() throws Exception {
|
||||
final JobParameters jobParameters = new JobParameters();
|
||||
jobExplorer.getJobInstances("foo", 0, 1);
|
||||
EasyMock.expectLastCall().andReturn(Collections.singletonList(new JobInstance(321L, jobParameters, "foo")));
|
||||
JobInstance jobInstance = new JobInstance(321L, "foo");
|
||||
expect(jobExplorer.getJobInstances("foo", 0, 1)).andReturn(Collections.singletonList(jobInstance));
|
||||
expect(jobExplorer.getJobExecutions(jobInstance)).andReturn(Collections.singletonList(new JobExecution(jobInstance, new JobParameters())));
|
||||
EasyMock.replay(jobExplorer);
|
||||
Long value = jobOperator.startNextInstance("foo");
|
||||
assertEquals(999, value.longValue());
|
||||
@@ -202,7 +203,7 @@ public class SimpleJobOperatorTests {
|
||||
jobParameters = new JobParameters();
|
||||
jobExplorer.getJobExecution(111L);
|
||||
EasyMock.expectLastCall()
|
||||
.andReturn(new JobExecution(new JobInstance(123L, jobParameters, job.getName()), 111L));
|
||||
.andReturn(new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters));
|
||||
EasyMock.replay(jobExplorer);
|
||||
Long value = jobOperator.restart(111L);
|
||||
assertEquals(999, value.longValue());
|
||||
@@ -213,7 +214,7 @@ public class SimpleJobOperatorTests {
|
||||
public void testGetSummarySunnyDay() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
jobExplorer.getJobExecution(111L);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(123L, jobParameters, job.getName()), 111L);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters);
|
||||
EasyMock.expectLastCall().andReturn(jobExecution);
|
||||
EasyMock.replay(jobExplorer);
|
||||
String value = jobOperator.getSummary(111L);
|
||||
@@ -240,7 +241,7 @@ public class SimpleJobOperatorTests {
|
||||
public void testGetStepExecutionSummariesSunnyDay() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
jobExplorer.getJobExecution(111L);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(123L, jobParameters, job.getName()), 111L);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters);
|
||||
jobExecution.createStepExecution("step1");
|
||||
jobExecution.createStepExecution("step2");
|
||||
jobExecution.getStepExecutions().iterator().next().setId(21L);
|
||||
@@ -270,7 +271,7 @@ public class SimpleJobOperatorTests {
|
||||
public void testFindRunningExecutionsSunnyDay() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
jobExplorer.findRunningJobExecutions("foo");
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(123L, jobParameters, job.getName()), 111L);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters);
|
||||
EasyMock.expectLastCall().andReturn(Collections.singleton(jobExecution));
|
||||
EasyMock.replay(jobExplorer);
|
||||
Set<Long> value = jobOperator.getRunningExecutions("foo");
|
||||
@@ -298,7 +299,7 @@ public class SimpleJobOperatorTests {
|
||||
final JobParameters jobParameters = new JobParameters();
|
||||
jobExplorer.getJobExecution(111L);
|
||||
EasyMock.expectLastCall()
|
||||
.andReturn(new JobExecution(new JobInstance(123L, jobParameters, job.getName()), 111L));
|
||||
.andReturn(new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters));
|
||||
EasyMock.replay(jobExplorer);
|
||||
String value = jobOperator.getParameters(111L);
|
||||
assertEquals("a=b", value);
|
||||
@@ -321,9 +322,8 @@ public class SimpleJobOperatorTests {
|
||||
|
||||
@Test
|
||||
public void testGetLastInstancesSunnyDay() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
jobExplorer.getJobInstances("foo", 0, 2);
|
||||
JobInstance jobInstance = new JobInstance(123L, jobParameters, job.getName());
|
||||
JobInstance jobInstance = new JobInstance(123L, job.getName());
|
||||
EasyMock.expectLastCall().andReturn(Collections.singletonList(jobInstance));
|
||||
EasyMock.replay(jobExplorer);
|
||||
List<Long> value = jobOperator.getJobInstances("foo", 0, 2);
|
||||
@@ -356,10 +356,10 @@ public class SimpleJobOperatorTests {
|
||||
|
||||
@Test
|
||||
public void testGetExecutionsSunnyDay() throws Exception {
|
||||
JobInstance jobInstance = new JobInstance(123L, jobParameters, job.getName());
|
||||
JobInstance jobInstance = new JobInstance(123L, job.getName());
|
||||
jobExplorer.getJobInstance(123L);
|
||||
EasyMock.expectLastCall().andReturn(jobInstance);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters);
|
||||
jobExplorer.getJobExecutions(jobInstance);
|
||||
EasyMock.expectLastCall().andReturn(Collections.singletonList(jobExecution));
|
||||
EasyMock.replay(jobExplorer);
|
||||
@@ -385,8 +385,8 @@ public class SimpleJobOperatorTests {
|
||||
|
||||
@Test
|
||||
public void testStop() throws Exception{
|
||||
JobInstance jobInstance = new JobInstance(123L, jobParameters, job.getName());
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L);
|
||||
JobInstance jobInstance = new JobInstance(123L, job.getName());
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters);
|
||||
jobExplorer.getJobExecution(111L);
|
||||
expectLastCall().andReturn(jobExecution);
|
||||
jobRepository.update(jobExecution);
|
||||
@@ -400,8 +400,8 @@ public class SimpleJobOperatorTests {
|
||||
|
||||
@Test
|
||||
public void testAbort() throws Exception {
|
||||
JobInstance jobInstance = new JobInstance(123L, jobParameters, job.getName());
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L);
|
||||
JobInstance jobInstance = new JobInstance(123L, job.getName());
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters);
|
||||
jobExecution.setStatus(BatchStatus.STOPPING);
|
||||
jobExplorer.getJobExecution(123L);
|
||||
expectLastCall().andReturn(jobExecution);
|
||||
@@ -414,8 +414,8 @@ public class SimpleJobOperatorTests {
|
||||
|
||||
@Test(expected = JobExecutionAlreadyRunningException.class)
|
||||
public void testAbortNonStopping() throws Exception {
|
||||
JobInstance jobInstance = new JobInstance(123L, jobParameters, job.getName());
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L);
|
||||
JobInstance jobInstance = new JobInstance(123L, job.getName());
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters);
|
||||
jobExecution.setStatus(BatchStatus.STARTED);
|
||||
jobExplorer.getJobExecution(123L);
|
||||
expectLastCall().andReturn(jobExecution);
|
||||
|
||||
@@ -82,7 +82,7 @@ public class CompositeJobExecutionListenerTests extends TestCase {
|
||||
list.add("foo");
|
||||
}
|
||||
});
|
||||
listener.beforeJob(new JobExecution(new JobInstance(new Long(11L), null, "testOpenJob")));
|
||||
listener.beforeJob(new JobExecution(new JobInstance(new Long(11L), "testOpenJob"), null));
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
|
||||
|
||||
@@ -28,7 +28,7 @@ import org.springframework.batch.core.StepExecution;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class JobParameterExecutionContextCopyListenerTests {
|
||||
|
||||
@@ -39,7 +39,7 @@ public class JobParameterExecutionContextCopyListenerTests {
|
||||
@Before
|
||||
public void createExecution() {
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
stepExecution = new StepExecution("foo", new JobExecution(new JobInstance(123L, jobParameters, "job")));
|
||||
stepExecution = new StepExecution("foo", new JobExecution(new JobInstance(123L, "job"), jobParameters));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -205,7 +205,7 @@ public class SimpleStepExecutionSplitterTests {
|
||||
jobExecution.setEndTime(new Date());
|
||||
jobRepository.update(jobExecution);
|
||||
JobInstance jobInstance = jobExecution.getJobInstance();
|
||||
jobExecution = jobRepository.createJobExecution(jobInstance.getJobName(), jobInstance.getJobParameters());
|
||||
jobExecution = jobRepository.createJobExecution(jobInstance.getJobName(), jobExecution.getJobParameters());
|
||||
}
|
||||
|
||||
stepExecution = jobExecution.createStepExecution(stepExecution.getStepName());
|
||||
|
||||
@@ -20,7 +20,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
public abstract class AbstractExecutionContextDaoTests extends AbstractTransactionalJUnit4SpringContextTests {
|
||||
|
||||
private JobInstanceDao jobInstanceDao;
|
||||
|
||||
|
||||
private JobExecutionDao jobExecutionDao;
|
||||
|
||||
private StepExecutionDao stepExecutionDao;
|
||||
@@ -39,7 +39,7 @@ public abstract class AbstractExecutionContextDaoTests extends AbstractTransacti
|
||||
contextDao = getExecutionContextDao();
|
||||
|
||||
JobInstance ji = jobInstanceDao.createJobInstance("testJob", new JobParameters());
|
||||
jobExecution = new JobExecution(ji);
|
||||
jobExecution = new JobExecution(ji, new JobParameters());
|
||||
jobExecutionDao.saveJobExecution(jobExecution);
|
||||
stepExecution = new StepExecution("stepName", jobExecution);
|
||||
stepExecutionDao.saveStepExecution(stepExecution);
|
||||
|
||||
@@ -42,7 +42,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public abstract class AbstractJobDaoTests {
|
||||
|
||||
@@ -90,7 +90,7 @@ public abstract class AbstractJobDaoTests {
|
||||
|
||||
// Create an execution
|
||||
jobExecutionStartTime = new Date(System.currentTimeMillis());
|
||||
jobExecution = new JobExecution(jobInstance);
|
||||
jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
jobExecution.setStartTime(jobExecutionStartTime);
|
||||
jobExecution.setStatus(BatchStatus.STARTED);
|
||||
jobExecutionDao.saveJobExecution(jobExecution);
|
||||
@@ -123,7 +123,6 @@ public abstract class AbstractJobDaoTests {
|
||||
JobInstance instance = jobInstanceDao.getJobInstance(jobName, jobParameters);
|
||||
assertNotNull(instance);
|
||||
assertTrue(jobInstance.equals(instance));
|
||||
assertEquals(jobParameters, instance.getJobParameters());
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@@ -156,7 +155,6 @@ public abstract class AbstractJobDaoTests {
|
||||
JobInstance instance;
|
||||
instance = jobInstanceDao.getJobInstance(scheduledJob, jobParameters);
|
||||
assertNotNull(instance);
|
||||
assertEquals(jobParameters, instance.getJobParameters());
|
||||
|
||||
instance = jobInstanceDao.getJobInstance(scheduledJob, tempProps);
|
||||
assertNull(instance);
|
||||
@@ -189,7 +187,7 @@ public abstract class AbstractJobDaoTests {
|
||||
public void testUpdateInvalidJobExecution() {
|
||||
|
||||
// id is invalid
|
||||
JobExecution execution = new JobExecution(jobInstance, (long) 29432);
|
||||
JobExecution execution = new JobExecution(jobInstance, (long) 29432, jobParameters);
|
||||
execution.incrementVersion();
|
||||
try {
|
||||
jobExecutionDao.updateJobExecution(execution);
|
||||
@@ -203,7 +201,7 @@ public abstract class AbstractJobDaoTests {
|
||||
@Transactional @Test
|
||||
public void testUpdateNullIdJobExection() {
|
||||
|
||||
JobExecution execution = new JobExecution(jobInstance);
|
||||
JobExecution execution = new JobExecution(jobInstance, jobParameters);
|
||||
try {
|
||||
jobExecutionDao.updateJobExecution(execution);
|
||||
fail();
|
||||
@@ -239,9 +237,6 @@ public abstract class AbstractJobDaoTests {
|
||||
JobInstance instance = jobInstanceDao.getJobInstance(testDefaultJob, jobParameters);
|
||||
|
||||
assertNotNull(instance);
|
||||
assertEquals(jobParameters.getString("job.key"), instance.getJobParameters().getString(
|
||||
"job.key"));
|
||||
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
@@ -252,11 +247,6 @@ public abstract class AbstractJobDaoTests {
|
||||
validateJobExecution(jobExecution, results.get(0));
|
||||
}
|
||||
|
||||
@Transactional @Test
|
||||
public void testFindJobsWithProperties() throws Exception {
|
||||
|
||||
}
|
||||
|
||||
private void validateJobExecution(JobExecution lhs, JobExecution rhs) {
|
||||
|
||||
// equals operator only checks id
|
||||
@@ -269,7 +259,7 @@ public abstract class AbstractJobDaoTests {
|
||||
|
||||
@Transactional @Test
|
||||
public void testGetLastJobExecution() {
|
||||
JobExecution lastExecution = new JobExecution(jobInstance);
|
||||
JobExecution lastExecution = new JobExecution(jobInstance, jobParameters);
|
||||
lastExecution.setStatus(BatchStatus.STARTED);
|
||||
|
||||
int JUMP_INTO_FUTURE = 1000; // makes sure start time is 'greatest'
|
||||
@@ -277,18 +267,20 @@ public abstract class AbstractJobDaoTests {
|
||||
jobExecutionDao.saveJobExecution(lastExecution);
|
||||
|
||||
assertEquals(lastExecution, jobExecutionDao.getLastJobExecution(jobInstance));
|
||||
assertNotNull(lastExecution.getJobParameters());
|
||||
assertEquals("jobKey", lastExecution.getJobParameters().getString("job.key"));
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Trying to create instance twice for the same job+parameters causes error
|
||||
*/
|
||||
@Transactional @Test
|
||||
public void testCreateDuplicateInstance() {
|
||||
|
||||
|
||||
jobParameters = new JobParameters();
|
||||
|
||||
|
||||
jobInstanceDao.createJobInstance(jobName, jobParameters);
|
||||
|
||||
|
||||
try {
|
||||
jobInstanceDao.createJobInstance(jobName, jobParameters);
|
||||
fail();
|
||||
@@ -297,35 +289,35 @@ public abstract class AbstractJobDaoTests {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Transactional @Test
|
||||
public void testCreationAddsVersion() {
|
||||
|
||||
|
||||
jobInstance = jobInstanceDao.createJobInstance("testCreationAddsVersion", new JobParameters());
|
||||
|
||||
|
||||
assertNotNull(jobInstance.getVersion());
|
||||
}
|
||||
|
||||
|
||||
@Transactional @Test
|
||||
public void testSaveAddsVersionAndId() {
|
||||
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
|
||||
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
|
||||
assertNull(jobExecution.getId());
|
||||
assertNull(jobExecution.getVersion());
|
||||
|
||||
|
||||
jobExecutionDao.saveJobExecution(jobExecution);
|
||||
|
||||
|
||||
assertNotNull(jobExecution.getId());
|
||||
assertNotNull(jobExecution.getVersion());
|
||||
}
|
||||
|
||||
|
||||
@Transactional @Test
|
||||
public void testUpdateIncrementsVersion() {
|
||||
int version = jobExecution.getVersion();
|
||||
|
||||
|
||||
jobExecutionDao.updateJobExecution(jobExecution);
|
||||
|
||||
|
||||
assertEquals(version + 1, jobExecution.getVersion().intValue());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -31,6 +31,8 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
|
||||
protected JobExecution execution;
|
||||
|
||||
protected JobParameters jobParameters;
|
||||
|
||||
/**
|
||||
* @return tested object ready for use
|
||||
*/
|
||||
@@ -48,8 +50,9 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
@Before
|
||||
public void onSetUp() throws Exception {
|
||||
dao = getJobExecutionDao();
|
||||
jobInstance = getJobInstanceDao().createJobInstance("execTestJob", new JobParameters());
|
||||
execution = new JobExecution(jobInstance);
|
||||
jobParameters = new JobParameters();
|
||||
jobInstance = getJobInstanceDao().createJobInstance("execTestJob", jobParameters);
|
||||
execution = new JobExecution(jobInstance, new JobParameters());
|
||||
}
|
||||
|
||||
/**
|
||||
@@ -81,7 +84,7 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
List<JobExecution> execs = new ArrayList<JobExecution>();
|
||||
|
||||
for (int i = 0; i < 10; i++) {
|
||||
JobExecution exec = new JobExecution(jobInstance);
|
||||
JobExecution exec = new JobExecution(jobInstance, jobParameters);
|
||||
exec.setCreateTime(new Date(i));
|
||||
execs.add(exec);
|
||||
dao.saveJobExecution(exec);
|
||||
@@ -146,10 +149,10 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
@Transactional
|
||||
@Test
|
||||
public void testGetLastExecution() {
|
||||
JobExecution exec1 = new JobExecution(jobInstance);
|
||||
JobExecution exec1 = new JobExecution(jobInstance, jobParameters);
|
||||
exec1.setCreateTime(new Date(0));
|
||||
|
||||
JobExecution exec2 = new JobExecution(jobInstance);
|
||||
JobExecution exec2 = new JobExecution(jobInstance, jobParameters);
|
||||
exec2.setCreateTime(new Date(1));
|
||||
|
||||
dao.saveJobExecution(exec1);
|
||||
@@ -176,13 +179,13 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
@Test
|
||||
public void testFindRunningExecutions() {
|
||||
|
||||
JobExecution exec = new JobExecution(jobInstance);
|
||||
JobExecution exec = new JobExecution(jobInstance, jobParameters);
|
||||
exec.setCreateTime(new Date(0));
|
||||
exec.setEndTime(new Date(1L));
|
||||
exec.setLastUpdated(new Date(5L));
|
||||
dao.saveJobExecution(exec);
|
||||
|
||||
exec = new JobExecution(jobInstance);
|
||||
exec = new JobExecution(jobInstance, jobParameters);
|
||||
exec.setLastUpdated(new Date(5L));
|
||||
exec.createStepExecution("step");
|
||||
dao.saveJobExecution(exec);
|
||||
@@ -219,7 +222,7 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
@Transactional
|
||||
@Test
|
||||
public void testGetExecution() {
|
||||
JobExecution exec = new JobExecution(jobInstance);
|
||||
JobExecution exec = new JobExecution(jobInstance, jobParameters);
|
||||
exec.setCreateTime(new Date(0));
|
||||
exec.createStepExecution("step");
|
||||
|
||||
@@ -254,10 +257,10 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
@Test
|
||||
public void testConcurrentModificationException() {
|
||||
|
||||
JobExecution exec1 = new JobExecution(jobInstance);
|
||||
JobExecution exec1 = new JobExecution(jobInstance, jobParameters);
|
||||
dao.saveJobExecution(exec1);
|
||||
|
||||
JobExecution exec2 = new JobExecution(jobInstance);
|
||||
JobExecution exec2 = new JobExecution(jobInstance, jobParameters);
|
||||
exec2.setId(exec1.getId());
|
||||
|
||||
exec2.incrementVersion();
|
||||
@@ -284,11 +287,11 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
@Test
|
||||
public void testSynchronizeStatusUpgrade() {
|
||||
|
||||
JobExecution exec1 = new JobExecution(jobInstance);
|
||||
JobExecution exec1 = new JobExecution(jobInstance, jobParameters);
|
||||
exec1.setStatus(BatchStatus.STOPPING);
|
||||
dao.saveJobExecution(exec1);
|
||||
|
||||
JobExecution exec2 = new JobExecution(jobInstance);
|
||||
JobExecution exec2 = new JobExecution(jobInstance, jobParameters);
|
||||
Assert.state(exec1.getId() != null);
|
||||
exec2.setId(exec1.getId());
|
||||
|
||||
@@ -311,11 +314,11 @@ public abstract class AbstractJobExecutionDaoTests {
|
||||
@Test
|
||||
public void testSynchronizeStatusDowngrade() {
|
||||
|
||||
JobExecution exec1 = new JobExecution(jobInstance);
|
||||
JobExecution exec1 = new JobExecution(jobInstance, jobParameters);
|
||||
exec1.setStatus(BatchStatus.STARTED);
|
||||
dao.saveJobExecution(exec1);
|
||||
|
||||
JobExecution exec2 = new JobExecution(jobInstance);
|
||||
JobExecution exec2 = new JobExecution(jobInstance, jobParameters);
|
||||
Assert.state(exec1.getId() != null);
|
||||
exec2.setId(exec1.getId());
|
||||
|
||||
|
||||
@@ -46,18 +46,10 @@ public abstract class AbstractJobInstanceDaoTests {
|
||||
JobInstance fooInstance = dao.createJobInstance(fooJob, fooParams);
|
||||
assertNotNull(fooInstance.getId());
|
||||
assertEquals(fooJob, fooInstance.getJobName());
|
||||
assertEquals(fooParams, fooInstance.getJobParameters());
|
||||
|
||||
JobInstance retrievedInstance = dao.getJobInstance(fooJob, fooParams);
|
||||
JobParameters retrievedParams = retrievedInstance.getJobParameters();
|
||||
assertEquals(fooInstance, retrievedInstance);
|
||||
assertEquals(fooJob, retrievedInstance.getJobName());
|
||||
assertEquals(fooParams, retrievedParams);
|
||||
|
||||
assertEquals(Long.MAX_VALUE, retrievedParams.getLong("longKey"));
|
||||
assertEquals(Double.MAX_VALUE, retrievedParams.getDouble("doubleKey"), 0.001);
|
||||
assertEquals("stringValue", retrievedParams.getString("stringKey"));
|
||||
assertEquals(new Date(DATE), retrievedParams.getDate("dateKey"));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -72,15 +64,10 @@ public abstract class AbstractJobInstanceDaoTests {
|
||||
JobInstance fooInstance = dao.createJobInstance(fooJob, jobParameters);
|
||||
assertNotNull(fooInstance.getId());
|
||||
assertEquals(fooJob, fooInstance.getJobName());
|
||||
assertEquals(jobParameters, fooInstance.getJobParameters());
|
||||
|
||||
JobInstance retrievedInstance = dao.getJobInstance(fooJob, jobParameters);
|
||||
JobParameters retrievedParams = retrievedInstance.getJobParameters();
|
||||
assertEquals(fooInstance, retrievedInstance);
|
||||
assertEquals(fooJob, retrievedInstance.getJobName());
|
||||
assertEquals(jobParameters, retrievedParams);
|
||||
|
||||
assertEquals(null, retrievedParams.getString("foo"));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -93,18 +80,10 @@ public abstract class AbstractJobInstanceDaoTests {
|
||||
JobInstance fooInstance = dao.createJobInstance(fooJob, fooParams);
|
||||
assertNotNull(fooInstance.getId());
|
||||
assertEquals(fooJob, fooInstance.getJobName());
|
||||
assertEquals(fooParams, fooInstance.getJobParameters());
|
||||
|
||||
JobInstance retrievedInstance = dao.getJobInstance(fooInstance.getId());
|
||||
JobParameters retrievedParams = retrievedInstance.getJobParameters();
|
||||
assertEquals(fooInstance, retrievedInstance);
|
||||
assertEquals(fooJob, retrievedInstance.getJobName());
|
||||
assertEquals(fooParams, retrievedParams);
|
||||
|
||||
assertEquals(Long.MAX_VALUE, retrievedParams.getLong("longKey"));
|
||||
assertEquals(Double.MAX_VALUE, retrievedParams.getDouble("doubleKey"), 0.001);
|
||||
assertEquals("stringValue", retrievedParams.getString("stringKey"));
|
||||
assertEquals(new Date(DATE), retrievedParams.getDate("dateKey"));
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -180,7 +159,7 @@ public abstract class AbstractJobInstanceDaoTests {
|
||||
JobParameters params = new JobParametersBuilder().addLong(paramKey, Long.valueOf(i)).toJobParameters();
|
||||
dao.createJobInstance(multiInstanceJob, params);
|
||||
}
|
||||
|
||||
|
||||
|
||||
int startIndex = 3;
|
||||
int queryCount = 2;
|
||||
@@ -192,9 +171,9 @@ public abstract class AbstractJobInstanceDaoTests {
|
||||
JobInstance returnedInstance = jobInstances.get(i);
|
||||
assertEquals(multiInstanceJob, returnedInstance.getJobName());
|
||||
assertEquals(Integer.valueOf(0), returnedInstance.getVersion());
|
||||
|
||||
|
||||
//checks the correct instances are returned and the order is descending
|
||||
assertEquals(instanceCount - startIndex - i , returnedInstance.getJobParameters().getLong(paramKey));
|
||||
// assertEquals(instanceCount - startIndex - i , returnedInstance.getJobParameters().getLong(paramKey));
|
||||
}
|
||||
|
||||
}
|
||||
@@ -241,7 +220,7 @@ public abstract class AbstractJobInstanceDaoTests {
|
||||
@Test
|
||||
public void testCreationAddsVersion() {
|
||||
|
||||
JobInstance jobInstance = new JobInstance((long) 1, new JobParameters(), "testVersionAndId");
|
||||
JobInstance jobInstance = new JobInstance((long) 1, "testVersionAndId");
|
||||
|
||||
assertNull(jobInstance.getVersion());
|
||||
|
||||
|
||||
@@ -40,7 +40,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Tests for {@link StepExecutionDao} implementations.
|
||||
*
|
||||
*
|
||||
* @see #getStepExecutionDao()
|
||||
*/
|
||||
public abstract class AbstractStepExecutionDaoTests extends AbstractTransactionalJUnit4SpringContextTests {
|
||||
@@ -139,7 +139,7 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona
|
||||
@Transactional
|
||||
@Test
|
||||
public void testGetForNotExistingJobExecution() {
|
||||
assertNull(dao.getStepExecution(new JobExecution(jobInstance, (long) 777), 11L));
|
||||
assertNull(dao.getStepExecution(new JobExecution(jobInstance, (long) 777, new JobParameters()), 11L));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -74,7 +74,7 @@ public class JdbcJobDaoQueryTests extends TestCase {
|
||||
return 1;
|
||||
}
|
||||
});
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(new Long(11), new JobParameters(), "testJob"));
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(new Long(11), "testJob"), new JobParameters());
|
||||
|
||||
jobExecutionDao.saveJobExecution(jobExecution);
|
||||
assertEquals(1, list.size());
|
||||
|
||||
@@ -23,7 +23,7 @@ public class JdbcJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
|
||||
private JobInstanceDao jobInstanceDao;
|
||||
|
||||
private JdbcTemplate jdbcTemplate;
|
||||
|
||||
|
||||
@Autowired
|
||||
public void setDataSource(DataSource dataSource) {
|
||||
jdbcTemplate = new JdbcTemplate(dataSource);
|
||||
@@ -36,9 +36,9 @@ public class JdbcJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
|
||||
|
||||
@Override
|
||||
protected JobExecutionDao getJobExecutionDao() {
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT",
|
||||
"BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION", "BATCH_JOB_PARAMS",
|
||||
"BATCH_JOB_INSTANCE");
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT",
|
||||
"BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION", "BATCH_JOB_EXECUTION_PARAMS",
|
||||
"BATCH_JOB_INSTANCE");
|
||||
return jobExecutionDao;
|
||||
}
|
||||
|
||||
|
||||
@@ -12,7 +12,6 @@ import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -41,78 +40,24 @@ public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests {
|
||||
protected JobInstanceDao getJobInstanceDao() {
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT",
|
||||
"BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION",
|
||||
"BATCH_JOB_EXECUTION", "BATCH_JOB_PARAMS", "BATCH_JOB_INSTANCE");
|
||||
"BATCH_JOB_EXECUTION", "BATCH_JOB_EXECUTION_PARAMS", "BATCH_JOB_INSTANCE");
|
||||
return jobInstanceDao;
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testNullStringParameter() throws Exception {
|
||||
|
||||
JobInstance jobInstance = dao.createJobInstance("testInstance",
|
||||
new JobParametersBuilder().addString("foo", null).toJobParameters());
|
||||
|
||||
JobInstance retrievedInstance = dao.getJobInstance(jobInstance.getId());
|
||||
JobParameters retrievedParams = retrievedInstance.getJobParameters();
|
||||
assertEquals(null, retrievedParams.getString("foo"));
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testFindJobInstanceByExecution() {
|
||||
|
||||
JobParameters jobParameters = new JobParameters();
|
||||
JobInstance jobInstance = dao.createJobInstance("testInstance",
|
||||
new JobParameters());
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 2L);
|
||||
jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 2L, jobParameters);
|
||||
jobExecutionDao.saveJobExecution(jobExecution);
|
||||
|
||||
JobInstance returnedInstance = dao.getJobInstance(jobExecution);
|
||||
assertEquals(jobInstance, returnedInstance);
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testCreateJobKey() {
|
||||
|
||||
JdbcJobInstanceDao jdbcDao = (JdbcJobInstanceDao) dao;
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString(
|
||||
"foo", "bar").addString("bar", "foo").toJobParameters();
|
||||
String key = jdbcDao.createJobKey(jobParameters);
|
||||
assertEquals(32, key.length());
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testCreateJobKeyWithNullParameter() {
|
||||
|
||||
JdbcJobInstanceDao jdbcDao = (JdbcJobInstanceDao) dao;
|
||||
JobParameters jobParameters1 = new JobParametersBuilder().addString(
|
||||
"foo", "bar").addString("bar", null).toJobParameters();
|
||||
JobParameters jobParameters2 = new JobParametersBuilder().addString(
|
||||
"foo", "bar").addString("bar", "").toJobParameters();
|
||||
String key1 = jdbcDao.createJobKey(jobParameters1);
|
||||
String key2 = jdbcDao.createJobKey(jobParameters2);
|
||||
assertEquals(key1, key2);
|
||||
|
||||
}
|
||||
|
||||
@Transactional
|
||||
@Test
|
||||
public void testCreateJobKeyOrdering() {
|
||||
|
||||
JdbcJobInstanceDao jdbcDao = (JdbcJobInstanceDao) dao;
|
||||
JobParameters jobParameters1 = new JobParametersBuilder().addString(
|
||||
"foo", "bar").addString("bar", "foo").toJobParameters();
|
||||
String key1 = jdbcDao.createJobKey(jobParameters1);
|
||||
JobParameters jobParameters2 = new JobParametersBuilder().addString(
|
||||
"bar", "foo").addString("foo", "bar").toJobParameters();
|
||||
String key2 = jdbcDao.createJobKey(jobParameters2);
|
||||
assertEquals(key1, key2);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testHexing() throws Exception {
|
||||
MessageDigest digest = MessageDigest.getInstance("MD5");
|
||||
|
||||
@@ -23,7 +23,7 @@ public class JdbcStepExecutionDaoTests extends AbstractStepExecutionDaoTests {
|
||||
@Override
|
||||
protected JobRepository getJobRepository() {
|
||||
deleteFromTables("BATCH_JOB_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION",
|
||||
"BATCH_JOB_PARAMS", "BATCH_JOB_INSTANCE");
|
||||
"BATCH_JOB_EXECUTION_PARAMS", "BATCH_JOB_INSTANCE");
|
||||
return (JobRepository) applicationContext.getBean("jobRepository");
|
||||
}
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class MapJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
|
||||
@Test
|
||||
public void testPersistentCopy() {
|
||||
JobExecutionDao tested = new MapJobExecutionDao();
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance((long) 1, new JobParameters(), "mapJob"));
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance((long) 1, "mapJob"), new JobParameters());
|
||||
|
||||
assertNull(jobExecution.getStartTime());
|
||||
tested.saveJobExecution(jobExecution);
|
||||
@@ -71,7 +71,7 @@ public class MapJobExecutionDaoTests extends AbstractJobExecutionDaoTests {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance((long) -1, new JobParameters(), "mapJob"));
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance((long) -1, "mapJob"), new JobParameters());
|
||||
latch.await();
|
||||
tested.saveJobExecution(jobExecution);
|
||||
ids.add(jobExecution.getId());
|
||||
|
||||
@@ -14,6 +14,7 @@ import org.springframework.batch.core.job.JobSupport;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.annotation.DirtiesContext;
|
||||
import org.springframework.test.annotation.DirtiesContext.ClassMode;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
@@ -25,6 +26,7 @@ import org.springframework.transaction.annotation.Transactional;
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration
|
||||
@DirtiesContext(classMode=ClassMode.AFTER_EACH_TEST_METHOD)
|
||||
public class SimpleJobRepositoryProxyTests {
|
||||
|
||||
@Autowired
|
||||
@@ -37,7 +39,6 @@ public class SimpleJobRepositoryProxyTests {
|
||||
|
||||
@Transactional
|
||||
@Test(expected=IllegalStateException.class)
|
||||
@DirtiesContext
|
||||
public void testCreateAndFindWithExistingTransaction() throws Exception {
|
||||
assertFalse(advice.invoked);
|
||||
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
|
||||
@@ -46,7 +47,6 @@ public class SimpleJobRepositoryProxyTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
@DirtiesContext
|
||||
public void testCreateAndFindNoTransaction() throws Exception {
|
||||
assertFalse(advice.invoked);
|
||||
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
|
||||
|
||||
@@ -16,8 +16,13 @@
|
||||
|
||||
package org.springframework.batch.core.repository.support;
|
||||
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.junit.Assert.*;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
@@ -43,9 +48,9 @@ import org.springframework.batch.core.step.StepSupport;
|
||||
* Test SimpleJobRepository. The majority of test cases are tested using
|
||||
* EasyMock, however, there were some issues with using it for the stepExecutionDao when
|
||||
* testing finding or creating steps, so an actual mock class had to be written.
|
||||
*
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SimpleJobRepositoryTests {
|
||||
|
||||
@@ -58,13 +63,13 @@ public class SimpleJobRepositoryTests {
|
||||
Step stepConfiguration1;
|
||||
|
||||
Step stepConfiguration2;
|
||||
|
||||
|
||||
JobExecutionDao jobExecutionDao;
|
||||
|
||||
|
||||
JobInstanceDao jobInstanceDao;
|
||||
|
||||
StepExecutionDao stepExecutionDao;
|
||||
|
||||
|
||||
ExecutionContextDao ecDao;
|
||||
|
||||
JobInstance jobInstance;
|
||||
@@ -74,7 +79,7 @@ public class SimpleJobRepositoryTests {
|
||||
String databaseStep2;
|
||||
|
||||
List<String> steps;
|
||||
|
||||
|
||||
JobExecution jobExecution;
|
||||
|
||||
@Before
|
||||
@@ -103,7 +108,7 @@ public class SimpleJobRepositoryTests {
|
||||
|
||||
job.setSteps(stepConfigurations);
|
||||
|
||||
jobInstance = new JobInstance(1L, jobParameters, job.getName());
|
||||
jobInstance = new JobInstance(1L, job.getName());
|
||||
|
||||
databaseStep1 = "dbStep1";
|
||||
databaseStep2 = "dbStep2";
|
||||
@@ -112,14 +117,14 @@ public class SimpleJobRepositoryTests {
|
||||
steps.add(databaseStep1);
|
||||
steps.add(databaseStep2);
|
||||
|
||||
jobExecution = new JobExecution(new JobInstance(1L, jobParameters, job.getName()), 1L);
|
||||
jobExecution = new JobExecution(new JobInstance(1L, job.getName()), 1L, jobParameters);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSaveOrUpdateInvalidJobExecution() {
|
||||
|
||||
// failure scenario - must have job ID
|
||||
JobExecution jobExecution = new JobExecution(null, null);
|
||||
JobExecution jobExecution = new JobExecution((JobInstance) null, (JobParameters) null);
|
||||
try {
|
||||
jobRepository.update(jobExecution);
|
||||
fail();
|
||||
@@ -132,13 +137,13 @@ public class SimpleJobRepositoryTests {
|
||||
@Test
|
||||
public void testUpdateValidJobExecution() throws Exception {
|
||||
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(1L, jobParameters, job.getName()), 1L);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(1L, job.getName()), 1L, jobParameters);
|
||||
// new execution - call update on job dao
|
||||
jobExecutionDao.updateJobExecution(jobExecution);
|
||||
replay(jobExecutionDao);
|
||||
jobRepository.update(jobExecution);
|
||||
verify(jobExecutionDao);
|
||||
|
||||
|
||||
assertNotNull(jobExecution.getLastUpdated());
|
||||
}
|
||||
|
||||
@@ -156,45 +161,45 @@ public class SimpleJobRepositoryTests {
|
||||
// expected
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testSaveStepExecutionSetsLastUpdated(){
|
||||
|
||||
|
||||
StepExecution stepExecution = new StepExecution("stepName", jobExecution);
|
||||
|
||||
long before = System.currentTimeMillis();
|
||||
|
||||
|
||||
long before = System.currentTimeMillis();
|
||||
|
||||
jobRepository.add(stepExecution);
|
||||
|
||||
|
||||
assertNotNull(stepExecution.getLastUpdated());
|
||||
|
||||
|
||||
long lastUpdated = stepExecution.getLastUpdated().getTime();
|
||||
assertTrue(lastUpdated > (before - 1000));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testUpdateStepExecutionSetsLastUpdated(){
|
||||
|
||||
|
||||
StepExecution stepExecution = new StepExecution("stepName", jobExecution);
|
||||
stepExecution.setId(2343L);
|
||||
|
||||
long before = System.currentTimeMillis();
|
||||
|
||||
|
||||
long before = System.currentTimeMillis();
|
||||
|
||||
jobRepository.update(stepExecution);
|
||||
|
||||
|
||||
assertNotNull(stepExecution.getLastUpdated());
|
||||
|
||||
|
||||
long lastUpdated = stepExecution.getLastUpdated().getTime();
|
||||
assertTrue(lastUpdated > (before - 1000));
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testInterrupted(){
|
||||
|
||||
|
||||
jobExecution.setStatus(BatchStatus.STOPPING);
|
||||
StepExecution stepExecution = new StepExecution("stepName", jobExecution);
|
||||
stepExecution.setId(323L);
|
||||
|
||||
|
||||
jobRepository.update(stepExecution);
|
||||
assertTrue(stepExecution.isTerminateOnly());
|
||||
}
|
||||
|
||||
@@ -53,8 +53,8 @@ public class StepExecutionSimpleCompletionPolicyTests extends TestCase {
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
JobParameters jobParameters = new JobParametersBuilder().addLong("commit.interval", 2L).toJobParameters();
|
||||
jobInstance = new JobInstance(new Long(0), jobParameters, "testJob");
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
jobInstance = new JobInstance(new Long(0), "testJob");
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
Step step = new StepSupport("bar");
|
||||
stepExecution = jobExecution.createStepExecution(step.getName());
|
||||
policy.beforeStep(stepExecution);
|
||||
|
||||
@@ -30,13 +30,13 @@ import org.springframework.batch.core.JobParameters;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class ChunkContextTests {
|
||||
|
||||
private ChunkContext context = new ChunkContext(new StepContext(new JobExecution(new JobInstance(0L,
|
||||
new JobParameters(Collections.singletonMap("foo", new JobParameter("bar"))), "job"), 1L)
|
||||
.createStepExecution("foo")));
|
||||
"job"), 1L, new JobParameters(Collections.singletonMap("foo", new JobParameter("bar"))))
|
||||
.createStepExecution("foo")));
|
||||
|
||||
@Test
|
||||
public void testGetStepContext() {
|
||||
@@ -49,7 +49,7 @@ public class ChunkContextTests {
|
||||
public void testIsComplete() {
|
||||
assertFalse(context.isComplete());
|
||||
context.setComplete();
|
||||
assertTrue(context.isComplete());
|
||||
assertTrue(context.isComplete());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -40,7 +40,7 @@ public class StepContextTests {
|
||||
|
||||
private List<String> list = new ArrayList<String>();
|
||||
|
||||
private StepExecution stepExecution = new StepExecution("step", new JobExecution(new JobInstance(2L, null, "job"), 0L), 1L);
|
||||
private StepExecution stepExecution = new StepExecution("step", new JobExecution(new JobInstance(2L, "job"), 0L, null), 1L);
|
||||
|
||||
private StepContext context = new StepContext(stepExecution);
|
||||
|
||||
@@ -169,8 +169,9 @@ public class StepContextTests {
|
||||
@Test
|
||||
public void testJobParameters() throws Exception {
|
||||
JobParameters jobParameters = new JobParametersBuilder().addString("foo", "bar").toJobParameters();
|
||||
JobInstance jobInstance = new JobInstance(0L, jobParameters, "foo");
|
||||
stepExecution.getJobExecution().setJobInstance(jobInstance);
|
||||
JobInstance instance = stepExecution.getJobExecution().getJobInstance();
|
||||
stepExecution = new StepExecution("step", new JobExecution(instance, jobParameters));
|
||||
context = new StepContext(stepExecution);
|
||||
assertEquals("bar", context.getJobParameters().get("foo"));
|
||||
}
|
||||
|
||||
|
||||
@@ -32,8 +32,8 @@ public class JobRepositorySupport implements JobRepository {
|
||||
*/
|
||||
@Override
|
||||
public JobExecution createJobExecution(String jobName, JobParameters jobParameters) {
|
||||
JobInstance jobInstance = new JobInstance(0L, jobParameters, jobName);
|
||||
return new JobExecution(jobInstance, 11L);
|
||||
JobInstance jobInstance = new JobInstance(0L, jobName);
|
||||
return new JobExecution(jobInstance, 11L, jobParameters);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
|
||||
@@ -34,8 +34,7 @@ public class NoWorkFoundStepExecutionListenerTests {
|
||||
|
||||
@Test
|
||||
public void noWork() {
|
||||
StepExecution stepExecution = new StepExecution("NoProcessingStep", new JobExecution(new JobInstance(1L,
|
||||
new JobParameters(), "NoProcessingJob")));
|
||||
StepExecution stepExecution = new StepExecution("NoProcessingStep", new JobExecution(new JobInstance(1L, "NoProcessingJob"), new JobParameters()));
|
||||
|
||||
stepExecution.setExitStatus(ExitStatus.COMPLETED);
|
||||
stepExecution.setReadCount(0);
|
||||
@@ -47,7 +46,7 @@ public class NoWorkFoundStepExecutionListenerTests {
|
||||
@Test
|
||||
public void workDone() {
|
||||
StepExecution stepExecution = new StepExecution("NoProcessingStep", new JobExecution(new JobInstance(1L,
|
||||
new JobParameters(), "NoProcessingJob")));
|
||||
"NoProcessingJob"), new JobParameters()));
|
||||
|
||||
stepExecution.setReadCount(1);
|
||||
|
||||
|
||||
@@ -39,7 +39,7 @@ public class NonAbstractStepTests {
|
||||
final List<String> events = new ArrayList<String>();
|
||||
|
||||
final StepExecution execution = new StepExecution(tested.getName(), new JobExecution(new JobInstance(1L,
|
||||
new JobParameters(), "jobName")));
|
||||
"jobName"), new JobParameters()));
|
||||
|
||||
/**
|
||||
* Fills the events list when abstract methods are called.
|
||||
|
||||
@@ -54,7 +54,7 @@ public class ChunkOrientedTaskletTests {
|
||||
}
|
||||
});
|
||||
StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(new JobInstance(
|
||||
123L, new JobParameters(), "job"))));
|
||||
123L, "job"),new JobParameters())));
|
||||
handler.execute(contribution, context);
|
||||
assertEquals(1, contribution.getReadCount());
|
||||
assertEquals(1, contribution.getWriteCount());
|
||||
@@ -77,7 +77,7 @@ public class ChunkOrientedTaskletTests {
|
||||
}
|
||||
});
|
||||
StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(new JobInstance(
|
||||
123L, new JobParameters(), "job"))));
|
||||
123L, "job"), new JobParameters())));
|
||||
try {
|
||||
handler.execute(contribution, context);
|
||||
fail("Expected RuntimeException");
|
||||
@@ -108,7 +108,7 @@ public class ChunkOrientedTaskletTests {
|
||||
}
|
||||
});
|
||||
StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(new JobInstance(
|
||||
123L, new JobParameters(), "job"))));
|
||||
123L, "job"), new JobParameters())));
|
||||
ExitStatus expected = contribution.getExitStatus();
|
||||
handler.execute(contribution, context);
|
||||
// The tasklet does not change the exit code
|
||||
|
||||
@@ -24,7 +24,7 @@ public class FaultTolerantChunkProviderTests {
|
||||
private FaultTolerantChunkProvider<String> provider;
|
||||
|
||||
private StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(
|
||||
new JobInstance(123L, new JobParameters(), "job"))));
|
||||
new JobInstance(123L, "job"), new JobParameters())));
|
||||
|
||||
@Test
|
||||
public void testProvide() throws Exception {
|
||||
|
||||
@@ -66,8 +66,8 @@ public class FaultTolerantStepFactoryBeanNonBufferingTests {
|
||||
factory.setSkipLimit(2);
|
||||
factory.setIsReaderTransactionalQueue(true);
|
||||
|
||||
JobInstance jobInstance = new JobInstance(new Long(1), new JobParameters(), "skipJob");
|
||||
jobExecution = new JobExecution(jobInstance);
|
||||
JobInstance jobInstance = new JobInstance(new Long(1), "skipJob");
|
||||
jobExecution = new JobExecution(jobInstance, new JobParameters());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -178,11 +178,6 @@ public class FaultTolerantStepFactoryBeanRetryTests {
|
||||
jobExecution);
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
// System.out.println(stepExecution.getWriteCount());
|
||||
// System.out.println(stepExecution.getSkipCount());
|
||||
// System.out.println(processed.size());
|
||||
// System.out.println(processed);
|
||||
// System.out.println(written);
|
||||
/*
|
||||
* Each chunk tried up to RETRY_LIMIT, then the scan processes each item
|
||||
* once, identfiying the skip as it goes
|
||||
@@ -230,7 +225,6 @@ public class FaultTolerantStepFactoryBeanRetryTests {
|
||||
jobExecution);
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
// System.out.println(processed);
|
||||
assertEquals(ExitStatus.COMPLETED.getExitCode(), stepExecution
|
||||
.getExitStatus().getExitCode());
|
||||
/*
|
||||
@@ -278,10 +272,6 @@ public class FaultTolerantStepFactoryBeanRetryTests {
|
||||
jobExecution);
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
// System.out.println(stepExecution.getWriteCount());
|
||||
// System.out.println(processed.size());
|
||||
// System.out.println(processed);
|
||||
// System.out.println(written);
|
||||
assertEquals(3, processed.size()); // Initial try only, then cached
|
||||
}
|
||||
|
||||
|
||||
@@ -44,7 +44,7 @@ public class RepeatOperationsStepFactoryBeanTests extends TestCase {
|
||||
|
||||
private List<String> list;
|
||||
|
||||
private JobExecution jobExecution = new JobExecution(new JobInstance(0L, new JobParameters(), "job"));
|
||||
private JobExecution jobExecution = new JobExecution(new JobInstance(0L, "job"), new JobParameters());
|
||||
|
||||
@Override
|
||||
protected void setUp() throws Exception {
|
||||
|
||||
@@ -38,7 +38,7 @@ public class SimpleChunkProcessorTests {
|
||||
});
|
||||
|
||||
private StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(
|
||||
new JobInstance(123L, new JobParameters(), "job"))));
|
||||
new JobInstance(123L, "job"), new JobParameters())));
|
||||
|
||||
private List<String> list = new ArrayList<String>();
|
||||
|
||||
|
||||
@@ -19,7 +19,7 @@ public class SimpleChunkProviderTests {
|
||||
private SimpleChunkProvider<String> provider;
|
||||
|
||||
private StepContribution contribution = new StepContribution(new StepExecution("foo", new JobExecution(
|
||||
new JobInstance(123L, new JobParameters(), "job"))));
|
||||
new JobInstance(123L, "job"), new JobParameters())));
|
||||
|
||||
@Test
|
||||
public void testProvide() throws Exception {
|
||||
@@ -36,7 +36,7 @@ public class SimpleChunkProviderTests {
|
||||
new RepeatTemplate()) {
|
||||
@Override
|
||||
protected String read(StepContribution contribution, Chunk<String> chunk) throws SkipOverflowException,
|
||||
Exception {
|
||||
Exception {
|
||||
chunk.skip(new RuntimeException("Planned"));
|
||||
throw new SkipOverflowException("Overflow");
|
||||
}
|
||||
|
||||
@@ -39,7 +39,7 @@ public class SkipWrapperTests {
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for {@link org.springframework.batch.core.step.item.SkipWrapper#SkipWrapper(java.lang.Object, java.lang.Exception)}.
|
||||
* Test method for {@link org.springframework.batch.core.step.item.SkipWrapper#SkipWrapper(java.lang.Object, java.lang.Throwable)}.
|
||||
*/
|
||||
@Test
|
||||
public void testItemWrapperTException() {
|
||||
|
||||
@@ -67,8 +67,8 @@ public class TaskletStepExceptionTests {
|
||||
taskletStep.setJobRepository(jobRepository);
|
||||
taskletStep.setTransactionManager(new ResourcelessTransactionManager());
|
||||
|
||||
JobInstance jobInstance = new JobInstance(1L, new JobParameters(), "testJob");
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
JobInstance jobInstance = new JobInstance(1L, "testJob");
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, new JobParameters());
|
||||
stepExecution = new StepExecution("testStep", jobExecution);
|
||||
}
|
||||
|
||||
|
||||
@@ -15,7 +15,7 @@
|
||||
*/
|
||||
package org.springframework.batch.core.step.job;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.Date;
|
||||
@@ -33,7 +33,7 @@ import org.springframework.batch.support.PropertiesConverter;
|
||||
*
|
||||
*/
|
||||
public class DefaultJobParametersExtractorJobParametersTests {
|
||||
|
||||
|
||||
private DefaultJobParametersExtractor extractor = new DefaultJobParametersExtractor();
|
||||
|
||||
@Test
|
||||
@@ -43,7 +43,7 @@ public class DefaultJobParametersExtractorJobParametersTests {
|
||||
JobParameters jobParameters = extractor.getJobParameters(null, stepExecution);
|
||||
assertEquals("{foo=bar}", jobParameters.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetAllJobParameters() throws Exception {
|
||||
StepExecution stepExecution = getStepExecution("foo=bar,spam=bucket");
|
||||
@@ -51,7 +51,7 @@ public class DefaultJobParametersExtractorJobParametersTests {
|
||||
JobParameters jobParameters = extractor.getJobParameters(null, stepExecution);
|
||||
assertEquals("{spam=bucket, foo=bar}", jobParameters.toString());
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetNamedLongStringParameters() throws Exception {
|
||||
StepExecution stepExecution = getStepExecution("foo=bar");
|
||||
@@ -100,7 +100,7 @@ public class DefaultJobParametersExtractorJobParametersTests {
|
||||
*/
|
||||
private StepExecution getStepExecution(String parameters) {
|
||||
JobParameters jobParameters = new DefaultJobParametersConverter().getJobParameters(PropertiesConverter.stringToProperties(parameters));
|
||||
return new StepExecution("step", new JobExecution(new JobInstance(1L, jobParameters, "job")));
|
||||
return new StepExecution("step", new JobExecution(new JobInstance(1L, "job"), jobParameters));
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.batch.item.ExecutionContext;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class JobStepTests {
|
||||
|
||||
@@ -143,7 +143,7 @@ public class JobStepTests {
|
||||
step.setJob(new JobSupport("child") {
|
||||
@Override
|
||||
public void execute(JobExecution execution) throws UnexpectedJobExecutionException {
|
||||
assertEquals(1, execution.getJobInstance().getJobParameters().getParameters().size());
|
||||
assertEquals(1, execution.getJobParameters().getParameters().size());
|
||||
execution.setStatus(BatchStatus.FAILED);
|
||||
execution.setEndTime(new Date());
|
||||
jobRepository.update(execution);
|
||||
@@ -160,11 +160,11 @@ public class JobStepTests {
|
||||
JobExecution jobExecution = stepExecution.getJobExecution();
|
||||
jobExecution.setEndTime(new Date());
|
||||
jobRepository.update(jobExecution);
|
||||
|
||||
|
||||
jobExecution = jobRepository.createJobExecution("job", new JobParameters());
|
||||
stepExecution = jobExecution.createStepExecution("step");
|
||||
// In a restart the surrounding Job would set up the context like this...
|
||||
stepExecution.setExecutionContext(executionContext);
|
||||
stepExecution.setExecutionContext(executionContext);
|
||||
jobRepository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
assertEquals("FOO", stepExecution.getFailureExceptions().get(0).getMessage());
|
||||
|
||||
@@ -113,7 +113,6 @@ public class AsyncChunkOrientedStepIntegrationTests {
|
||||
repeatTemplate.setTaskExecutor(new SimpleAsyncTaskExecutor());
|
||||
step.setStepOperations(repeatTemplate);
|
||||
step.setTransactionManager(transactionManager);
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -134,11 +133,10 @@ public class AsyncChunkOrientedStepIntegrationTests {
|
||||
jobRepository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
|
||||
dataSource.setMaxActive(2);
|
||||
StepExecution lastStepExecution = jobRepository.getLastStepExecution(jobExecution.getJobInstance(), step
|
||||
.getName());
|
||||
assertEquals(lastStepExecution, stepExecution);
|
||||
assertFalse(lastStepExecution == stepExecution);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -25,19 +25,18 @@ import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepContribution;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.step.tasklet.MethodInvokingTaskletAdapter;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
*/
|
||||
public class StepHandlerAdapterTests {
|
||||
|
||||
|
||||
private MethodInvokingTaskletAdapter tasklet = new MethodInvokingTaskletAdapter();
|
||||
private Object result = null;
|
||||
|
||||
|
||||
private StepExecution stepExecution = new StepExecution("systemCommandStep", new JobExecution(new JobInstance(1L,
|
||||
new JobParameters(), "systemCommandJob")));
|
||||
"systemCommandJob"), new JobParameters()));
|
||||
|
||||
public ExitStatus execute() {
|
||||
return ExitStatus.NOOP;
|
||||
|
||||
@@ -31,7 +31,7 @@ public class SystemCommandTaskletIntegrationTests {
|
||||
private SystemCommandTasklet tasklet = new SystemCommandTasklet();
|
||||
|
||||
private StepExecution stepExecution = new StepExecution("systemCommandStep", new JobExecution(new JobInstance(1L,
|
||||
new JobParameters(), "systemCommandJob")));
|
||||
"systemCommandJob"), new JobParameters()));
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
|
||||
@@ -85,6 +85,8 @@ public class TaskletStepTests {
|
||||
|
||||
private JobInstance jobInstance;
|
||||
|
||||
private JobParameters jobParameters;
|
||||
|
||||
private ResourcelessTransactionManager transactionManager;
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@@ -125,7 +127,8 @@ public class TaskletStepTests {
|
||||
step.setStepOperations(template);
|
||||
|
||||
job = new JobSupport("FOO");
|
||||
jobInstance = new JobInstance(0L, new JobParameters(), job.getName());
|
||||
jobInstance = new JobInstance(0L, job.getName());
|
||||
jobParameters = new JobParameters();
|
||||
|
||||
step.setTransactionManager(transactionManager);
|
||||
|
||||
@@ -133,7 +136,7 @@ public class TaskletStepTests {
|
||||
|
||||
@Test
|
||||
public void testStepExecutor() throws Exception {
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
step.execute(stepExecution);
|
||||
assertEquals(1, processed.size());
|
||||
@@ -143,7 +146,7 @@ public class TaskletStepTests {
|
||||
|
||||
@Test
|
||||
public void testCommitCount_Even() throws Exception {
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
step = getStep(new String[] { "foo", "bar", "spam", "eggs" }, 2);
|
||||
step.setTransactionManager(transactionManager);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
@@ -156,7 +159,7 @@ public class TaskletStepTests {
|
||||
|
||||
@Test
|
||||
public void testCommitCount_Uneven() throws Exception {
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
step = getStep(new String[] { "foo", "bar", "spam" }, 2);
|
||||
step.setTransactionManager(transactionManager);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
@@ -169,7 +172,7 @@ public class TaskletStepTests {
|
||||
|
||||
@Test
|
||||
public void testEmptyReader() throws Exception {
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
step = getStep(new String[0]);
|
||||
step.setTasklet(new TestingChunkOrientedTasklet<String>(getReader(new String[0]), itemWriter,
|
||||
@@ -190,7 +193,7 @@ public class TaskletStepTests {
|
||||
@Test
|
||||
public void testStepExecutionUpdates() throws Exception {
|
||||
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
|
||||
step.setStepOperations(new RepeatTemplate());
|
||||
@@ -211,7 +214,7 @@ public class TaskletStepTests {
|
||||
@Test
|
||||
public void testStepExecutionUpdateFailure() throws Exception {
|
||||
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
|
||||
JobRepository repository = new JobRepositoryFailedUpdateStub();
|
||||
@@ -230,7 +233,7 @@ public class TaskletStepTests {
|
||||
new MapStepExecutionDao(), new MapExecutionContextDao());
|
||||
step.setJobRepository(repository);
|
||||
|
||||
JobExecution jobExecution = repository.createJobExecution(job.getName(), jobInstance.getJobParameters());
|
||||
JobExecution jobExecution = repository.createJobExecution(job.getName(), jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
repository.add(stepExecution);
|
||||
step.execute(stepExecution);
|
||||
@@ -250,7 +253,7 @@ public class TaskletStepTests {
|
||||
};
|
||||
|
||||
step.setTasklet(new TestingChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
try {
|
||||
@@ -276,7 +279,7 @@ public class TaskletStepTests {
|
||||
};
|
||||
|
||||
step.setTasklet(new TestingChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
try {
|
||||
@@ -308,7 +311,7 @@ public class TaskletStepTests {
|
||||
return ExitStatus.FAILED.addExitDescription("FOO");
|
||||
}
|
||||
});
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
try {
|
||||
@@ -331,7 +334,7 @@ public class TaskletStepTests {
|
||||
MockRestartableItemReader tasklet = new MockRestartableItemReader();
|
||||
step.setTasklet(new TestingChunkOrientedTasklet<String>(tasklet, itemWriter));
|
||||
step.registerStream(tasklet);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
step.execute(stepExecution);
|
||||
@@ -342,7 +345,7 @@ public class TaskletStepTests {
|
||||
|
||||
@Test
|
||||
public void testSuccessfulExecutionWithExecutionContext() throws Exception {
|
||||
final JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
final JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
final StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
step.setJobRepository(new JobRepositorySupport() {
|
||||
@Override
|
||||
@@ -359,7 +362,7 @@ public class TaskletStepTests {
|
||||
|
||||
@Test
|
||||
public void testSuccessfulExecutionWithFailureOnSaveOfExecutionContext() throws Exception {
|
||||
final JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
final JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
final StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
step.setJobRepository(new JobRepositorySupport() {
|
||||
private int counter = 0;
|
||||
@@ -389,7 +392,7 @@ public class TaskletStepTests {
|
||||
public void testNoSaveExecutionAttributesRestartableJob() {
|
||||
MockRestartableItemReader tasklet = new MockRestartableItemReader();
|
||||
step.setTasklet(new TestingChunkOrientedTasklet<String>(tasklet, itemWriter));
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
try {
|
||||
@@ -415,7 +418,7 @@ public class TaskletStepTests {
|
||||
return "foo";
|
||||
}
|
||||
}, itemWriter));
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
|
||||
step.execute(stepExecution);
|
||||
@@ -436,7 +439,7 @@ public class TaskletStepTests {
|
||||
};
|
||||
step.setTasklet(new TestingChunkOrientedTasklet<String>(reader, itemWriter));
|
||||
step.registerStream(reader);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
|
||||
assertEquals(false, stepExecution.getExecutionContext().containsKey("foo"));
|
||||
@@ -456,7 +459,7 @@ public class TaskletStepTests {
|
||||
executionContext.putString("foo", "bar");
|
||||
}
|
||||
} });
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
|
||||
assertEquals(false, stepExecution.getExecutionContext().containsKey("foo"));
|
||||
@@ -480,7 +483,7 @@ public class TaskletStepTests {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
step.execute(stepExecution);
|
||||
assertEquals(2, list.size());
|
||||
@@ -501,7 +504,7 @@ public class TaskletStepTests {
|
||||
};
|
||||
step.setStreams(new ItemStream[] { reader });
|
||||
step.registerStepExecutionListener(reader);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance));
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance, jobParameters));
|
||||
step.execute(stepExecution);
|
||||
assertEquals(1, list.size());
|
||||
}
|
||||
@@ -523,7 +526,7 @@ public class TaskletStepTests {
|
||||
stepTemplate.setCompletionPolicy(new SimpleCompletionPolicy(5));
|
||||
step.setStepOperations(stepTemplate);
|
||||
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
step.execute(stepExecution);
|
||||
assertEquals(1, list.size());
|
||||
@@ -547,7 +550,7 @@ public class TaskletStepTests {
|
||||
throw new RuntimeException("FOO");
|
||||
}
|
||||
}, itemWriter));
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
step.execute(stepExecution);
|
||||
assertEquals("FOO", stepExecution.getFailureExceptions().get(0).getMessage());
|
||||
@@ -569,7 +572,7 @@ public class TaskletStepTests {
|
||||
};
|
||||
step.setTasklet(new TestingChunkOrientedTasklet<String>(reader, itemWriter));
|
||||
step.setStreams(new ItemStream[] { reader });
|
||||
JobExecution jobExecution = new JobExecution(jobInstance);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
|
||||
|
||||
assertEquals(false, stepExecution.getExecutionContext().containsKey("foo"));
|
||||
@@ -606,7 +609,7 @@ public class TaskletStepTests {
|
||||
|
||||
step.setTasklet(new TestingChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
stepExecution.setExecutionContext(foobarEc);
|
||||
@@ -630,7 +633,7 @@ public class TaskletStepTests {
|
||||
};
|
||||
step.setTasklet(new TestingChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
stepExecution.setExecutionContext(foobarEc);
|
||||
@@ -654,7 +657,7 @@ public class TaskletStepTests {
|
||||
};
|
||||
step.setTasklet(new TestingChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
stepExecution.setExecutionContext(foobarEc);
|
||||
@@ -686,7 +689,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
});
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
stepExecution.setExecutionContext(foobarEc);
|
||||
@@ -716,7 +719,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
});
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
stepExecution.setExecutionContext(foobarEc);
|
||||
@@ -740,7 +743,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
} });
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
step.execute(stepExecution);
|
||||
@@ -768,7 +771,7 @@ public class TaskletStepTests {
|
||||
step.setTasklet(new TestingChunkOrientedTasklet<String>(itemReader, itemWriter));
|
||||
step.registerStream(itemReader);
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
stepExecution.setExecutionContext(foobarEc);
|
||||
@@ -801,7 +804,7 @@ public class TaskletStepTests {
|
||||
step.setTasklet(new TestingChunkOrientedTasklet<String>(reader, itemWriter));
|
||||
step.registerStream(reader);
|
||||
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance));
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance, jobParameters));
|
||||
|
||||
step.execute(stepExecution);
|
||||
assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
|
||||
@@ -820,7 +823,7 @@ public class TaskletStepTests {
|
||||
template.setCompletionPolicy(new DefaultResultCompletionPolicy());
|
||||
step.setStepOperations(template);
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
step.execute(stepExecution);
|
||||
@@ -842,7 +845,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
};
|
||||
step.setStepExecutionListeners(new StepExecutionListener[] { listener });
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance));
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), new JobExecution(jobInstance, jobParameters));
|
||||
|
||||
step.execute(stepExecution);
|
||||
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
|
||||
@@ -859,7 +862,7 @@ public class TaskletStepTests {
|
||||
}
|
||||
});
|
||||
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
|
||||
@SuppressWarnings("serial")
|
||||
@@ -883,7 +886,7 @@ public class TaskletStepTests {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance);
|
||||
JobExecution jobExecutionContext = new JobExecution(jobInstance, jobParameters);
|
||||
StepExecution stepExecution = new StepExecution(step.getName(), jobExecutionContext);
|
||||
step.execute(stepExecution);
|
||||
assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
|
||||
|
||||
Reference in New Issue
Block a user