committed by
Mahmoud Ben Hassine
parent
fd7dd5f1a7
commit
5a35b03300
@@ -20,6 +20,7 @@ import java.util.Set;
|
||||
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.launch.NoSuchJobException;
|
||||
import org.springframework.batch.item.ExecutionContext;
|
||||
@@ -34,6 +35,7 @@ import org.springframework.lang.Nullable;
|
||||
* @author Michael Minella
|
||||
* @author Will Schipp
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @author Parikshit Dutta
|
||||
* @since 2.0
|
||||
*/
|
||||
public interface JobExplorer {
|
||||
@@ -92,6 +94,16 @@ public interface JobExplorer {
|
||||
@Nullable
|
||||
JobInstance getJobInstance(@Nullable Long instanceId);
|
||||
|
||||
/**
|
||||
* @param jobName {@link String} name for the jobInstance.
|
||||
* @param jobParameters {@link JobParameters} parameters for the jobInstance.
|
||||
* @return the {@link JobInstance} with this name and parameters, or null
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Nullable
|
||||
JobInstance getJobInstance(String jobName, JobParameters jobParameters);
|
||||
|
||||
/**
|
||||
* Retrieve job executions by their job instance. The corresponding step executions
|
||||
* may not be fully hydrated (for example, their execution context may be missing),
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.batch.core.explore.support;
|
||||
|
||||
import org.springframework.batch.core.JobExecution;
|
||||
import org.springframework.batch.core.JobInstance;
|
||||
import org.springframework.batch.core.JobParameters;
|
||||
import org.springframework.batch.core.StepExecution;
|
||||
import org.springframework.batch.core.explore.JobExplorer;
|
||||
import org.springframework.batch.core.launch.NoSuchJobException;
|
||||
@@ -38,6 +39,8 @@ import java.util.Set;
|
||||
* @author Michael Minella
|
||||
* @author Will Schipp
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @author Parikshit Dutta
|
||||
*
|
||||
* @see JobExplorer
|
||||
* @see JobInstanceDao
|
||||
* @see JobExecutionDao
|
||||
@@ -185,6 +188,19 @@ public class SimpleJobExplorer implements JobExplorer {
|
||||
return jobInstanceDao.getJobInstance(instanceId);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.batch.core.explore.JobExplorer#getJobInstance(java
|
||||
* .lang.String, org.springframework.batch.core.JobParameters)
|
||||
*/
|
||||
@Nullable
|
||||
@Override
|
||||
public JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
|
||||
return jobInstanceDao.getJobInstance(jobName, jobParameters);
|
||||
}
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
*
|
||||
|
||||
@@ -46,6 +46,7 @@ import java.util.List;
|
||||
* @author David Turanski
|
||||
* @author Michael Minella
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @author Parikshit Dutta
|
||||
*/
|
||||
public interface JobRepository {
|
||||
|
||||
@@ -186,6 +187,16 @@ public interface JobRepository {
|
||||
*/
|
||||
void updateExecutionContext(JobExecution jobExecution);
|
||||
|
||||
/**
|
||||
* @param jobName {@link String} the name of the jobInstance
|
||||
* @param jobParameters {@link JobParameters} parameters identifying the {@link JobInstance}
|
||||
* @return the {@link JobInstance} with name and parameters, or null
|
||||
*
|
||||
* @since 5.0
|
||||
*/
|
||||
@Nullable
|
||||
JobInstance getJobInstance(String jobName, JobParameters jobParameters);
|
||||
|
||||
/**
|
||||
* @param jobInstance {@link JobInstance} instance containing the step executions.
|
||||
* @param stepName the name of the step execution that might have run.
|
||||
|
||||
@@ -53,6 +53,8 @@ import java.util.List;
|
||||
* @author David Turanski
|
||||
* @author Mahmoud Ben Hassine
|
||||
* @author Baris Cubukcuoglu
|
||||
* @author Parikshit Dutta
|
||||
*
|
||||
* @see JobRepository
|
||||
* @see JobInstanceDao
|
||||
* @see JobExecutionDao
|
||||
@@ -244,6 +246,11 @@ public class SimpleJobRepository implements JobRepository {
|
||||
ecDao.updateExecutionContext(jobExecution);
|
||||
}
|
||||
|
||||
@Override
|
||||
public JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
|
||||
return jobInstanceDao.getJobInstance(jobName, jobParameters);
|
||||
}
|
||||
|
||||
@Override
|
||||
@Nullable
|
||||
public StepExecution getLastStepExecution(JobInstance jobInstance, String stepName) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -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) {
|
||||
|
||||
@@ -30,7 +30,7 @@ import org.springframework.lang.Nullable;
|
||||
/**
|
||||
* @author Dave Syer
|
||||
* @author Mahmoud Ben Hassine
|
||||
*
|
||||
* @author Parikshit Dutta
|
||||
*/
|
||||
public class JobRepositorySupport implements JobRepository {
|
||||
|
||||
@@ -48,6 +48,14 @@ public class JobRepositorySupport implements JobRepository {
|
||||
|
||||
/*
|
||||
* (non-Javadoc)
|
||||
* @see org.springframework.batch.core.repository.JobRepository#getJobInstance(java.lang.String,
|
||||
* org.springframework.batch.core.JobParameters)
|
||||
*/
|
||||
public JobInstance getJobInstance(String jobName, JobParameters jobParameters) {
|
||||
return null;
|
||||
}
|
||||
|
||||
/* (non-Javadoc)
|
||||
*
|
||||
* @see
|
||||
* org.springframework.batch.core.repository.JobRepository#getLastStepExecution(org.
|
||||
|
||||
Reference in New Issue
Block a user