diff --git a/spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java b/spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java index d9a25ebc0f..dab7c356bf 100644 --- a/spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java +++ b/spring-batch-samples/src/test/java/org/springframework/batch/sample/GracefulShutdownFunctionalTests.java @@ -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.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; @@ -38,6 +39,7 @@ * thread, then it's stopped using {@link JobExecution#stop()}. * * @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 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) { @@ -74,7 +79,5 @@ public void testLaunchJob() throws Exception { assertFalse("Timed out waiting for job to end.", jobExecution.isRunning()); assertEquals(BatchStatus.STOPPED, jobExecution.getStatus()); - } - }