Search in sources :

Example 11 with JobExecution

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);
    }
}
Also used : JobExecution(javax.batch.runtime.JobExecution) JobOperator(javax.batch.operations.JobOperator) Properties(java.util.Properties)

Example 12 with JobExecution

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());
}
Also used : JobExecution(javax.batch.runtime.JobExecution) ArrayList(java.util.ArrayList) JobOperator(javax.batch.operations.JobOperator) Properties(java.util.Properties) StepExecution(javax.batch.runtime.StepExecution) Test(org.junit.Test)

Example 13 with JobExecution

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);
}
Also used : JobExecution(javax.batch.runtime.JobExecution) JobOperator(javax.batch.operations.JobOperator) Properties(java.util.Properties) Test(org.junit.Test)

Example 14 with JobExecution

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);
}
Also used : JobExecution(javax.batch.runtime.JobExecution) Properties(java.util.Properties)

Example 15 with 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());
}
Also used : JobExecution(javax.batch.runtime.JobExecution)

Aggregations

JobExecution (javax.batch.runtime.JobExecution)25 JobOperator (javax.batch.operations.JobOperator)13 Test (org.junit.Test)12 Properties (java.util.Properties)8 TaggedJobExecution (com.ibm.jbatch.spi.TaggedJobExecution)6 JobInstance (javax.batch.runtime.JobInstance)5 ModelNode (org.jboss.dmr.ModelNode)5 ArrayList (java.util.ArrayList)3 StepExecution (javax.batch.runtime.StepExecution)3 ColumnFormatter (com.sun.enterprise.util.ColumnFormatter)2 NoSuchJobExecutionException (javax.batch.operations.NoSuchJobExecutionException)2 RunAsClient (org.jboss.arquillian.container.test.api.RunAsClient)2 HashMap (java.util.HashMap)1 List (java.util.List)1 TreeSet (java.util.TreeSet)1 NoSuchJobException (javax.batch.operations.NoSuchJobException)1