AsyncJobOperatorImpl implements JobOperator { @Override public int start(String[] args) { try { while (!asyncBatchStopper.canStop()) { BatchJobListResult batchJobListResult = jobControlFinder .resolveBatchJobResult(args); if (batchJobListResult == null) { pollingSleep(); continue; } asyncJobLauncher .executeJob(batchJobListResult.getJobSequenceId()); } } finally { asyncJobLauncher.shutdown(); } return 0; } AsyncJobOperatorImpl(JobControlFinder jobControlFinder,
            AsyncJobLauncher asyncJobLauncher,
            AsyncBatchStopper asyncBatchStopper); @Override int start(String[] args);  }
@Test public void testStart01() throws Exception { doReturn(true).when(asyncBatchStopper).canStop(); String[] args = new String[] {}; doReturn(new BatchJobListResult()).when(jobControlFinder) .resolveBatchJobResult(args); AsyncJobOperatorImpl asyncJobOperator = new AsyncJobOperatorImpl( jobControlFinder, asyncJobLauncher, asyncBatchStopper); assertEquals(0, asyncJobOperator.start(new String[] {})); verify(jobControlFinder, never()).resolveBatchJobResult(args); verify(asyncJobLauncher).shutdown(); }
@Test public void testStart02() throws Exception { doReturn(false).doReturn(true).when(asyncBatchStopper).canStop(); String[] args = new String[] {}; doReturn(null).when(jobControlFinder).resolveBatchJobResult(args); doNothing().when(asyncJobLauncher).executeJob(anyString()); AsyncJobOperatorImpl asyncJobOperator = new AsyncJobOperatorImpl( jobControlFinder, asyncJobLauncher, asyncBatchStopper); assertEquals(0, asyncJobOperator.start(new String[] {})); verify(asyncJobLauncher, never()).executeJob(anyString()); verify(asyncJobLauncher).shutdown(); }
@Test public void testStart03() throws Exception { doReturn(false).doReturn(true).when(asyncBatchStopper).canStop(); String[] args = new String[] {}; BatchJobListResult result = new BatchJobListResult() {{ setJobSequenceId("jobSequenceId"); }}; doReturn(result).when(jobControlFinder) .resolveBatchJobResult(args); doNothing().when(asyncJobLauncher).executeJob(anyString()); AsyncJobOperatorImpl asyncJobOperator = new AsyncJobOperatorImpl( jobControlFinder, asyncJobLauncher, asyncBatchStopper); assertEquals(0, asyncJobOperator.start(new String[] {})); verify(asyncJobLauncher, times(1)).executeJob("jobSequenceId"); verify(asyncJobLauncher).shutdown(); }
@Test public void testStart04() throws Exception { doReturn(false).doReturn(false).doReturn(false).doReturn(true) .when(asyncBatchStopper).canStop(); String[] args = new String[] {}; BatchJobListResult result = new BatchJobListResult() {{ setJobSequenceId("jobSequenceId"); }}; doReturn(result).when(jobControlFinder) .resolveBatchJobResult(args); doNothing().when(asyncJobLauncher).executeJob(anyString()); AsyncJobOperatorImpl asyncJobOperator = new AsyncJobOperatorImpl( jobControlFinder, asyncJobLauncher, asyncBatchStopper); assertEquals(0, asyncJobOperator.start(new String[] {})); verify(asyncJobLauncher, times(3)).executeJob("jobSequenceId"); verify(asyncJobLauncher).shutdown(); }
@Test public void testStart05() throws Exception { doReturn(false).when(asyncBatchStopper).canStop(); String[] args = new String[] {}; BatchJobListResult result = new BatchJobListResult() {{ setJobSequenceId("jobSequenceId"); }}; doReturn(result).when(jobControlFinder) .resolveBatchJobResult(args); doNothing().when(asyncJobLauncher).executeJob(anyString()); IllegalStateException e = new IllegalStateException( "job execution failed."); doThrow(e).when(asyncJobLauncher).executeJob("jobSequenceId"); AsyncJobOperatorImpl asyncJobOperator = new AsyncJobOperatorImpl( jobControlFinder, asyncJobLauncher, asyncBatchStopper); try { asyncJobOperator.start(new String[] {}); fail(); } catch (IllegalStateException ise) { assertThat(ise, is(e)); } verify(asyncJobLauncher).shutdown(); }