Replace usage of deprecated jobOperator#start method with newer version

Related to #4303
This commit is contained in:
jinwoo-Bae
2023-02-18 01:37:49 +09:00
committed by Mahmoud Ben Hassine
parent b76993ca3d
commit 2cc0be4a0c
3 changed files with 27 additions and 10 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 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.
@@ -39,6 +39,7 @@ import org.springframework.batch.core.StepContribution;
import org.springframework.batch.core.configuration.JobRegistry;
import org.springframework.batch.core.configuration.support.MapJobRegistry;
import org.springframework.batch.core.converter.DefaultJobParametersConverter;
import org.springframework.batch.core.converter.JobParametersConverter;
import org.springframework.batch.core.explore.JobExplorer;
import org.springframework.batch.core.job.AbstractJob;
import org.springframework.batch.core.job.JobSupport;
@@ -69,6 +70,7 @@ import static org.mockito.Mockito.when;
* @author Dave Syer
* @author Will Schipp
* @author Mahmoud Ben Hassine
* @author Jinwoo Bae
*
*/
class SimpleJobOperatorTests {
@@ -83,9 +85,13 @@ class SimpleJobOperatorTests {
private JobParameters jobParameters;
private JobParametersConverter jobParametersConverter;
@BeforeEach
void setUp() throws Exception {
jobParametersConverter = new DefaultJobParametersConverter();
job = new JobSupport("foo") {
@Nullable
@Override
@@ -162,18 +168,23 @@ class SimpleJobOperatorTests {
@Test
void testStartNewInstanceSunnyDay() throws Exception {
jobParameters = new JobParameters();
Properties parameters = new Properties();
parameters.setProperty("a", "b");
JobParameters jobParameters = jobParametersConverter.getJobParameters(parameters);
jobRepository.isJobInstanceExists("foo", jobParameters);
Long value = jobOperator.start("foo", "a=b");
Long value = jobOperator.start("foo", parameters);
assertEquals(999, value.longValue());
}
@Test
void testStartNewInstanceAlreadyExists() {
Properties properties = new Properties();
properties.setProperty("a", "b");
jobParameters = new JobParameters();
when(jobRepository.isJobInstanceExists("foo", jobParameters)).thenReturn(true);
jobRepository.isJobInstanceExists("foo", jobParameters);
assertThrows(JobInstanceAlreadyExistsException.class, () -> jobOperator.start("foo", "a=b"));
assertThrows(JobInstanceAlreadyExistsException.class, () -> jobOperator.start("foo", properties));
}
@Test

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2008-2022 the original author or authors.
* Copyright 2008-2023 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.
@@ -17,6 +17,7 @@ package org.springframework.batch.sample;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import java.util.Set;
import org.apache.commons.logging.Log;
@@ -61,8 +62,10 @@ class JobOperatorFunctionalTests {
@Test
void testStartStopResumeJob() throws Exception {
String params = "jobOperatorTestParam=7,java.lang.Long,true";
Properties properties = new Properties();
properties.setProperty("jobOperatorTestParam", "7,java.lang.Long,true");
long executionId = operator.start(job.getName(), params);
long executionId = operator.start(job.getName(), properties);
assertEquals(params, operator.getParameters(executionId));
stopAndCheckStatus(executionId);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2006-2022 the original author or authors.
* Copyright 2006-2023 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.
@@ -31,11 +31,13 @@ import javax.management.MalformedObjectNameException;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
import java.util.Properties;
import static org.junit.jupiter.api.Assertions.*;
/**
* @author Dave Syer
* @author Jinwoo Bae
*
*/
class RemoteLauncherTests {
@@ -61,11 +63,12 @@ class RemoteLauncherTests {
@Test
void testLaunchBadJob() throws Exception {
Properties properties = new Properties();
properties.setProperty("time", String.valueOf(new Date().getTime()));
assertEquals(0, errors.size());
assertTrue(isConnected());
Exception exception = assertThrows(RuntimeException.class,
() -> launcher.start("foo", "time=" + (new Date().getTime())));
Exception exception = assertThrows(RuntimeException.class, () -> launcher.start("foo", properties));
String message = exception.getMessage();
assertTrue(message.contains("NoSuchJobException"), "Wrong message: " + message);
}
@@ -84,7 +87,7 @@ class RemoteLauncherTests {
assertTrue(isConnected());
assertTrue(launcher.getJobNames().contains("loopJob"));
long executionId = launcher.start("loopJob", "");
long executionId = launcher.start("loopJob", new Properties());
// sleep long enough to avoid race conditions (serializable tx isolation
// doesn't work with HSQL)