From 86e1b0a3a92d749280d1a307bef6e471bc1371c1 Mon Sep 17 00:00:00 2001 From: Parikshit Dutta Date: Tue, 18 May 2021 22:51:21 +0530 Subject: [PATCH] Updated graceful shutdown sample by removing deprecated code Resolves #3901 --- .../sample/GracefulShutdownFunctionalTests.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 d9a25ebc0..0083cf3e0 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.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()); - } - }