@Test(expected=NoSuchJobExecutionException.class) public void testAbandonNoSuchJob() throws Exception { jsrJobOperator.abandon(5L); }
@Test(expected=JobExecutionIsRunningException.class) public void testAbandonJobRunning() throws Exception { JobExecution jobExecution = new JobExecution(5L); jobExecution.setStartTime(new Date(1L)); when(jobExplorer.getJobExecution(5L)).thenReturn(jobExecution); jsrJobOperator.abandon(5L); }
@Test public void testAbandonRoseyScenario() throws Exception { JobExecution jobExecution = new JobExecution(5L); jobExecution.setEndTime(new Date()); when(jobExplorer.getJobExecution(5L)).thenReturn(jobExecution); jsrJobOperator.abandon(5L); ArgumentCaptor<JobExecution> executionCaptor = ArgumentCaptor.forClass(JobExecution.class); verify(jobRepository).update(executionCaptor.capture()); assertEquals(org.springframework.batch.core.BatchStatus.ABANDONED, executionCaptor.getValue().getStatus()); }
@Test(expected = JobRestartException.class) public void testRestartAbandoned() throws Exception { jsrJobOperator = BatchRuntime.getJobOperator(); javax.batch.runtime.JobExecution execution = runJob("jsrJobOperatorTestRestartAbandonJob", null, TIMEOUT); assertEquals(BatchStatus.FAILED, execution.getBatchStatus()); jsrJobOperator.abandon(execution.getExecutionId()); jsrJobOperator.restart(execution.getExecutionId(), null); }
@Override public void abandon(final long executionId) { operator.abandon(executionId); }
public void abandonJobExecution(long executionId) throws NoSuchJobInstanceException, JobExecutionIsRunningException, JobSecurityException, NoSuchJobExecutionException { jobOp.abandon(executionId); }
@HEAD @Path("execution/abandon/{id}") public void abandon(final @PathParam("id") long executionId) { operator.abandon(executionId); }
@Override public void abandon(final long executionId) throws NoSuchJobExecutionException, JobExecutionIsRunningException, JobSecurityException { getDelegate().abandon(executionId); }
@Override public void execute() throws MojoExecutionException, MojoFailureException { getOrCreateOperator().abandon(executionId); getLog().info("Abandonned job #" + executionId); } }
@Override public void abandon(long executionId) throws NoSuchJobExecutionException, JobExecutionIsRunningException, JobSecurityException { Transaction tran = suspendTran(); try { jobOperator.abandon(executionId); } finally { resumeTran(tran); } }
@Override public void process(final Exchange exchange) throws Exception { final long id; if (stop) { final long stopId = exchange.getIn().getHeader(JBATCH_EXECUTION_ID, Long.class); operator.stop(stopId); return; } else if (abandon) { final long abandonId = exchange.getIn().getHeader(JBATCH_EXECUTION_ID, Long.class); operator.abandon(abandonId); return; } else if (restart) { final long restartId = exchange.getIn().getHeader(JBATCH_EXECUTION_ID, Long.class); id = operator.restart(restartId, toProperties(exchange.getIn().getHeaders())); } else { id = operator.start(jobName, toProperties(exchange.getIn().getHeaders())); } exchange.getIn().setHeader(JBATCH_EXECUTION_ID, id); exchange.getIn().setHeader(JBATCH_OPERATOR, operator); if (synchronous > 0) { final Collection<BatchStatus> endStatuses = Arrays.asList(BatchStatus.COMPLETED, BatchStatus.FAILED); do { try { Thread.sleep(synchronous); } catch (final InterruptedException e) { return; } } while (!endStatuses.contains(operator.getJobExecution(id).getBatchStatus())); } }
@Override public JobExecution abandon(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException { JobExecution jobExecution = getJobExecution(jobExecutionId); if (jobExecution.getStatus().isLessThan(BatchStatus.STOPPING)) { throw new JobExecutionAlreadyRunningException( "JobExecution is running or complete and therefore cannot be aborted"); } logger.info("Aborting job execution: " + jobExecution); Collection<String> jsrJobNames = getJsrJobNames(); JobInstance jobInstance = jobExecution.getJobInstance(); if(jsrJobOperator != null && jsrJobNames.contains(jobInstance.getJobName())) { jsrJobOperator.abandon(jobExecutionId); jobExecution = getJobExecution(jobExecutionId); } else { jobExecution.upgradeStatus(BatchStatus.ABANDONED); jobExecution.setEndTime(new Date()); jobRepository.update(jobExecution); } return jobExecution; }
@Override public JobExecution abandon(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionAlreadyRunningException { JobExecution jobExecution = getJobExecution(jobExecutionId); if (jobExecution.getStatus().isLessThan(BatchStatus.STOPPING)) { throw new JobExecutionAlreadyRunningException( "JobExecution is running or complete and therefore cannot be aborted"); } logger.info("Aborting job execution: " + jobExecution); Collection<String> jsrJobNames = getJsrJobNames(); JobInstance jobInstance = jobExecution.getJobInstance(); if(jsrJobOperator != null && jsrJobNames.contains(jobInstance.getJobName())) { jsrJobOperator.abandon(jobExecutionId); jobExecution = getJobExecution(jobExecutionId); } else { jobExecution.upgradeStatus(BatchStatus.ABANDONED); jobExecution.setEndTime(new Date()); jobRepository.update(jobExecution); } return jobExecution; }
@Override public void abandon(final long executionId) throws NoSuchJobExecutionException, JobExecutionIsRunningException, JobSecurityException { checkState(); final ClassLoader current = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader); final JobInstance instance = delegate.getJobInstance(executionId); validateJob(instance.getJobName()); delegate.abandon(executionId); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(current); } }
JbatchUtil.waitForStop(runningExecution, () -> JOB_OPERATOR.abandon(runningExecution.getExecutionId()));
JbatchUtil.waitForStop(runningExecution, () -> JOB_OPERATOR.abandon(runningExecution.getExecutionId()));
/** * */ @Test public void testAbandonNoTran() throws Exception { final JobOperator mockJobOperator = mockery.mock(JobOperator.class); final TransactionManager mockTranMgr = mockery.mock(TransactionManager.class); mockery.checking( new Expectations() { { oneOf(mockTranMgr).suspend(); will(returnValue(null)); oneOf(mockJobOperator).abandon(0); } }); buildJobOperator(mockJobOperator, mockTranMgr).abandon(0); }
/** * */ @Test(expected = IllegalArgumentException.class) public void testAbandonFail() throws Exception { final JobOperator mockJobOperator = mockery.mock(JobOperator.class); final TransactionManager mockTranMgr = mockery.mock(TransactionManager.class); final Transaction mockTran = mockery.mock(Transaction.class); mockery.checking( new Expectations() { { oneOf(mockTranMgr).suspend(); will(returnValue(mockTran)); oneOf(mockJobOperator).abandon(0); will(throwException(new IllegalArgumentException())); oneOf(mockTranMgr).resume(mockTran); } }); buildJobOperator(mockJobOperator, mockTranMgr).abandon(0); }
/** * */ @Test public void testAbandon() throws Exception { final JobOperator mockJobOperator = mockery.mock(JobOperator.class); final TransactionManager mockTranMgr = mockery.mock(TransactionManager.class); final Transaction mockTran = mockery.mock(Transaction.class); mockery.checking( new Expectations() { { oneOf(mockTranMgr).suspend(); will(returnValue(mockTran)); oneOf(mockJobOperator).abandon(0); oneOf(mockTranMgr).resume(mockTran); } }); buildJobOperator(mockJobOperator, mockTranMgr).abandon(0); }