Skip to content

Commit 86e1b0a

Browse files
parikshitduttafmbenhassine
authored andcommitted
Updated graceful shutdown sample by removing deprecated code
Resolves #3901
1 parent 7a3d26c commit 86e1b0a

File tree

1 file changed

+8
-5
lines changed

1 file changed

+8
-5
lines changed

spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java

+8-5
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
/*
2-
* Copyright 2006-2007 the original author or authors.
2+
* Copyright 2006-2021 the original author or authors.
33
*
44
* Licensed under the Apache License, Version 2.0 (the "License");
55
* you may not use this file except in compliance with the License.
@@ -28,16 +28,18 @@
2828
import org.springframework.batch.core.JobExecution;
2929
import org.springframework.batch.core.JobParameters;
3030
import org.springframework.batch.core.JobParametersBuilder;
31+
import org.springframework.batch.core.launch.JobOperator;
3132
import org.springframework.batch.test.JobLauncherTestUtils;
3233
import org.springframework.beans.factory.annotation.Autowired;
3334
import org.springframework.test.context.ContextConfiguration;
3435
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3536

3637
/**
3738
* Functional test for graceful shutdown. A batch container is started in a new
38-
* thread, then it's stopped using {@link JobExecution#stop()}.
39+
* thread, then it's stopped using {@link JobOperator#stop(long)}.
3940
*
4041
* @author Lucas Ward
42+
* @author Parikshit Dutta
4143
*
4244
*/
4345
@RunWith(SpringJUnit4ClassRunner.class)
@@ -50,6 +52,9 @@ public class GracefulShutdownFunctionalTests {
5052
@Autowired
5153
private JobLauncherTestUtils jobLauncherTestUtils;
5254

55+
@Autowired
56+
private JobOperator jobOperator;
57+
5358
@Test
5459
public void testLaunchJob() throws Exception {
5560

@@ -63,7 +68,7 @@ public void testLaunchJob() throws Exception {
6368
assertEquals(BatchStatus.STARTED, jobExecution.getStatus());
6469
assertTrue(jobExecution.isRunning());
6570

66-
jobExecution.stop();
71+
jobOperator.stop(jobExecution.getId());
6772

6873
int count = 0;
6974
while (jobExecution.isRunning() && count <= 10) {
@@ -74,7 +79,5 @@ public void testLaunchJob() throws Exception {
7479

7580
assertFalse("Timed out waiting for job to end.", jobExecution.isRunning());
7681
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
77-
7882
}
79-
8083
}

0 commit comments

Comments
 (0)