IN PROGRESS - issue BATCH-453: Killed batches cannot be restarted
http://jira.springframework.org/browse/BATCH-453 Added a new sample job: DatabaseShutdownFunctionalTests that uses the database to detect a stopped job.
This commit is contained in:
@@ -0,0 +1,73 @@
|
||||
/*
|
||||
* Copyright 2006-2007 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.sample;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.jdbc.core.JdbcTemplate;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
import org.springframework.transaction.annotation.Transactional;
|
||||
|
||||
/**
|
||||
* Functional test for graceful shutdown. A batch container is started in a new thread,
|
||||
* then it's stopped using {@link JobExecution#stop()}.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@ContextConfiguration()
|
||||
public class DatabaseShutdownFunctionalTests extends AbstractBatchLauncherTests {
|
||||
|
||||
@Transactional @Test
|
||||
public void testLaunchJob() throws Exception {
|
||||
|
||||
final JobParameters jobParameters = new JobParameters();
|
||||
|
||||
JobExecution jobExecution = launcher.run(getJob(), jobParameters);
|
||||
|
||||
Thread.sleep(1000);
|
||||
|
||||
assertEquals(BatchStatus.STARTED, jobExecution.getStatus());
|
||||
assertTrue(jobExecution.isRunning());
|
||||
|
||||
//jobExecution.stop();
|
||||
JdbcTemplate jdbcTemplate = (JdbcTemplate)applicationContext.getBean("jdbcTemplate");
|
||||
jdbcTemplate.update("UPDATE BATCH_JOB_EXECUTION set STATUS = ?", new Object[]{BatchStatus.STOPPING.toString()});
|
||||
|
||||
|
||||
int count = 0;
|
||||
while(jobExecution.isRunning() && count <= 10){
|
||||
logger.info("Checking for end time in JobExecution: count="+count);
|
||||
Thread.sleep(100);
|
||||
count++;
|
||||
}
|
||||
|
||||
assertFalse("Timed out waiting for job to end.", jobExecution.isRunning());
|
||||
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,10 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans xmlns="http://www.springframework.org/schema/beans"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="
|
||||
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-2.0.xsd">
|
||||
|
||||
<import resource="classpath:/simple-job-launcher-context.xml" />
|
||||
<import resource="classpath:/jobs/infiniteLoopJob.xml" />
|
||||
|
||||
</beans>
|
||||
Reference in New Issue
Block a user