Updated graceful shutdown sample by removing deprecated code
Resolves #3901
This commit is contained in:
committed by
Mahmoud Ben Hassine
parent
7a3d26c9f7
commit
86e1b0a3a9
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2006-2007 the original author or authors.
|
||||
* Copyright 2006-2021 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.
|
||||
@@ -28,6 +28,7 @@ import org.springframework.batch.core.BatchStatus;
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.JobParametersBuilder;
|
||||
import org.springframework.batch.core.launch.JobOperator;
|
||||
import org.springframework.batch.test.JobLauncherTestUtils;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
import org.springframework.test.context.ContextConfiguration;
|
||||
@@ -35,9 +36,10 @@ import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
|
||||
|
||||
/**
|
||||
* Functional test for graceful shutdown. A batch container is started in a new
|
||||
* thread, then it's stopped using {@link JobExecution#stop()}.
|
||||
* thread, then it's stopped using {@link JobOperator#stop(long)}.
|
||||
*
|
||||
* @author Lucas Ward
|
||||
* @author Parikshit Dutta
|
||||
*
|
||||
*/
|
||||
@RunWith(SpringJUnit4ClassRunner.class)
|
||||
@@ -50,6 +52,9 @@ public class GracefulShutdownFunctionalTests {
|
||||
@Autowired
|
||||
private JobLauncherTestUtils jobLauncherTestUtils;
|
||||
|
||||
@Autowired
|
||||
private JobOperator jobOperator;
|
||||
|
||||
@Test
|
||||
public void testLaunchJob() throws Exception {
|
||||
|
||||
@@ -63,7 +68,7 @@ public class GracefulShutdownFunctionalTests {
|
||||
assertEquals(BatchStatus.STARTED, jobExecution.getStatus());
|
||||
assertTrue(jobExecution.isRunning());
|
||||
|
||||
jobExecution.stop();
|
||||
jobOperator.stop(jobExecution.getId());
|
||||
|
||||
int count = 0;
|
||||
while (jobExecution.isRunning() && count <= 10) {
|
||||
@@ -74,7 +79,5 @@ public class GracefulShutdownFunctionalTests {
|
||||
|
||||
assertFalse("Timed out waiting for job to end.", jobExecution.isRunning());
|
||||
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user