Fixed exception behavior on JsrJobOperator#getJobInstanceCount
This commit is contained in:
@@ -116,7 +116,7 @@ import org.springframework.util.Assert;
|
||||
* @since 3.0
|
||||
*/
|
||||
public class JsrJobOperator implements JobOperator {
|
||||
private static final String BATCH_PROPERTY_CONTEXT_BEAN_NAME = "batchPropertyContext";
|
||||
private static final String BATCH_PROPERTY_CONTEXT_BEAN_NAME = "batchPropertyContext";
|
||||
|
||||
private org.springframework.batch.core.launch.JobOperator batchJobOperator;
|
||||
private JobExplorer jobExplorer;
|
||||
@@ -273,7 +273,13 @@ public class JsrJobOperator implements JobOperator {
|
||||
public int getJobInstanceCount(String jobName) throws NoSuchJobException,
|
||||
JobSecurityException {
|
||||
try {
|
||||
return jobExplorer.getJobInstanceCount(jobName);
|
||||
int count = jobExplorer.getJobInstanceCount(jobName);
|
||||
|
||||
if(count <= 0) {
|
||||
throw new NoSuchJobException("No job instances were found for job name " + jobName);
|
||||
} else {
|
||||
return count;
|
||||
}
|
||||
} catch (org.springframework.batch.core.launch.NoSuchJobException e) {
|
||||
throw new NoSuchJobException("No job instances were found for job name " + jobName);
|
||||
}
|
||||
|
||||
@@ -197,6 +197,13 @@ public class JsrJobOperatorTests {
|
||||
jsrJobOperator.getJobInstanceCount("myJob");
|
||||
}
|
||||
|
||||
@Test(expected=NoSuchJobException.class)
|
||||
public void testGetJobInstanceCountZeroInstancesReturned() throws Exception {
|
||||
when(jobExplorer.getJobInstanceCount("myJob")).thenReturn(0);
|
||||
|
||||
jsrJobOperator.getJobInstanceCount("myJob");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetJobInstancesRoseyScenario() {
|
||||
List<JobInstance> instances = new ArrayList<JobInstance>();
|
||||
@@ -313,9 +320,16 @@ public class JsrJobOperatorTests {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testStartMultipleTimesSameParameters() {
|
||||
public void testStartMultipleTimesSameParameters() throws Exception {
|
||||
jsrJobOperator = BatchRuntime.getJobOperator();
|
||||
|
||||
int jobInstanceCountBefore = 0;
|
||||
|
||||
try {
|
||||
jobInstanceCountBefore = jsrJobOperator.getJobInstanceCount("myJob3");
|
||||
} catch (NoSuchJobException ignore) {
|
||||
}
|
||||
|
||||
long run1 = jsrJobOperator.start("jsrJobOperatorTestJob", null);
|
||||
long run2 = jsrJobOperator.start("jsrJobOperatorTestJob", null);
|
||||
long run3 = jsrJobOperator.start("jsrJobOperatorTestJob", null);
|
||||
@@ -324,7 +338,9 @@ public class JsrJobOperatorTests {
|
||||
assertEquals(BatchStatus.COMPLETED, jsrJobOperator.getJobExecution(run2).getBatchStatus());
|
||||
assertEquals(BatchStatus.COMPLETED, jsrJobOperator.getJobExecution(run3).getBatchStatus());
|
||||
|
||||
assertTrue(3 >= jsrJobOperator.getJobInstanceCount("jsrJobOperatorTestJob"));
|
||||
int jobInstanceCountAfter = jsrJobOperator.getJobInstanceCount("myJob3");
|
||||
|
||||
assertTrue((jobInstanceCountAfter - jobInstanceCountBefore) == 3);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user