@Test public void testCustomBaseContextCustomWired() throws Exception { GenericApplicationContext context = new AnnotationConfigApplicationContext(BatchConfgiuration.class); JobOperator jobOperator = (JobOperator) context.getBean("jobOperator"); assertEquals(context, ReflectionTestUtils.getField(jobOperator, "baseContext")); long executionId = jobOperator.start("longRunningJob", null); // Give the job a chance to get started Thread.sleep(1000L); jobOperator.stop(executionId); // Give the job the chance to finish stopping Thread.sleep(1000L); assertEquals(BatchStatus.STOPPED, jobOperator.getJobExecution(executionId).getBatchStatus()); System.getProperties().remove("JSR-352-BASE-CONTEXT"); }
@Test public void testJobStopRoseyScenario() throws Exception { jsrJobOperator = BatchRuntime.getJobOperator(); long executionId = jsrJobOperator.start("longRunningJob", null); // Give the job a chance to get started Thread.sleep(1000L); jsrJobOperator.stop(executionId); // Give the job the chance to finish stopping Thread.sleep(1000L); assertEquals(BatchStatus.STOPPED, jsrJobOperator.getJobExecution(executionId).getBatchStatus()); }
@Test public void testCustomBaseContextJsrCompliant() throws Exception { System.setProperty("JSR-352-BASE-CONTEXT", "META-INF/alternativeJsrBaseContext.xml"); ReflectionTestUtils.setField(JsrJobOperator.BaseContextHolder.class, "instance", null); JobOperator jobOperator = BatchRuntime.getJobOperator(); Object transactionManager = ReflectionTestUtils.getField(jobOperator, "transactionManager"); assertTrue(transactionManager instanceof ResourcelessTransactionManager); long executionId = jobOperator.start("longRunningJob", null); // Give the job a chance to get started Thread.sleep(1000L); jobOperator.stop(executionId); // Give the job the chance to finish stopping Thread.sleep(1000L); assertEquals(BatchStatus.STOPPED, jobOperator.getJobExecution(executionId).getBatchStatus()); System.getProperties().remove("JSR-352-BASE-CONTEXT"); }
@Override public void stop(final long executionId) { operator.stop(executionId); }
public void stopJobWithoutWaitingForResult(long jobInstanceId) throws NoSuchJobExecutionException, JobExecutionNotRunningException, JobSecurityException { jobOp.stop(jobInstanceId); }
@HEAD @Path("execution/stop/{id}") public void stop(final @PathParam("id") long executionId) { operator.stop(executionId); }
@Override public void stop(final long executionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException, JobSecurityException { getDelegate().stop(executionId); }
@Override public void execute() throws MojoExecutionException, MojoFailureException { getOrCreateOperator().stop(executionId); getLog().info("Stopped job #" + executionId); } }
@Override public void stop(long executionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException, JobSecurityException { Transaction tran = suspendTran(); try { jobOperator.stop(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())); } }
public JobExecution stopJobAndWaitForResult(JobExecution jobExecution) throws NoSuchJobExecutionException, JobExecutionNotRunningException, JobSecurityException, JobExecutionTimeoutException { JobExecution terminatedJobExecution = null; jobOp.stop(jobExecution.getExecutionId()); JobExecutionWaiter waiter = waiterFactory.createWaiter(jobExecution.getExecutionId(), jobOp, sleepTime); try { terminatedJobExecution = waiter.awaitTermination(); } catch (JobExecutionTimeoutException e) { logger.severe(TIMEOUT_MSG); Reporter.log(TIMEOUT_MSG); throw e; } return new TCKJobExecutionWrapper(terminatedJobExecution, jobOp); }
@Override public int stopAll() { Collection<JobExecution> result = jobExecutionDao.getRunningJobExecutions(); Collection<String> jsrJobNames = getJsrJobNames(); for (JobExecution jobExecution : result) { if(jsrJobOperator != null && jsrJobNames.contains(jobExecution.getJobInstance().getJobName())) { jsrJobOperator.stop(jobExecution.getId()); } else { jobExecution.stop(); jobRepository.update(jobExecution); } } return result.size(); }
private void batchStop(String batchId, HttpServletRequest req, HttpServletResponse resp) { Long executionId = extractExecutionId(batchId, resp); if (executionId == null) { return; } try { jobOperator.stop(executionId); reportSuccess(executionId, resp, BatchStatus.STOPPING.toString()); } catch (NoSuchJobExecutionException noSuchJob) { reportFailure(executionId, resp, "NoSuchJob"); } catch (JobExecutionNotRunningException notRunningException) { reportFailure(executionId, resp, "JobExecutionNotRunning"); } catch (Exception generalException) { StringBuilder msg = new StringBuilder("Failure in BatchExecution"); appendExceptionMsg(msg, generalException); reportFailure(executionId, resp, msg.toString()); } }
@Override public int stopAll() { Collection<JobExecution> result = jobExecutionDao.getRunningJobExecutions(); Collection<String> jsrJobNames = getJsrJobNames(); for (JobExecution jobExecution : result) { if(jsrJobOperator != null && jsrJobNames.contains(jobExecution.getJobInstance().getJobName())) { jsrJobOperator.stop(jobExecution.getId()); } else { jobExecution.stop(); jobRepository.update(jobExecution); } } return result.size(); }
@Override public JobExecution stop(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException { JobExecution jobExecution = getJobExecution(jobExecutionId); if (!jobExecution.isRunning()) { throw new JobExecutionNotRunningException("JobExecution is not running and therefore cannot be stopped"); } logger.info("Stopping job execution: " + jobExecution); Collection<String> jsrJobNames = getJsrJobNames(); if(jsrJobOperator != null && jsrJobNames.contains(jobExecution.getJobInstance().getJobName())) { jsrJobOperator.stop(jobExecutionId); jobExecution = getJobExecution(jobExecutionId); } else { jobExecution.stop(); jobRepository.update(jobExecution); } return jobExecution; }
@Override public JobExecution stop(Long jobExecutionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException { JobExecution jobExecution = getJobExecution(jobExecutionId); if (!jobExecution.isRunning()) { throw new JobExecutionNotRunningException("JobExecution is not running and therefore cannot be stopped"); } logger.info("Stopping job execution: " + jobExecution); Collection<String> jsrJobNames = getJsrJobNames(); if(jsrJobOperator != null && jsrJobNames.contains(jobExecution.getJobInstance().getJobName())) { jsrJobOperator.stop(jobExecutionId); jobExecution = getJobExecution(jobExecutionId); } else { jobExecution.stop(); jobRepository.update(jobExecution); } return jobExecution; }
@Override public void stop(final long executionId) throws NoSuchJobExecutionException, JobExecutionNotRunningException, JobSecurityException { checkState(); final ClassLoader current = WildFlySecurityManager.getCurrentContextClassLoaderPrivileged(); try { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(classLoader); final JobInstance instance = delegate.getJobInstance(executionId); validateJob(instance.getJobName()); delegate.stop(executionId); } finally { WildFlySecurityManager.setCurrentContextClassLoaderPrivileged(current); } }
/** * */ @Test public void testStopNoTran() 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).stop(0); } }); buildJobOperator(mockJobOperator, mockTranMgr).stop(0); }
/** * */ @Test(expected = IllegalArgumentException.class) public void testStopFail() 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).stop(0); will(throwException(new IllegalArgumentException())); oneOf(mockTranMgr).resume(mockTran); } }); buildJobOperator(mockJobOperator, mockTranMgr).stop(0); }
/** * */ @Test public void testStop() 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).stop(0); oneOf(mockTranMgr).resume(mockTran); } }); buildJobOperator(mockJobOperator, mockTranMgr).stop(0); }