BATCH-295: JobLauncher now only contains one method: run(Job, JobInstanceProperties). Misc. other changes were made to facilitate.
This commit is contained in:
@@ -188,6 +188,7 @@
|
||||
</includes>
|
||||
<excludes>
|
||||
<exclude>**/Abstract*.java</exclude>
|
||||
<exclude>**/HibernateJobFunctionalTests.java</exclude>
|
||||
</excludes>
|
||||
</configuration>
|
||||
</plugin>
|
||||
|
||||
@@ -6,7 +6,7 @@
|
||||
http://www.springframework.org/schema/util http://www.springframework.org/schema/util/spring-util-2.0.xsd">
|
||||
|
||||
<!-- Initialise the database before every test case: -->
|
||||
<import resource="data-source-context-init.xml" />
|
||||
<import resource="data-source-context-init.xml" />
|
||||
|
||||
<bean id="dataSource"
|
||||
class="org.springframework.jdbc.datasource.DriverManagerDataSource">
|
||||
|
||||
@@ -128,8 +128,6 @@
|
||||
<bean id="jobLauncher"
|
||||
class="org.springframework.batch.execution.launch.SimpleJobLauncher">
|
||||
<property name="jobRepository" ref="simpleJobRepository" />
|
||||
<property name="jobLocator"
|
||||
ref="jobConfigurationRegistry" />
|
||||
<property name="jobExecutor">
|
||||
<bean parent="jobExecutor">
|
||||
<property name="stepExecutorFactory">
|
||||
|
||||
@@ -20,7 +20,7 @@
|
||||
<list>
|
||||
<bean id="playerload"
|
||||
class="org.springframework.batch.execution.step.SimpleStep">
|
||||
<property name="commitInterval" value="100"></property>
|
||||
<property name="commitInterval" value="1"></property>
|
||||
<property name="startLimit" value="100" />
|
||||
<property name="saveRestartData" value="true" />
|
||||
<property name="allowStartIfComplete" value="false" />
|
||||
@@ -46,7 +46,7 @@
|
||||
</bean>
|
||||
<bean id="gameLoad"
|
||||
class="org.springframework.batch.execution.step.SimpleStep">
|
||||
<property name="commitInterval" value="1000" />
|
||||
<property name="commitInterval" value="1" />
|
||||
<property name="startLimit" value="100" />
|
||||
<property name="saveRestartData" value="true" />
|
||||
<property name="tasklet">
|
||||
@@ -71,7 +71,7 @@
|
||||
</bean>
|
||||
<bean id="playerSummarization"
|
||||
class="org.springframework.batch.execution.step.SimpleStep">
|
||||
<property name="commitInterval" value="100" />
|
||||
<property name="commitInterval" value="1" />
|
||||
<property name="startLimit" value="100" />
|
||||
<property name="saveRestartData" value="true" />
|
||||
<property name="tasklet">
|
||||
|
||||
@@ -24,6 +24,10 @@
|
||||
</property>
|
||||
</bean>
|
||||
|
||||
<bean id="jobLauncher" class="org.springframework.batch.execution.launch.SimpleJobLauncher">
|
||||
<property name="jobExecutor" ref="jobExecutor" />
|
||||
<property name="jobRepository" ref="simpleJobRepository" />
|
||||
</bean>
|
||||
|
||||
<bean id="infiniteLoopJob" parent="simpleJob">
|
||||
<property name="steps">
|
||||
|
||||
@@ -24,8 +24,6 @@
|
||||
<bean id="jobLauncher"
|
||||
class="org.springframework.batch.execution.launch.SimpleJobLauncher">
|
||||
<property name="jobRepository" ref="simpleJobRepository" />
|
||||
<property name="jobLocator"
|
||||
ref="jobConfigurationRegistry" />
|
||||
<property name="jobExecutor" ref="jobExecutor" />
|
||||
</bean>
|
||||
|
||||
|
||||
@@ -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