BATCH-2007: Added a JobOperator implementation that complies with JSR-352.
* Added JsrJobOperator * Added a ParametersConverter (and JSR-352 implementation) that converts parameters as specified by the JSR to JobParameters and back * Added a method to the JobRepository to allow the direct creation of a JobInstance (since the JSR requires a new instance for each call to JobOperator#start * Added a base context to be bootstrapped when the JobOperator is first referenced. It provides things like a JobRepository, etc.
This commit is contained in:
@@ -35,7 +35,7 @@ import org.springframework.batch.support.SerializationUtils;
|
||||
public class JobExecutionTests {
|
||||
|
||||
private JobExecution execution = new JobExecution(new JobInstance(new Long(11), "foo"),
|
||||
new Long(12), new JobParameters());
|
||||
new Long(12), new JobParameters(), null);
|
||||
|
||||
@Test
|
||||
public void testJobExecution() {
|
||||
@@ -53,6 +53,12 @@ public class JobExecutionTests {
|
||||
assertEquals(100L, execution.getEndTime().getTime());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobConfigurationName() {
|
||||
execution = new JobExecution(new JobInstance(null, "foo"), null, "/META-INF/batch-jobs/someJob.xml");
|
||||
assertEquals("/META-INF/batch-jobs/someJob.xml", execution.getJobConfigurationName());
|
||||
}
|
||||
|
||||
/**
|
||||
* Test method for
|
||||
* {@link org.springframework.batch.core.JobExecution#getEndTime()}.
|
||||
@@ -126,7 +132,7 @@ public class JobExecutionTests {
|
||||
@Test
|
||||
public void testGetJobId() {
|
||||
assertEquals(11, execution.getJobId().longValue());
|
||||
execution = new JobExecution(new JobInstance(new Long(23), "testJob"), null, new JobParameters());
|
||||
execution = new JobExecution(new JobInstance(new Long(23), "testJob"), null, new JobParameters(), null);
|
||||
assertEquals(23, execution.getJobId().longValue());
|
||||
}
|
||||
|
||||
|
||||
@@ -6,7 +6,6 @@ import static org.junit.Assert.assertFalse;
|
||||
import java.util.Date;
|
||||
import java.util.Iterator;
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
@@ -21,30 +20,6 @@ public class JobParametersBuilderTests {
|
||||
|
||||
Date date = new Date(System.currentTimeMillis());
|
||||
|
||||
@Test
|
||||
public void testFromProperties() {
|
||||
Properties props = new Properties();
|
||||
props.put("SCHEDULE_DATE", date.toString());
|
||||
props.put("LONG", "1");
|
||||
props.put("STRING", "string value");
|
||||
|
||||
JobParametersBuilder builder = new JobParametersBuilder(props);
|
||||
JobParameters parameters = builder.toJobParameters();
|
||||
assertEquals(date.toString(), parameters.getString("SCHEDULE_DATE"));
|
||||
assertEquals("1", parameters.getString("LONG").toString());
|
||||
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 testFromNullProperties() {
|
||||
JobParametersBuilder builder = new JobParametersBuilder((Properties) null);
|
||||
JobParameters parameters = builder.toJobParameters();
|
||||
assertEquals(0, parameters.getParameters().size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonIdentifyingParameters() {
|
||||
parametersBuilder.addDate("SCHEDULE_DATE", date, false);
|
||||
|
||||
@@ -10,7 +10,6 @@ import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
@@ -213,18 +212,4 @@ public class JobParametersTests {
|
||||
public void testDateReturnsNullWhenKeyDoesntExit(){
|
||||
assertNull(new JobParameters().getDate("keythatdoesntexist"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testToProperties() {
|
||||
Properties results = parameters.toProperties();
|
||||
|
||||
assertEquals(results.get("string.key1"), "value1");
|
||||
assertEquals(results.get("string.key2"), "value2");
|
||||
assertEquals(results.get("long.key1"), "1");
|
||||
assertEquals(results.get("long.key2"), "2");
|
||||
assertEquals(results.get("double.key1"), "1.1");
|
||||
assertEquals(results.get("double.key2"), "2.2");
|
||||
assertEquals(results.get("date.key1"), String.valueOf(date1.getTime()));
|
||||
assertEquals(results.get("date.key2"), String.valueOf(date2.getTime()));
|
||||
}
|
||||
}
|
||||
|
||||
@@ -305,7 +305,7 @@ public class StepExecutionTests {
|
||||
|
||||
private StepExecution newStepExecution(Step step, Long jobExecutionId, long stepExecutionId) {
|
||||
JobInstance job = new JobInstance(3L, "testJob");
|
||||
StepExecution execution = new StepExecution(step.getName(), new JobExecution(job, jobExecutionId, new JobParameters()), stepExecutionId);
|
||||
StepExecution execution = new StepExecution(step.getName(), new JobExecution(job, jobExecutionId, new JobParameters(), null), stepExecutionId);
|
||||
return execution;
|
||||
}
|
||||
|
||||
|
||||
@@ -22,7 +22,7 @@ import java.util.ArrayList;
|
||||
import org.junit.Before;
|
||||
import org.springframework.batch.core.Job;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||
import org.springframework.batch.core.repository.JobInstanceAlreadyCompleteException;
|
||||
@@ -42,7 +42,7 @@ public abstract class AbstractJobParserTests {
|
||||
|
||||
@Autowired
|
||||
private JobRepository jobRepository;
|
||||
|
||||
|
||||
@Autowired
|
||||
private MapJobRepositoryFactoryBean mapJobRepositoryFactoryBean;
|
||||
|
||||
@@ -59,8 +59,8 @@ public abstract class AbstractJobParserTests {
|
||||
* @return JobExecution
|
||||
*/
|
||||
protected JobExecution createJobExecution() throws JobInstanceAlreadyCompleteException, JobRestartException,
|
||||
JobExecutionAlreadyRunningException {
|
||||
return jobRepository.createJobExecution(job.getName(), new JobParameters());
|
||||
JobExecutionAlreadyRunningException {
|
||||
return jobRepository.createJobExecution(job.getName(), new JobParametersBuilder().addLong("key1", 1l).toJobParameters());
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -95,4 +95,15 @@ public class DummyJobRepository implements JobRepository, BeanNameAware {
|
||||
public void addAll(Collection<StepExecution> stepExecutions) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobInstance createJobInstance(String jobName,
|
||||
JobParameters jobParameters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobExecution createJobExecution(JobInstance jobInstance,
|
||||
JobParameters jobParameters, String jobConfigurationLocation) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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,11 +16,11 @@
|
||||
|
||||
package org.springframework.batch.core.explore.support;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.launch.NoSuchJobException;
|
||||
import org.springframework.batch.core.repository.dao.ExecutionContextDao;
|
||||
import org.springframework.batch.core.repository.dao.JobExecutionDao;
|
||||
import org.springframework.batch.core.repository.dao.JobInstanceDao;
|
||||
@@ -40,7 +41,7 @@ import org.springframework.batch.core.repository.dao.StepExecutionDao;
|
||||
*
|
||||
* @author Dave Syer
|
||||
* @author Will Schipp
|
||||
*
|
||||
* @author Michael Minella
|
||||
*
|
||||
*/
|
||||
public class SimpleJobExplorerTests {
|
||||
@@ -57,7 +58,7 @@ public class SimpleJobExplorerTests {
|
||||
|
||||
private ExecutionContextDao ecDao;
|
||||
|
||||
private JobExecution jobExecution = new JobExecution(jobInstance, 1234L, new JobParameters());
|
||||
private JobExecution jobExecution = new JobExecution(jobInstance, 1234L, new JobParameters(), null);
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
@@ -93,13 +94,13 @@ public class SimpleJobExplorerTests {
|
||||
when(jobInstanceDao.getJobInstance(jobExecution)).thenReturn(jobInstance);
|
||||
StepExecution stepExecution = jobExecution.createStepExecution("foo");
|
||||
when(stepExecutionDao.getStepExecution(jobExecution, 123L))
|
||||
.thenReturn(stepExecution);
|
||||
.thenReturn(stepExecution);
|
||||
when(ecDao.getExecutionContext(stepExecution)).thenReturn(null);
|
||||
stepExecution = jobExplorer.getStepExecution(jobExecution.getId(), 123L);
|
||||
|
||||
assertEquals(jobInstance,
|
||||
stepExecution.getJobExecution().getJobInstance());
|
||||
|
||||
|
||||
assertEquals(jobInstance,
|
||||
stepExecution.getJobExecution().getJobInstance());
|
||||
|
||||
verify(jobInstanceDao).getJobInstance(jobExecution);
|
||||
}
|
||||
|
||||
@@ -107,7 +108,7 @@ public class SimpleJobExplorerTests {
|
||||
public void testGetStepExecutionMissing() throws Exception {
|
||||
when(jobExecutionDao.getJobExecution(jobExecution.getId())).thenReturn(jobExecution);
|
||||
when(stepExecutionDao.getStepExecution(jobExecution, 123L))
|
||||
.thenReturn(null);
|
||||
.thenReturn(null);
|
||||
assertNull(jobExplorer.getStepExecution(jobExecution.getId(), 123L));
|
||||
}
|
||||
|
||||
@@ -161,4 +162,17 @@ public class SimpleJobExplorerTests {
|
||||
jobExplorer.getJobNames();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobInstanceCount() throws Exception {
|
||||
when(jobInstanceDao.getJobInstanceCount("myJob")).thenReturn(4);
|
||||
|
||||
assertEquals(4, jobExplorer.getJobInstanceCount("myJob"));
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobException.class)
|
||||
public void testGetJobInstanceCountException() throws Exception {
|
||||
when(jobInstanceDao.getJobInstanceCount("throwException")).thenThrow(new NoSuchJobException("expected"));
|
||||
|
||||
jobExplorer.getJobInstanceCount("throwException");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,17 +24,19 @@ public class JobContextTests {
|
||||
private JobExecution execution;
|
||||
@Mock
|
||||
private JobInstance instance;
|
||||
@Mock
|
||||
private ParametersConverter converter;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
context = new JobContext(execution);
|
||||
context = new JobContext(execution, converter);
|
||||
when(execution.getJobInstance()).thenReturn(instance);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCreateWithNull() {
|
||||
context = new JobContext(null);
|
||||
context = new JobContext(null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -69,8 +71,11 @@ public class JobContextTests {
|
||||
JobParameters params = new JobParametersBuilder()
|
||||
.addString("key1", "value1")
|
||||
.toJobParameters();
|
||||
Properties results = new Properties();
|
||||
results.put("key1", "value1");
|
||||
|
||||
when(execution.getJobParameters()).thenReturn(params);
|
||||
when(converter.convert(params)).thenReturn(results);
|
||||
|
||||
Properties props = context.getProperties();
|
||||
|
||||
|
||||
@@ -34,12 +34,12 @@ public class JobExecutionTests {
|
||||
execution.setStatus(BatchStatus.FAILED);
|
||||
execution.setVersion(21);
|
||||
|
||||
adapter = new JobExecution(execution);
|
||||
adapter = new JobExecution(execution, new ParametersConverterSupport());
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testCreateWithNull() {
|
||||
adapter = new JobExecution(null);
|
||||
adapter = new JobExecution(null, new ParametersConverterSupport());
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -0,0 +1,110 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.sql.DataSource;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.jdbc.datasource.embedded.EmbeddedDatabaseBuilder;
|
||||
|
||||
public class JsrJobParametersConverterTests {
|
||||
|
||||
private JsrJobParametersConverter converter;
|
||||
private static DataSource dataSource;
|
||||
|
||||
@BeforeClass
|
||||
public static void setupDatabase() {
|
||||
dataSource = new EmbeddedDatabaseBuilder().
|
||||
addScript("classpath:org/springframework/batch/core/schema-drop-hsqldb.sql").
|
||||
addScript("classpath:org/springframework/batch/core/schema-hsqldb.sql").
|
||||
build();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
converter = new JsrJobParametersConverter(dataSource);
|
||||
converter.afterPropertiesSet();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullJobParameters() {
|
||||
Properties props = converter.convert((JobParameters) null);
|
||||
assertNotNull(props);
|
||||
Set<Entry<Object, Object>> properties = props.entrySet();
|
||||
assertEquals(1, properties.size());
|
||||
assertTrue(props.containsKey(JsrJobParametersConverter.JOB_RUN_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStringJobParameters() {
|
||||
JobParameters parameters = new JobParametersBuilder().addString("key", "value", false).toJobParameters();
|
||||
Properties props = converter.convert(parameters);
|
||||
assertNotNull(props);
|
||||
Set<Entry<Object, Object>> properties = props.entrySet();
|
||||
assertEquals(2, properties.size());
|
||||
assertTrue(props.containsKey(JsrJobParametersConverter.JOB_RUN_ID));
|
||||
assertEquals("value", props.getProperty("key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNonStringJobParameters() {
|
||||
JobParameters parameters = new JobParametersBuilder().addLong("key", 5l, false).toJobParameters();
|
||||
Properties props = converter.convert(parameters);
|
||||
assertNotNull(props);
|
||||
Set<Entry<Object, Object>> properties = props.entrySet();
|
||||
assertEquals(2, properties.size());
|
||||
assertTrue(props.containsKey(JsrJobParametersConverter.JOB_RUN_ID));
|
||||
assertEquals("5", props.getProperty("key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testJobParametersWithRunId() {
|
||||
JobParameters parameters = new JobParametersBuilder().addLong("key", 5l, false).addLong(JsrJobParametersConverter.JOB_RUN_ID, 2l).toJobParameters();
|
||||
Properties props = converter.convert(parameters);
|
||||
assertNotNull(props);
|
||||
Set<Entry<Object, Object>> properties = props.entrySet();
|
||||
assertEquals(2, properties.size());
|
||||
assertEquals("2", props.getProperty(JsrJobParametersConverter.JOB_RUN_ID));
|
||||
assertEquals("5", props.getProperty("key"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullProperties() {
|
||||
JobParameters parameters = converter.convert((Properties)null);
|
||||
assertNotNull(parameters);
|
||||
assertEquals(1, parameters.getParameters().size());
|
||||
assertTrue(parameters.getParameters().containsKey(JsrJobParametersConverter.JOB_RUN_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testProperties() {
|
||||
Properties properties = new Properties();
|
||||
properties.put("key", "value");
|
||||
JobParameters parameters = converter.convert(properties);
|
||||
assertEquals(2, parameters.getParameters().size());
|
||||
assertEquals("value", parameters.getString("key"));
|
||||
assertTrue(parameters.getParameters().containsKey(JsrJobParametersConverter.JOB_RUN_ID));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPropertiesWithRunId() {
|
||||
Properties properties = new Properties();
|
||||
properties.put("key", "value");
|
||||
properties.put(JsrJobParametersConverter.JOB_RUN_ID, "3");
|
||||
JobParameters parameters = converter.convert(properties);
|
||||
assertEquals(2, parameters.getParameters().size());
|
||||
assertEquals("value", parameters.getString("key"));
|
||||
assertEquals(Long.valueOf(3l), parameters.getLong(JsrJobParametersConverter.JOB_RUN_ID));
|
||||
assertTrue(parameters.getParameters().get(JsrJobParametersConverter.JOB_RUN_ID).isIdentifying());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,40 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import java.util.Map;
|
||||
import java.util.Properties;
|
||||
|
||||
import org.springframework.batch.core.JobParameter;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
|
||||
public class ParametersConverterSupport implements ParametersConverter {
|
||||
|
||||
@Override
|
||||
public JobParameters convert(Properties parameters) {
|
||||
JobParametersBuilder builder = new JobParametersBuilder();
|
||||
|
||||
if(parameters != null) {
|
||||
for (Map.Entry<Object, Object> curParameter : parameters.entrySet()) {
|
||||
if(curParameter.getValue() != null) {
|
||||
|
||||
builder.addString(curParameter.getKey().toString(), curParameter.getValue().toString(), false);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
return builder.toJobParameters();
|
||||
}
|
||||
|
||||
@Override
|
||||
public Properties convert(JobParameters parameters) {
|
||||
Properties properties = new Properties();
|
||||
|
||||
if(properties != null) {
|
||||
for(Map.Entry<String, JobParameter> curParameter: parameters.getParameters().entrySet()) {
|
||||
properties.setProperty(curParameter.getKey(), curParameter.getValue().getValue().toString());
|
||||
}
|
||||
}
|
||||
|
||||
return properties;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,24 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import javax.batch.runtime.Metric;
|
||||
import javax.batch.runtime.Metric.MetricType;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
public class SimpleMetricTests {
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testNullType() {
|
||||
Metric metric = new SimpleMetric(null, 0);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void test() {
|
||||
Metric metric = new SimpleMetric(MetricType.FILTER_COUNT, 3);
|
||||
|
||||
assertEquals(3, metric.getValue());
|
||||
assertEquals(MetricType.FILTER_COUNT, metric.getType());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,94 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Properties;
|
||||
|
||||
import javax.batch.runtime.Metric;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
|
||||
public class StepContextTests {
|
||||
|
||||
private StepExecution stepExecution;
|
||||
private StepContext stepContext;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
JobExecution jobExecution = new JobExecution(1l, new JobParametersBuilder().addString("key", "value").toJobParameters());
|
||||
|
||||
stepExecution = new StepExecution("testStep", jobExecution);
|
||||
stepExecution.setId(5l);
|
||||
stepExecution.setStatus(BatchStatus.STARTED);
|
||||
stepExecution.setExitStatus(new ExitStatus("customExitStatus"));
|
||||
stepExecution.setCommitCount(1);
|
||||
stepExecution.setFilterCount(2);
|
||||
stepExecution.setProcessSkipCount(3);
|
||||
stepExecution.setReadCount(4);
|
||||
stepExecution.setReadSkipCount(5);
|
||||
stepExecution.setRollbackCount(6);
|
||||
stepExecution.setWriteCount(7);
|
||||
stepExecution.setWriteSkipCount(8);
|
||||
|
||||
stepContext = new StepContext(stepExecution, new ParametersConverterSupport());
|
||||
stepContext.setTransientUserData("This is my transient data");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicProperties() {
|
||||
assertEquals(javax.batch.runtime.BatchStatus.STARTED, stepContext.getBatchStatus());
|
||||
assertEquals("customExitStatus", stepContext.getExitStatus());
|
||||
assertEquals(5l, stepContext.getStepExecutionId());
|
||||
assertEquals("testStep", stepContext.getStepName());
|
||||
assertEquals("This is my transient data", stepContext.getTransientUserData());
|
||||
|
||||
Properties params = stepContext.getProperties();
|
||||
assertEquals("value", params.get("key"));
|
||||
|
||||
Metric[] metrics = stepContext.getMetrics();
|
||||
|
||||
for (Metric metric : metrics) {
|
||||
switch (metric.getType()) {
|
||||
case COMMIT_COUNT:
|
||||
assertEquals(1, metric.getValue());
|
||||
break;
|
||||
case FILTER_COUNT:
|
||||
assertEquals(2, metric.getValue());
|
||||
break;
|
||||
case PROCESS_SKIP_COUNT:
|
||||
assertEquals(3, metric.getValue());
|
||||
break;
|
||||
case READ_COUNT:
|
||||
assertEquals(4, metric.getValue());
|
||||
break;
|
||||
case READ_SKIP_COUNT:
|
||||
assertEquals(5, metric.getValue());
|
||||
break;
|
||||
case ROLLBACK_COUNT:
|
||||
assertEquals(6, metric.getValue());
|
||||
break;
|
||||
case WRITE_COUNT:
|
||||
assertEquals(7, metric.getValue());
|
||||
break;
|
||||
case WRITE_SKIP_COUNT:
|
||||
assertEquals(8, metric.getValue());
|
||||
break;
|
||||
default:
|
||||
fail("Invalid metric type");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSetExitStatus() {
|
||||
stepContext.setExitStatus("new Exit Status");
|
||||
assertEquals("new Exit Status", stepExecution.getExitStatus().getExitCode());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,100 @@
|
||||
package org.springframework.batch.core.jsr;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.fail;
|
||||
|
||||
import java.util.Date;
|
||||
|
||||
import javax.batch.runtime.Metric;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.ExitStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
|
||||
public class StepExecutionTests {
|
||||
|
||||
private StepExecution stepExecution;
|
||||
private javax.batch.runtime.StepExecution jsrStepExecution;
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
JobExecution jobExecution = new JobExecution(1l, new JobParametersBuilder().addString("key", "value").toJobParameters());
|
||||
|
||||
stepExecution = new StepExecution("testStep", jobExecution);
|
||||
stepExecution.setId(5l);
|
||||
stepExecution.setStatus(BatchStatus.STARTED);
|
||||
stepExecution.setExitStatus(new ExitStatus("customExitStatus"));
|
||||
stepExecution.setCommitCount(1);
|
||||
stepExecution.setFilterCount(2);
|
||||
stepExecution.setProcessSkipCount(3);
|
||||
stepExecution.setReadCount(4);
|
||||
stepExecution.setReadSkipCount(5);
|
||||
stepExecution.setRollbackCount(6);
|
||||
stepExecution.setWriteCount(7);
|
||||
stepExecution.setWriteSkipCount(8);
|
||||
stepExecution.setStartTime(new Date(0));
|
||||
stepExecution.setEndTime(new Date(10000000));
|
||||
|
||||
jsrStepExecution = new org.springframework.batch.core.jsr.StepExecution(stepExecution);
|
||||
}
|
||||
|
||||
@Test(expected=IllegalArgumentException.class)
|
||||
public void testWithNullStepExecution() {
|
||||
new org.springframework.batch.core.jsr.StepExecution(null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullExitStatus() {
|
||||
stepExecution.setExitStatus(null);
|
||||
|
||||
assertNull(jsrStepExecution.getExitStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBaseValues() {
|
||||
assertEquals(5l, jsrStepExecution.getStepExecutionId());
|
||||
assertEquals("testStep", jsrStepExecution.getStepName());
|
||||
assertEquals(javax.batch.runtime.BatchStatus.STARTED, jsrStepExecution.getBatchStatus());
|
||||
assertEquals(new Date(0), jsrStepExecution.getStartTime());
|
||||
assertEquals(new Date(10000000), jsrStepExecution.getEndTime());
|
||||
assertEquals("customExitStatus", jsrStepExecution.getExitStatus());
|
||||
|
||||
Metric[] metrics = jsrStepExecution.getMetrics();
|
||||
|
||||
for (Metric metric : metrics) {
|
||||
switch (metric.getType()) {
|
||||
case COMMIT_COUNT:
|
||||
assertEquals(1, metric.getValue());
|
||||
break;
|
||||
case FILTER_COUNT:
|
||||
assertEquals(2, metric.getValue());
|
||||
break;
|
||||
case PROCESS_SKIP_COUNT:
|
||||
assertEquals(3, metric.getValue());
|
||||
break;
|
||||
case READ_COUNT:
|
||||
assertEquals(4, metric.getValue());
|
||||
break;
|
||||
case READ_SKIP_COUNT:
|
||||
assertEquals(5, metric.getValue());
|
||||
break;
|
||||
case ROLLBACK_COUNT:
|
||||
assertEquals(6, metric.getValue());
|
||||
break;
|
||||
case WRITE_COUNT:
|
||||
assertEquals(7, metric.getValue());
|
||||
break;
|
||||
case WRITE_SKIP_COUNT:
|
||||
assertEquals(8, metric.getValue());
|
||||
break;
|
||||
default:
|
||||
fail("Invalid metric type");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,340 @@
|
||||
package org.springframework.batch.core.jsr.launch;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Properties;
|
||||
import java.util.Set;
|
||||
|
||||
import javax.batch.operations.JobExecutionIsRunningException;
|
||||
import javax.batch.operations.JobOperator;
|
||||
import javax.batch.operations.NoSuchJobException;
|
||||
import javax.batch.operations.NoSuchJobExecutionException;
|
||||
import javax.batch.operations.NoSuchJobInstanceException;
|
||||
import javax.batch.runtime.BatchRuntime;
|
||||
import javax.batch.runtime.BatchStatus;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.MockitoAnnotations;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.explore.support.SimpleJobExplorer;
|
||||
import org.springframework.batch.core.jsr.ParametersConverter;
|
||||
import org.springframework.batch.core.jsr.ParametersConverterSupport;
|
||||
import org.springframework.batch.core.launch.support.SimpleJobOperator;
|
||||
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.core.step.JobRepositorySupport;
|
||||
|
||||
public class JsrJobOperatorTests {
|
||||
|
||||
private JobOperator jsrJobOperator;
|
||||
@Mock
|
||||
private org.springframework.batch.core.launch.JobOperator jobOperator;
|
||||
@Mock
|
||||
private JobExplorer jobExplorer;
|
||||
@Mock
|
||||
private JobRepository jobRepository;
|
||||
private ParametersConverter parameterConverter;
|
||||
|
||||
@Before
|
||||
public void setup() {
|
||||
MockitoAnnotations.initMocks(this);
|
||||
parameterConverter = new ParametersConverterSupport();
|
||||
jsrJobOperator = new JsrJobOperator(jobExplorer, jobRepository, jobOperator, parameterConverter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testLoadingWithBatchRuntime() {
|
||||
jsrJobOperator = BatchRuntime.getJobOperator();
|
||||
assertNotNull(jsrJobOperator);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testNullsInConstructor() {
|
||||
try {
|
||||
new JsrJobOperator(null, new JobRepositorySupport(), new SimpleJobOperator(), parameterConverter);
|
||||
fail("JobExplorer should be required");
|
||||
} catch (IllegalArgumentException correct) {
|
||||
}
|
||||
|
||||
try {
|
||||
new JsrJobOperator(new SimpleJobExplorer(null, null, null, null), null, new SimpleJobOperator(), parameterConverter);
|
||||
fail("JobRepository should be required");
|
||||
} catch (IllegalArgumentException correct) {
|
||||
}
|
||||
|
||||
try {
|
||||
new JsrJobOperator(new SimpleJobExplorer(null, null, null, null), new JobRepositorySupport(), null, parameterConverter);
|
||||
fail("JobOperator should be required");
|
||||
} catch (IllegalArgumentException correct) {
|
||||
}
|
||||
|
||||
try {
|
||||
new JsrJobOperator(new SimpleJobExplorer(null, null, null, null), new JobRepositorySupport(), new SimpleJobOperator(), null);
|
||||
fail("ParameterConverter should be required");
|
||||
} catch (IllegalArgumentException correct) {
|
||||
}
|
||||
|
||||
new JsrJobOperator(new SimpleJobExplorer(null, null, null, null), new JobRepositorySupport(), new SimpleJobOperator(), parameterConverter);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testAbandonRoseyScenario() throws Exception {
|
||||
jsrJobOperator.abandon(5l);
|
||||
|
||||
verify(jobOperator).abandon(5l);
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobExecutionException.class)
|
||||
public void testAbandonNoSuchJob() throws Exception {
|
||||
when(jobOperator.abandon(5l)).thenThrow(new org.springframework.batch.core.launch.NoSuchJobExecutionException("expected"));
|
||||
|
||||
jsrJobOperator.abandon(5l);
|
||||
}
|
||||
|
||||
@Test(expected=JobExecutionIsRunningException.class)
|
||||
public void testAbandonJobRunning() throws Exception {
|
||||
when(jobOperator.abandon(5l)).thenThrow(new JobExecutionAlreadyRunningException("expected"));
|
||||
|
||||
jsrJobOperator.abandon(5l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobExecutionRoseyScenario() {
|
||||
when(jobExplorer.getJobExecution(5l)).thenReturn(new JobExecution(5l));
|
||||
|
||||
assertEquals(5l, jsrJobOperator.getJobExecution(5l).getExecutionId());
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobExecutionException.class)
|
||||
public void testGetJobExecutionNoExecutionFound() {
|
||||
jsrJobOperator.getJobExecution(5l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobExecutionsRoseyScenario() {
|
||||
org.springframework.batch.core.JobInstance jobInstance = new org.springframework.batch.core.JobInstance(5l, "my job");
|
||||
List<JobExecution> executions = new ArrayList<JobExecution>();
|
||||
executions.add(new JobExecution(2l));
|
||||
|
||||
when(jobExplorer.getJobExecutions(jobInstance)).thenReturn(executions);
|
||||
|
||||
List<javax.batch.runtime.JobExecution> jobExecutions = jsrJobOperator.getJobExecutions(jobInstance);
|
||||
assertEquals(1, jobExecutions.size());
|
||||
assertEquals(2l, executions.get(0).getId().longValue());
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobInstanceException.class)
|
||||
public void testGetJobExecutionsNullJobInstance() {
|
||||
jsrJobOperator.getJobExecutions(null);
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobInstanceException.class)
|
||||
public void testGetJobExecutionsNullReturned() {
|
||||
org.springframework.batch.core.JobInstance jobInstance = new org.springframework.batch.core.JobInstance(5l, "my job");
|
||||
|
||||
jsrJobOperator.getJobExecutions(jobInstance);
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobInstanceException.class)
|
||||
public void testGetJobExecutionsNoneReturned() {
|
||||
org.springframework.batch.core.JobInstance jobInstance = new org.springframework.batch.core.JobInstance(5l, "my job");
|
||||
List<JobExecution> executions = new ArrayList<JobExecution>();
|
||||
|
||||
when(jobExplorer.getJobExecutions(jobInstance)).thenReturn(executions);
|
||||
|
||||
jsrJobOperator.getJobExecutions(jobInstance);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobInstanceRoseyScenario() {
|
||||
JobInstance instance = new JobInstance(1l, "my job");
|
||||
JobExecution execution = new JobExecution(5l);
|
||||
execution.setJobInstance(instance);
|
||||
|
||||
when(jobExplorer.getJobExecution(5l)).thenReturn(execution);
|
||||
when(jobExplorer.getJobInstance(1l)).thenReturn(instance);
|
||||
|
||||
javax.batch.runtime.JobInstance jobInstance = jsrJobOperator.getJobInstance(5l);
|
||||
|
||||
assertEquals(1l, jobInstance.getInstanceId());
|
||||
assertEquals("my job", jobInstance.getJobName());
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobExecutionException.class)
|
||||
public void testGetJobInstanceNoExecution() {
|
||||
JobInstance instance = new JobInstance(1l, "my job");
|
||||
JobExecution execution = new JobExecution(5l);
|
||||
execution.setJobInstance(instance);
|
||||
|
||||
jsrJobOperator.getJobInstance(5l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobInstanceCount() throws Exception {
|
||||
when(jobExplorer.getJobInstanceCount("myJob")).thenReturn(4);
|
||||
|
||||
assertEquals(4, jsrJobOperator.getJobInstanceCount("myJob"));
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobException.class)
|
||||
public void testGetJobInstanceCountNoSuchJob() throws Exception {
|
||||
when(jobExplorer.getJobInstanceCount("myJob")).thenThrow(new org.springframework.batch.core.launch.NoSuchJobException("expected"));
|
||||
|
||||
jsrJobOperator.getJobInstanceCount("myJob");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobInstancesRoseyScenario() {
|
||||
List<JobInstance> instances = new ArrayList<JobInstance>();
|
||||
instances.add(new JobInstance(1l, "myJob"));
|
||||
instances.add(new JobInstance(2l, "myJob"));
|
||||
instances.add(new JobInstance(3l, "myJob"));
|
||||
|
||||
when(jobExplorer.getJobInstances("myJob", 0, 3)).thenReturn(instances);
|
||||
|
||||
List<javax.batch.runtime.JobInstance> jobInstances = jsrJobOperator.getJobInstances("myJob", 0, 3);
|
||||
|
||||
assertEquals(3, jobInstances.size());
|
||||
assertEquals(1l, jobInstances.get(0).getInstanceId());
|
||||
assertEquals(2l, jobInstances.get(1).getInstanceId());
|
||||
assertEquals(3l, jobInstances.get(2).getInstanceId());
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobException.class)
|
||||
public void testGetJobInstancesNullInstancesReturned() {
|
||||
jsrJobOperator.getJobInstances("myJob", 0, 3);
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobException.class)
|
||||
public void testGetJobInstancesZeroInstancesReturned() {
|
||||
List<JobInstance> instances = new ArrayList<JobInstance>();
|
||||
|
||||
when(jobExplorer.getJobInstances("myJob", 0, 3)).thenReturn(instances);
|
||||
|
||||
jsrJobOperator.getJobInstances("myJob", 0, 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobNames() {
|
||||
List<String> jobNames = new ArrayList<String>();
|
||||
jobNames.add("job1");
|
||||
jobNames.add("job2");
|
||||
|
||||
when(jobExplorer.getJobNames()).thenReturn(jobNames);
|
||||
|
||||
Set<String> result = jsrJobOperator.getJobNames();
|
||||
|
||||
assertEquals(2, result.size());
|
||||
assertTrue(result.contains("job1"));
|
||||
assertTrue(result.contains("job2"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetParametersRoseyScenario() {
|
||||
JobExecution jobExecution = new JobExecution(5l, new JobParametersBuilder().addString("key1", "value1").toJobParameters());
|
||||
|
||||
when(jobExplorer.getJobExecution(5l)).thenReturn(jobExecution);
|
||||
|
||||
Properties params = jsrJobOperator.getParameters(5l);
|
||||
|
||||
assertEquals("value1", params.get("key1"));
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobExecutionException.class)
|
||||
public void testGetParametersNoExecution() {
|
||||
jsrJobOperator.getParameters(5l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetRunningExecutions() {
|
||||
Set<JobExecution> executions = new HashSet<JobExecution>();
|
||||
executions.add(new JobExecution(5l));
|
||||
|
||||
when(jobExplorer.findRunningJobExecutions("myJob")).thenReturn(executions);
|
||||
|
||||
assertEquals(5l, jsrJobOperator.getRunningExecutions("myJob").get(0).longValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepExecutionsRoseyScenario() {
|
||||
JobExecution jobExecution = new JobExecution(5l);
|
||||
List<StepExecution> stepExecutions = new ArrayList<StepExecution>();
|
||||
stepExecutions.add(new StepExecution("step1", jobExecution));
|
||||
stepExecutions.add(new StepExecution("step2", jobExecution));
|
||||
jobExecution.addStepExecutions(stepExecutions);
|
||||
|
||||
when(jobExplorer.getJobExecution(5l)).thenReturn(jobExecution);
|
||||
|
||||
List<javax.batch.runtime.StepExecution> results = jsrJobOperator.getStepExecutions(5l);
|
||||
|
||||
assertEquals("step1", results.get(0).getStepName());
|
||||
assertEquals("step2", results.get(1).getStepName());
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobException.class)
|
||||
public void testGetStepExecutionsNoExecutionReturned() {
|
||||
jsrJobOperator.getStepExecutions(5l);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetStepExecutionsNoStepExecutions() {
|
||||
JobExecution jobExecution = new JobExecution(5l);
|
||||
|
||||
when(jobExplorer.getJobExecution(5l)).thenReturn(jobExecution);
|
||||
|
||||
List<javax.batch.runtime.StepExecution> results = jsrJobOperator.getStepExecutions(5l);
|
||||
|
||||
assertEquals(0, results.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartRoseyScenario() {
|
||||
jsrJobOperator = BatchRuntime.getJobOperator();
|
||||
|
||||
long executionId = jsrJobOperator.start("jsrJobOperatorTestJob", null);
|
||||
|
||||
assertEquals(BatchStatus.COMPLETED, jsrJobOperator.getJobExecution(executionId).getBatchStatus());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartMultipleTimesSameParameters() {
|
||||
jsrJobOperator = BatchRuntime.getJobOperator();
|
||||
|
||||
long run1 = jsrJobOperator.start("jsrJobOperatorTestJob", null);
|
||||
long run2 = jsrJobOperator.start("jsrJobOperatorTestJob", null);
|
||||
long run3 = jsrJobOperator.start("jsrJobOperatorTestJob", null);
|
||||
|
||||
assertEquals(BatchStatus.COMPLETED, jsrJobOperator.getJobExecution(run1).getBatchStatus());
|
||||
assertEquals(BatchStatus.COMPLETED, jsrJobOperator.getJobExecution(run2).getBatchStatus());
|
||||
assertEquals(BatchStatus.COMPLETED, jsrJobOperator.getJobExecution(run3).getBatchStatus());
|
||||
|
||||
assertTrue(3 >= jsrJobOperator.getJobInstanceCount("jsrJobOperatorTestJob"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testRestartRoseyScenario() {
|
||||
jsrJobOperator = BatchRuntime.getJobOperator();
|
||||
|
||||
long executionId = jsrJobOperator.start("jsrJobOperatorTestRestartJob", null);
|
||||
|
||||
assertEquals(BatchStatus.FAILED, jsrJobOperator.getJobExecution(executionId).getBatchStatus());
|
||||
|
||||
long finalExecutionId = jsrJobOperator.restart(executionId, null);
|
||||
|
||||
assertEquals(BatchStatus.COMPLETED, jsrJobOperator.getJobExecution(finalExecutionId).getBatchStatus());
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package org.springframework.batch.core.jsr.step.batchlet;
|
||||
|
||||
import javax.batch.api.Batchlet;
|
||||
|
||||
public class RestartBatchlet implements Batchlet {
|
||||
|
||||
private static int runCount = 0;
|
||||
|
||||
@Override
|
||||
public String process() throws Exception {
|
||||
runCount++;
|
||||
|
||||
if(runCount == 1) {
|
||||
throw new RuntimeException("This is expected");
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void stop() throws Exception {
|
||||
}
|
||||
}
|
||||
@@ -42,6 +42,7 @@ import org.springframework.batch.core.converter.DefaultJobParametersConverter;
|
||||
import org.springframework.batch.core.converter.JobParametersConverter;
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.launch.JobLauncher;
|
||||
import org.springframework.batch.core.launch.NoSuchJobException;
|
||||
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||
import org.springframework.batch.core.step.JobRepositorySupport;
|
||||
import org.springframework.util.ClassUtils;
|
||||
@@ -69,7 +70,7 @@ public class CommandLineJobRunnerTests {
|
||||
|
||||
@Before
|
||||
public void setUp() throws Exception {
|
||||
JobExecution jobExecution = new JobExecution(null, new Long(1), null);
|
||||
JobExecution jobExecution = new JobExecution(null, new Long(1), null, null);
|
||||
ExitStatus exitStatus = ExitStatus.COMPLETED;
|
||||
jobExecution.setExitStatus(exitStatus);
|
||||
StubJobLauncher.jobExecution = jobExecution;
|
||||
@@ -284,7 +285,7 @@ public class CommandLineJobRunnerTests {
|
||||
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, jobName), 11L, jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(0L, jobName), 11L, jobParameters, null);
|
||||
jobExecution.setStatus(BatchStatus.FAILED);
|
||||
StubJobExplorer.jobExecution = jobExecution;
|
||||
CommandLineJobRunner.main(args);
|
||||
@@ -296,7 +297,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, jobName), 11L, jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(0L, jobName), 11L, jobParameters, null);
|
||||
jobExecution.setStatus(BatchStatus.COMPLETED);
|
||||
StubJobExplorer.jobExecution = jobExecution;
|
||||
CommandLineJobRunner.main(args);
|
||||
@@ -451,7 +452,7 @@ public class CommandLineJobRunnerTests {
|
||||
}
|
||||
|
||||
private JobExecution createJobExecution(JobInstance jobInstance, BatchStatus status) {
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 1L, jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 1L, jobParameters, null);
|
||||
jobExecution.setStatus(status);
|
||||
jobExecution.setStartTime(new Date());
|
||||
if (status != BatchStatus.STARTED) {
|
||||
@@ -485,6 +486,24 @@ public class CommandLineJobRunnerTests {
|
||||
throw new UnsupportedOperationException();
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getJobInstanceCount(String jobName)
|
||||
throws NoSuchJobException {
|
||||
int count = 0;
|
||||
|
||||
for (JobInstance jobInstance : jobInstances) {
|
||||
if(jobInstance.getJobName().equals(jobName)) {
|
||||
count++;
|
||||
}
|
||||
}
|
||||
|
||||
if(count == 0) {
|
||||
throw new NoSuchJobException("Unable to find job instances for " + jobName);
|
||||
} else {
|
||||
return count;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
public static class StubJobParametersConverter implements JobParametersConverter {
|
||||
|
||||
@@ -15,13 +15,12 @@
|
||||
*/
|
||||
package org.springframework.batch.core.launch.support;
|
||||
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.when;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
@@ -112,7 +111,7 @@ public class SimpleJobOperatorTests {
|
||||
@Override
|
||||
public JobExecution run(Job job, JobParameters jobParameters) throws JobExecutionAlreadyRunningException,
|
||||
JobRestartException, JobInstanceAlreadyCompleteException {
|
||||
return new JobExecution(new JobInstance(123L, job.getName()), 999L, jobParameters);
|
||||
return new JobExecution(new JobInstance(123L, job.getName()), 999L, jobParameters, null);
|
||||
}
|
||||
});
|
||||
|
||||
@@ -192,7 +191,7 @@ public class SimpleJobOperatorTests {
|
||||
@Test
|
||||
public void testResumeSunnyDay() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
when(jobExplorer.getJobExecution(111l)).thenReturn(new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters));
|
||||
when(jobExplorer.getJobExecution(111l)).thenReturn(new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters, null));
|
||||
jobExplorer.getJobExecution(111L);
|
||||
Long value = jobOperator.restart(111L);
|
||||
assertEquals(999, value.longValue());
|
||||
@@ -201,7 +200,7 @@ public class SimpleJobOperatorTests {
|
||||
@Test
|
||||
public void testGetSummarySunnyDay() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters, null);
|
||||
when(jobExplorer.getJobExecution(111L)).thenReturn(jobExecution);
|
||||
jobExplorer.getJobExecution(111L);
|
||||
String value = jobOperator.getSummary(111L);
|
||||
@@ -224,7 +223,7 @@ public class SimpleJobOperatorTests {
|
||||
public void testGetStepExecutionSummariesSunnyDay() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters, null);
|
||||
jobExecution.createStepExecution("step1");
|
||||
jobExecution.createStepExecution("step2");
|
||||
jobExecution.getStepExecutions().iterator().next().setId(21L);
|
||||
@@ -248,7 +247,7 @@ public class SimpleJobOperatorTests {
|
||||
@Test
|
||||
public void testFindRunningExecutionsSunnyDay() throws Exception {
|
||||
jobParameters = new JobParameters();
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters, null);
|
||||
when(jobExplorer.findRunningJobExecutions("foo")).thenReturn(Collections.singleton(jobExecution));
|
||||
Set<Long> value = jobOperator.getRunningExecutions("foo");
|
||||
assertEquals(111L, value.iterator().next().longValue());
|
||||
@@ -269,7 +268,7 @@ public class SimpleJobOperatorTests {
|
||||
@Test
|
||||
public void testGetJobParametersSunnyDay() throws Exception {
|
||||
final JobParameters jobParameters = new JobParameters();
|
||||
when(jobExplorer.getJobExecution(111L)).thenReturn(new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters));
|
||||
when(jobExplorer.getJobExecution(111L)).thenReturn(new JobExecution(new JobInstance(123L, job.getName()), 111L, jobParameters, null));
|
||||
String value = jobOperator.getParameters(111L);
|
||||
assertEquals("a=b", value);
|
||||
}
|
||||
@@ -319,8 +318,8 @@ public class SimpleJobOperatorTests {
|
||||
public void testGetExecutionsSunnyDay() throws Exception {
|
||||
JobInstance jobInstance = new JobInstance(123L, job.getName());
|
||||
when(jobExplorer.getJobInstance(123L)).thenReturn(jobInstance);
|
||||
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters);
|
||||
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters, null);
|
||||
when(jobExplorer.getJobExecutions(jobInstance)).thenReturn(Collections.singletonList(jobExecution));
|
||||
List<Long> value = jobOperator.getExecutions(123L);
|
||||
assertEquals(111L, value.iterator().next().longValue());
|
||||
@@ -341,7 +340,7 @@ public class SimpleJobOperatorTests {
|
||||
@Test
|
||||
public void testStop() throws Exception{
|
||||
JobInstance jobInstance = new JobInstance(123L, job.getName());
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters, null);
|
||||
when(jobExplorer.getJobExecution(111L)).thenReturn(jobExecution);
|
||||
jobExplorer.getJobExecution(111L);
|
||||
jobRepository.update(jobExecution);
|
||||
@@ -352,7 +351,7 @@ public class SimpleJobOperatorTests {
|
||||
@Test
|
||||
public void testAbort() throws Exception {
|
||||
JobInstance jobInstance = new JobInstance(123L, job.getName());
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters, null);
|
||||
jobExecution.setStatus(BatchStatus.STOPPING);
|
||||
when(jobExplorer.getJobExecution(123L)).thenReturn(jobExecution);
|
||||
jobRepository.update(jobExecution);
|
||||
@@ -364,7 +363,7 @@ public class SimpleJobOperatorTests {
|
||||
@Test(expected = JobExecutionAlreadyRunningException.class)
|
||||
public void testAbortNonStopping() throws Exception {
|
||||
JobInstance jobInstance = new JobInstance(123L, job.getName());
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 111L, jobParameters, null);
|
||||
jobExecution.setStatus(BatchStatus.STARTED);
|
||||
when(jobExplorer.getJobExecution(123L)).thenReturn(jobExecution);
|
||||
jobRepository.update(jobExecution);
|
||||
|
||||
@@ -84,7 +84,6 @@ public abstract class AbstractJobDaoTests {
|
||||
|
||||
@Before
|
||||
public void onSetUpInTransaction() throws Exception {
|
||||
|
||||
// Create job.
|
||||
jobInstance = jobInstanceDao.createJobInstance(jobName, jobParameters);
|
||||
|
||||
@@ -119,7 +118,6 @@ public abstract class AbstractJobDaoTests {
|
||||
|
||||
@Transactional @Test
|
||||
public void testFindJob() {
|
||||
|
||||
JobInstance instance = jobInstanceDao.getJobInstance(jobName, jobParameters);
|
||||
assertNotNull(instance);
|
||||
assertTrue(jobInstance.equals(instance));
|
||||
@@ -187,7 +185,7 @@ public abstract class AbstractJobDaoTests {
|
||||
public void testUpdateInvalidJobExecution() {
|
||||
|
||||
// id is invalid
|
||||
JobExecution execution = new JobExecution(jobInstance, (long) 29432, jobParameters);
|
||||
JobExecution execution = new JobExecution(jobInstance, (long) 29432, jobParameters, null);
|
||||
execution.incrementVersion();
|
||||
try {
|
||||
jobExecutionDao.updateJobExecution(execution);
|
||||
|
||||
@@ -188,7 +188,7 @@ public abstract class AbstractStepExecutionDaoTests extends AbstractTransactiona
|
||||
@Transactional
|
||||
@Test
|
||||
public void testGetForNotExistingJobExecution() {
|
||||
assertNull(dao.getStepExecution(new JobExecution(jobInstance, (long) 777, new JobParameters()), 11L));
|
||||
assertNull(dao.getStepExecution(new JobExecution(jobInstance, (long) 777, new JobParameters(), null), 11L));
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -39,7 +39,7 @@ public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests {
|
||||
@Override
|
||||
protected JobInstanceDao getJobInstanceDao() {
|
||||
JdbcTestUtils.deleteFromTables(jdbcTemplate, "BATCH_JOB_EXECUTION_CONTEXT",
|
||||
"BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION_PARAMS",
|
||||
"BATCH_STEP_EXECUTION_CONTEXT", "BATCH_STEP_EXECUTION", "BATCH_JOB_EXECUTION_PARAMS",
|
||||
"BATCH_JOB_EXECUTION", "BATCH_JOB_INSTANCE");
|
||||
return jobInstanceDao;
|
||||
}
|
||||
@@ -51,7 +51,7 @@ public class JdbcJobInstanceDaoTests extends AbstractJobInstanceDaoTests {
|
||||
JobParameters jobParameters = new JobParameters();
|
||||
JobInstance jobInstance = dao.createJobInstance("testInstance",
|
||||
jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 2L, jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(jobInstance, 2L, jobParameters, null);
|
||||
jobExecutionDao.saveJobExecution(jobExecution);
|
||||
|
||||
JobInstance returnedInstance = dao.getJobInstance(jobExecution);
|
||||
|
||||
@@ -50,7 +50,7 @@ import org.springframework.batch.core.step.StepSupport;
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Will Schipp
|
||||
*
|
||||
*
|
||||
*/
|
||||
public class SimpleJobRepositoryTests {
|
||||
|
||||
@@ -117,7 +117,7 @@ public class SimpleJobRepositoryTests {
|
||||
steps.add(databaseStep1);
|
||||
steps.add(databaseStep2);
|
||||
|
||||
jobExecution = new JobExecution(new JobInstance(1L, job.getName()), 1L, jobParameters);
|
||||
jobExecution = new JobExecution(new JobInstance(1L, job.getName()), 1L, jobParameters, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -137,7 +137,7 @@ public class SimpleJobRepositoryTests {
|
||||
@Test
|
||||
public void testUpdateValidJobExecution() throws Exception {
|
||||
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(1L, job.getName()), 1L, jobParameters);
|
||||
JobExecution jobExecution = new JobExecution(new JobInstance(1L, job.getName()), 1L, jobParameters, null);
|
||||
// new execution - call update on job dao
|
||||
jobExecutionDao.updateJobExecution(jobExecution);
|
||||
jobRepository.update(jobExecution);
|
||||
|
||||
@@ -35,7 +35,7 @@ import org.springframework.batch.core.JobParameters;
|
||||
public class ChunkContextTests {
|
||||
|
||||
private ChunkContext context = new ChunkContext(new StepContext(new JobExecution(new JobInstance(0L,
|
||||
"job"), 1L, new JobParameters(Collections.singletonMap("foo", new JobParameter("bar"))))
|
||||
"job"), 1L, new JobParameters(Collections.singletonMap("foo", new JobParameter("bar"))), null)
|
||||
.createStepExecution("foo")));
|
||||
|
||||
@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, "job"), 0L, null), 1L);
|
||||
private StepExecution stepExecution = new StepExecution("step", new JobExecution(new JobInstance(2L, "job"), 0L, null, null), 1L);
|
||||
|
||||
private StepContext context = new StepContext(stepExecution);
|
||||
|
||||
|
||||
@@ -36,7 +36,7 @@ public class JobRepositorySupport implements JobRepository {
|
||||
@Override
|
||||
public JobExecution createJobExecution(String jobName, JobParameters jobParameters) {
|
||||
JobInstance jobInstance = new JobInstance(0L, jobName);
|
||||
return new JobExecution(jobInstance, 11L, jobParameters);
|
||||
return new JobExecution(jobInstance, 11L, jobParameters, null);
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
@@ -103,4 +103,15 @@ public class JobRepositorySupport implements JobRepository {
|
||||
public void addAll(Collection<StepExecution> stepExecutions) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobInstance createJobInstance(String jobName,
|
||||
JobParameters jobParameters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobExecution createJobExecution(JobInstance jobInstance,
|
||||
JobParameters jobParameters, String jobConfigurationLocation) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -471,6 +471,18 @@ public class TaskletStepExceptionTests {
|
||||
@Override
|
||||
public void addAll(Collection<StepExecution> stepExecutions) {
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobInstance createJobInstance(String jobName,
|
||||
JobParameters jobParameters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobExecution createJobExecution(JobInstance jobInstance,
|
||||
JobParameters jobParameters, String jobConfigurationLocation) {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user