use of javax.batch.runtime.JobExecution in project quickstart by wildfly.
the class BatchRaceStage method run.
@Override
public void run(Race.Registration registration) throws Exception {
// retrieve the job operator
JobOperator jobOperator = BatchRuntime.getJobOperator();
// start the race.xml job
Long executionId = jobOperator.start("race", new Properties());
// would be nice if the job start would provide a Future object wrt the job execution, perhaps something for next spec revision
// just check every 1ms if the job status is completed
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
while (jobExecution.getBatchStatus() != BatchStatus.COMPLETED) {
Thread.sleep(1);
}
}
use of javax.batch.runtime.JobExecution in project javaee7-samples by javaee-samples.
the class BatchDecisionTest method testBatchDecision.
/**
* In the test, we're just going to invoke the batch execution and wait for completion. To validate the test
* expected behaviour we need to query +javax.batch.operations.JobOperator#getStepExecutions+ and the
* +javax.batch.runtime.Metric+ object available in the step execution.
*
* @throws Exception an exception if the batch could not complete successfully.
*/
@Test
public void testBatchDecision() throws Exception {
JobOperator jobOperator = BatchRuntime.getJobOperator();
Long executionId = jobOperator.start("myJob", new Properties());
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
List<String> executedSteps = new ArrayList<>();
for (StepExecution stepExecution : stepExecutions) {
executedSteps.add(stepExecution.getStepName());
}
// <1> Make sure that only two steps were executed.
assertEquals(2, stepExecutions.size());
// <2> Make sure that only the expected steps were executed an in order.
assertArrayEquals(new String[] { "step1", "step3" }, executedSteps.toArray());
// <3> Make sure that this step was never executed.
assertFalse(executedSteps.contains("step2"));
// <4> Job should be completed.
assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
}
use of javax.batch.runtime.JobExecution in project javaee7-samples by javaee-samples.
the class MyBatchletTest method testBatchletProcess.
/**
* In the test, we're just going to invoke the batch execution and wait for completion. To validate the test
* expected behaviour we just need to check the Batch Status in the +javax.batch.runtime.JobExecution+ object. We
* should get a +javax.batch.runtime.BatchStatus.COMPLETED+.
*
* @throws Exception an exception if the batch could not complete successfully.
*/
@Test
public void testBatchletProcess() throws Exception {
JobOperator jobOperator = BatchRuntime.getJobOperator();
Long executionId = jobOperator.start("myJob", new Properties());
JobExecution jobExecution = jobOperator.getJobExecution(executionId);
jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
// <1> Job should be completed.
assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
use of javax.batch.runtime.JobExecution in project wildfly by wildfly.
the class StartBatchServlet method doGet.
@Override
protected void doGet(final HttpServletRequest req, final HttpServletResponse resp) throws ServletException, IOException {
// Get the batch file name
final String jobXml = req.getParameter(JOB_XML_PARAMETER);
final String timeoutString = req.getParameter(TIMEOUT_PARAM);
final String wait = req.getParameter(WAIT_FOR_COMPLETION);
if (jobXml == null) {
throw new IllegalStateException(String.format("%s is a required parameter", JOB_XML_PARAMETER));
}
final Properties params = parseParams(req, Arrays.asList(TIMEOUT_PARAM, WAIT_FOR_COMPLETION));
final JobExecution jobExecution = service.start(jobXml, params);
long timeout = TimeoutUtil.adjust(timeoutString == null ? DEFAULT_TIMEOUT : Integer.parseInt(timeoutString));
long sleep = 100L;
final boolean waitForCompletion = (wait == null || Boolean.parseBoolean(wait));
boolean b = waitForCompletion;
while (b) {
switch(jobExecution.getBatchStatus()) {
case STARTED:
case STARTING:
case STOPPING:
try {
TimeUnit.MILLISECONDS.sleep(sleep);
} catch (InterruptedException e) {
throw new RuntimeException(e);
}
timeout -= sleep;
sleep = Math.max(sleep / 2, 100L);
break;
default:
b = false;
break;
}
if (timeout <= 0) {
throw new IllegalStateException(String.format("Batch job '%s' did not complete within allotted time.", jobXml));
}
}
if (waitForCompletion)
write(resp, jobExecution);
}
use of javax.batch.runtime.JobExecution in project wildfly by wildfly.
the class DeploymentDescriptorTestCase method testCompletion.
private void testCompletion(final long expectedExecutionId, final URL url) throws IOException, ExecutionException, TimeoutException {
final UrlBuilder builder = UrlBuilder.of(url, "start");
builder.addParameter(StartBatchServlet.JOB_XML_PARAMETER, "test-chunk");
builder.addParameter("reader.end", 10);
final String result = performCall(builder.build());
final JobExecution jobExecution = JobExecutionMarshaller.unmarshall(result);
Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
Assert.assertEquals(expectedExecutionId, jobExecution.getExecutionId());
}
Aggregations