Skip to content

Updated graceful shutdown sample by removing deprecated code #3916

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
Closed
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -28,6 +28,7 @@
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;
Expand All @@ -38,6 +39,7 @@
* thread, then it's stopped using {@link JobExecution#stop()}.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should be updated to {@link JobOperator#stop(long)}. I will do it on merge.

*
* @author Lucas Ward
* @author Parikshit Dutta
*
*/
@RunWith(SpringJUnit4ClassRunner.class)
Expand All @@ -50,6 +52,9 @@ public class GracefulShutdownFunctionalTests {
@Autowired
private JobLauncherTestUtils jobLauncherTestUtils;

@Autowired
private JobOperator jobOperator;

@Test
public void testLaunchJob() throws Exception {

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

jobExecution.stop();
jobOperator.stop(jobExecution.getId());

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

assertFalse("Timed out waiting for job to end.", jobExecution.isRunning());
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());

}

}