Add getJobInstance method in JobExplorer/JobRepository

Resolves #3930
This commit is contained in:
Parikshit Dutta
2021-06-07 20:41:40 +05:30
committed by Mahmoud Ben Hassine
parent fd7dd5f1a7
commit 5a35b03300
11 changed files with 108 additions and 5 deletions

View File

@@ -32,6 +32,8 @@ import org.springframework.lang.Nullable;
* @author Dan Garrette
* @author David Turanski
* @author Mahmoud Ben Hassine
* @author Parikshit Dutta
*
* @since 2.0.1
*/
public class DummyJobRepository implements JobRepository, BeanNameAware {
@@ -57,6 +59,12 @@ public class DummyJobRepository implements JobRepository, BeanNameAware {
return null;
}
@Nullable
@Override
public JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
return null;
}
@Nullable
@Override
public JobExecution getLastJobExecution(String jobName, JobParameters jobParameters) {

View File

@@ -19,6 +19,10 @@ package org.springframework.batch.core.explore.support;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNull;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -44,7 +48,7 @@ import org.springframework.batch.core.repository.dao.StepExecutionDao;
* @author Will Schipp
* @author Michael Minella
* @author Mahmoud Ben Hassine
*
* @author Parikshit Dutta
*/
class SimpleJobExplorerTests {
@@ -150,6 +154,14 @@ class SimpleJobExplorerTests {
jobExplorer.getJobInstance(111L);
}
@Test
public void testGetJobInstanceWithNameAndParameters() throws Exception {
when(jobInstanceDao.getJobInstance("job", new JobParameters())).thenReturn(jobInstance);
JobInstance jobInstance = jobExplorer.getJobInstance("job", new JobParameters());
verify(jobInstanceDao).getJobInstance(anyString(), any(JobParameters.class));
assertEquals(jobInstance, jobInstance);
}
@Test
void testGetLastJobInstances() {
jobInstanceDao.getJobInstances("foo", 0, 1);

View File

@@ -55,7 +55,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue;
/**
* @author Lucas Ward
* @author Mahmoud Ben Hassine
*
* @author Parikshit Dutta
*/
class CommandLineJobRunnerTests {
@@ -515,6 +515,12 @@ class CommandLineJobRunnerTests {
throw new UnsupportedOperationException();
}
@Nullable
@Override
public JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
throw new UnsupportedOperationException();
}
@Nullable
@Override
public JobInstance getLastJobInstance(String jobName) {

View File

@@ -21,6 +21,8 @@ import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
@@ -60,6 +62,7 @@ import org.springframework.batch.core.step.StepSupport;
* @author Dimitrios Liapis
* @author Baris Cubukcuoglu
* @author Mahmoud Ben Hassine
* @author Parikshit Dutta
*
*/
class SimpleJobRepositoryTests {
@@ -329,4 +332,12 @@ class SimpleJobRepositoryTests {
assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());
}
@Test
public void testGetJobInstanceWithNameAndParameters() throws Exception {
when(jobInstanceDao.getJobInstance("job", new JobParameters())).thenReturn(jobInstance);
JobInstance jobInstance = jobRepository.getJobInstance("job", new JobParameters());
verify(jobInstanceDao).getJobInstance(anyString(), any(JobParameters.class));
assertEquals(jobInstance, jobInstance);
}
}

View File

@@ -28,7 +28,7 @@ import org.springframework.lang.Nullable;
* @author Dave Syer
* @author David Turanski
* @author Mahmoud Ben Hassine
*
* @author Parikshit Dutta
*/
public class JobRepositorySupport implements JobRepository {
@@ -66,6 +66,12 @@ public class JobRepositorySupport implements JobRepository {
public void update(JobInstance job) {
}
@Nullable
@Override
public JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
return null;
}
@Nullable
@Override
public StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) {

View File

@@ -62,7 +62,7 @@ import static org.springframework.batch.core.BatchStatus.UNKNOWN;
* @author Dave Syer
* @author David Turanski
* @author Mahmoud Ben Hassine
*
* @author Parikshit Dutta
*/
class TaskletStepExceptionTests {
@@ -520,6 +520,12 @@ class TaskletStepExceptionTests {
return null;
}
@Nullable
@Override
public JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
return null;
}
@Nullable
@Override
public StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) {