BATCH-295: JobLauncher now only contains one method: run(Job, JobInstanceProperties). Misc. other changes were made to facilitate.
This commit is contained in:
@@ -17,6 +17,7 @@
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import org.springframework.batch.core.domain.Job;
|
||||
import org.springframework.batch.core.domain.JobInstanceProperties;
|
||||
import org.springframework.batch.execution.launch.JobLauncher;
|
||||
import org.springframework.batch.execution.runtime.DefaultJobIdentifier;
|
||||
import org.springframework.context.ApplicationContext;
|
||||
@@ -67,6 +68,10 @@ public abstract class AbstractBatchLauncherTests extends
|
||||
public void setJob(Job job) {
|
||||
this.job = job;
|
||||
}
|
||||
|
||||
public Job getJob() {
|
||||
return job;
|
||||
}
|
||||
|
||||
protected String getJobName() {
|
||||
return job.getName();
|
||||
@@ -79,8 +84,6 @@ public abstract class AbstractBatchLauncherTests extends
|
||||
public void testLaunchJob() throws Exception {
|
||||
// Make sure the job is unique by the test case that runs it, not just
|
||||
// its name:
|
||||
launcher.run(new DefaultJobIdentifier(getJobName(), this.getClass()
|
||||
.getName()));
|
||||
launcher.stop();
|
||||
launcher.run(job, new JobInstanceProperties());
|
||||
}
|
||||
}
|
||||
|
||||
@@ -19,6 +19,9 @@ package org.springframework.batch.sample;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.batch.core.domain.BatchStatus;
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstanceProperties;
|
||||
import org.springframework.batch.core.executor.StepInterruptedException;
|
||||
import org.springframework.batch.core.runtime.SimpleJobIdentifier;
|
||||
|
||||
@@ -37,46 +40,61 @@ public class GracefulShutdownFunctionalTest extends AbstractBatchLauncherTests {
|
||||
|
||||
public void testLaunchJob() throws Exception {
|
||||
final List errors = new ArrayList();
|
||||
final JobInstanceProperties jobInstanceProperties = new JobInstanceProperties();
|
||||
|
||||
Thread jobThread = new Thread(){
|
||||
public void run(){
|
||||
try {
|
||||
launcher.run(new SimpleJobIdentifier(getJobName()));
|
||||
}
|
||||
catch (RuntimeException e) {
|
||||
if (!(e.getCause() instanceof StepInterruptedException)) {
|
||||
errors.add(e);
|
||||
}
|
||||
}
|
||||
catch (Exception e) {
|
||||
errors.add(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
jobThread.start();
|
||||
// Thread jobThread = new Thread(){
|
||||
// public void run(){
|
||||
// try {
|
||||
// launcher.run(getJob(), jobInstanceProperties);
|
||||
// }
|
||||
// catch (RuntimeException e) {
|
||||
// if (!(e.getCause() instanceof StepInterruptedException)) {
|
||||
// errors.add(e);
|
||||
// }
|
||||
// }
|
||||
// catch (Exception e) {
|
||||
// errors.add(e);
|
||||
// }
|
||||
// }
|
||||
// };
|
||||
//
|
||||
// jobThread.start();
|
||||
//
|
||||
// //give the thread a second to start up
|
||||
// Thread.sleep(200);
|
||||
//
|
||||
// assertTrue(launcher.isRunning());
|
||||
// assertTrue(jobThread.isAlive());
|
||||
//
|
||||
// //stop the job
|
||||
//
|
||||
// launcher.stop();
|
||||
//
|
||||
// //it takes a little while for it to shut down.
|
||||
// Thread.sleep(1000);
|
||||
//
|
||||
// assertFalse(launcher.isRunning());
|
||||
// assertFalse(jobThread.isAlive());
|
||||
//
|
||||
// if (!errors.isEmpty()) {
|
||||
// Exception e = (Exception) errors.get(0);
|
||||
// e.printStackTrace();
|
||||
// fail("Unexpected Exception: "+e);
|
||||
// }
|
||||
|
||||
//give the thread a second to start up
|
||||
Thread.sleep(200);
|
||||
JobExecution jobExecution = launcher.run(getJob(), jobInstanceProperties);
|
||||
|
||||
assertTrue(launcher.isRunning());
|
||||
assertTrue(jobThread.isAlive());
|
||||
assertEquals(BatchStatus.STARTED, jobExecution.getExitStatus());
|
||||
|
||||
//stop the job
|
||||
jobExecution.stop();
|
||||
|
||||
launcher.stop();
|
||||
|
||||
//it takes a little while for it to shut down.
|
||||
Thread.sleep(1000);
|
||||
|
||||
assertFalse(launcher.isRunning());
|
||||
assertFalse(jobThread.isAlive());
|
||||
|
||||
if (!errors.isEmpty()) {
|
||||
Exception e = (Exception) errors.get(0);
|
||||
e.printStackTrace();
|
||||
fail("Unexpected Exception: "+e);
|
||||
int count = 0;
|
||||
while(jobExecution.isRunning() && count <= 10){
|
||||
Thread.sleep(10);
|
||||
}
|
||||
|
||||
assertFalse(jobExecution.isRunning());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -16,6 +16,7 @@
|
||||
|
||||
package org.springframework.batch.sample;
|
||||
|
||||
import org.springframework.batch.core.domain.JobInstanceProperties;
|
||||
import org.springframework.batch.core.runtime.SimpleJobIdentifier;
|
||||
import org.springframework.batch.io.exception.BatchCriticalException;
|
||||
import org.springframework.jdbc.core.JdbcOperations;
|
||||
@@ -69,7 +70,7 @@ public class RestartFunctionalTests extends AbstractBatchLauncherTests {
|
||||
runJob();
|
||||
fail("First run of the job is expected to fail.");
|
||||
}
|
||||
catch (BatchCriticalException expected) {
|
||||
catch (Exception expected) {
|
||||
//expected
|
||||
}
|
||||
|
||||
@@ -81,8 +82,8 @@ public class RestartFunctionalTests extends AbstractBatchLauncherTests {
|
||||
}
|
||||
|
||||
// load the application context and launch the job
|
||||
private void runJob() throws Exception, Exception {
|
||||
launcher.run(new SimpleJobIdentifier(getJobName()));
|
||||
private void runJob() throws Exception {
|
||||
launcher.run(getJob(), new JobInstanceProperties());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -12,6 +12,7 @@ import org.springframework.batch.core.domain.BatchStatus;
|
||||
import org.springframework.batch.core.domain.Job;
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobInstanceProperties;
|
||||
import org.springframework.batch.core.repository.JobExecutionAlreadyRunningException;
|
||||
import org.springframework.batch.core.repository.JobRepository;
|
||||
import org.springframework.batch.execution.runtime.ScheduledJobIdentifier;
|
||||
@@ -78,7 +79,7 @@ public class JdbcJobRepositoryTests extends AbstractTransactionalDataSourceSprin
|
||||
public void testFindOrCreateJob() throws Exception {
|
||||
jobConfiguration.setName("foo");
|
||||
int before = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
JobExecution execution = repository.findOrCreateJob(jobConfiguration, jobIdentifier);
|
||||
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobInstanceProperties());
|
||||
int after = getJdbcTemplate().queryForInt("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE");
|
||||
assertEquals(before + 1, after);
|
||||
assertNotNull(execution.getId());
|
||||
@@ -123,7 +124,7 @@ public class JdbcJobRepositoryTests extends AbstractTransactionalDataSourceSprin
|
||||
|
||||
jobConfiguration.setName("spam");
|
||||
|
||||
JobExecution execution = repository.findOrCreateJob(jobConfiguration, jobIdentifier);
|
||||
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobInstanceProperties());
|
||||
cacheJobIds(execution);
|
||||
execution.setEndTime(new Timestamp(System.currentTimeMillis()));
|
||||
repository.saveOrUpdate(execution);
|
||||
@@ -173,7 +174,7 @@ public class JdbcJobRepositoryTests extends AbstractTransactionalDataSourceSprin
|
||||
new TransactionTemplate(transactionManager).execute(new TransactionCallback() {
|
||||
public Object doInTransaction(org.springframework.transaction.TransactionStatus status) {
|
||||
try {
|
||||
JobExecution execution = repository.findOrCreateJob(jobConfiguration, jobIdentifier);
|
||||
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobInstanceProperties());
|
||||
cacheJobIds(execution);
|
||||
list.add(execution);
|
||||
Thread.sleep(1000);
|
||||
@@ -193,7 +194,7 @@ public class JdbcJobRepositoryTests extends AbstractTransactionalDataSourceSprin
|
||||
}).start();
|
||||
|
||||
Thread.sleep(400);
|
||||
JobExecution execution = repository.findOrCreateJob(jobConfiguration, jobIdentifier);
|
||||
JobExecution execution = repository.createJobExecution(jobConfiguration, new JobInstanceProperties());
|
||||
cacheJobIds(execution);
|
||||
|
||||
int count = 0;
|
||||
|
||||
@@ -1,7 +1,9 @@
|
||||
package org.springframework.batch.sample.item.processor;
|
||||
|
||||
import org.springframework.batch.core.domain.Job;
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobInstanceProperties;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepInstance;
|
||||
import org.springframework.batch.core.runtime.SimpleJobIdentifier;
|
||||
@@ -28,8 +30,8 @@ public class StagingItemProcessorTests extends
|
||||
SimpleStepContext stepScopeContext = StepSynchronizationManager
|
||||
.open();
|
||||
stepScopeContext.setStepExecution(new StepExecution(new StepInstance(
|
||||
new Long(11)), new JobExecution(new JobInstance(
|
||||
new SimpleJobIdentifier("job"), new Long(12)))));
|
||||
new Long(11)), new JobExecution(new JobInstance(new Long(12),
|
||||
new JobInstanceProperties(), new Job("job")))));
|
||||
super.prepareTestInstance();
|
||||
}
|
||||
|
||||
|
||||
@@ -2,6 +2,7 @@ package org.springframework.batch.sample.item.reader;
|
||||
|
||||
import org.springframework.batch.core.domain.JobExecution;
|
||||
import org.springframework.batch.core.domain.JobInstance;
|
||||
import org.springframework.batch.core.domain.JobInstanceProperties;
|
||||
import org.springframework.batch.core.domain.StepExecution;
|
||||
import org.springframework.batch.core.domain.StepInstance;
|
||||
import org.springframework.batch.core.runtime.SimpleJobIdentifier;
|
||||
@@ -39,8 +40,8 @@ public class StagingItemReaderTests extends
|
||||
SimpleStepContext stepScopeContext = StepSynchronizationManager.open();
|
||||
jobId = new Long(11);
|
||||
stepScopeContext.setStepExecution(new StepExecution(new StepInstance(
|
||||
new Long(12)), new JobExecution(new JobInstance(
|
||||
new SimpleJobIdentifier("job"), jobId))));
|
||||
new Long(12)), new JobExecution(new JobInstance(jobId,
|
||||
new JobInstanceProperties()))));
|
||||
RepeatSynchronizationManager.register(new RepeatContextSupport(null));
|
||||
super.prepareTestInstance();
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user