Java Code Examples for javax.batch.operations.JobOperator#getStepExecutions()

The following examples show how to use javax.batch.operations.JobOperator#getStepExecutions() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CustomCheckPointUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenChunk_whenCustomCheckPoint_thenCommitCountIsThree() throws Exception {
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    Long executionId = jobOperator.start("customCheckPoint", new Properties());
    JobExecution jobExecution = jobOperator.getJobExecution(executionId);
    jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
    for (StepExecution stepExecution : jobOperator.getStepExecutions(executionId)) {
        if (stepExecution.getStepName()
            .equals("firstChunkStep")) {
            jobOperator.getStepExecutions(executionId)
                .stream()
                .map(BatchTestHelper::getCommitCount)
                .forEach(count -> assertEquals(3L, count.longValue()));
        }
    }
    assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
 
Example 2
Source File: SimpleChunkUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenChunk_thenBatch_CompletesWithSucess() throws Exception {
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    Long executionId = jobOperator.start("simpleChunk", new Properties());
    JobExecution jobExecution = jobOperator.getJobExecution(executionId);
    jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
    List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
    for (StepExecution stepExecution : stepExecutions) {
        if (stepExecution.getStepName()
            .equals("firstChunkStep")) {
            Map<Metric.MetricType, Long> metricsMap = BatchTestHelper.getMetricsMap(stepExecution.getMetrics());
            assertEquals(10L, metricsMap.get(Metric.MetricType.READ_COUNT)
                .longValue());
            assertEquals(10L / 2L, metricsMap.get(Metric.MetricType.WRITE_COUNT)
                .longValue());
            assertEquals(10L / 3 + (10L % 3 > 0 ? 1 : 0), metricsMap.get(Metric.MetricType.COMMIT_COUNT)
                .longValue());
        }
    }
    assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
 
Example 3
Source File: SimpleChunkUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenChunk__thenBatch_fetchInformation() throws Exception {
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    Long executionId = jobOperator.start("simpleChunk", new Properties());
    JobExecution jobExecution = jobOperator.getJobExecution(executionId);
    jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
    // job name contains simpleBatchLet which is the name of the file
    assertTrue(jobOperator.getJobNames().contains("simpleChunk"));
    // job parameters are empty
    assertTrue(jobOperator.getParameters(executionId).isEmpty());
    // step execution information
    List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
    assertEquals("firstChunkStep", stepExecutions.get(0).getStepName());
    // finding out batch status
    assertEquals(BatchStatus.COMPLETED, stepExecutions.get(0).getBatchStatus());
    Map<Metric.MetricType, Long> metricTest = BatchTestHelper.getMetricsMap(stepExecutions.get(0).getMetrics());
    assertEquals(10L, metricTest.get(Metric.MetricType.READ_COUNT).longValue());
    assertEquals(5L, metricTest.get(Metric.MetricType.FILTER_COUNT).longValue());
    assertEquals(4L, metricTest.get(Metric.MetricType.COMMIT_COUNT).longValue());
    assertEquals(5L, metricTest.get(Metric.MetricType.WRITE_COUNT).longValue());
    assertEquals(0L, metricTest.get(Metric.MetricType.READ_SKIP_COUNT).longValue());
    assertEquals(0L, metricTest.get(Metric.MetricType.WRITE_SKIP_COUNT).longValue());
    assertEquals(0L, metricTest.get(Metric.MetricType.PROCESS_SKIP_COUNT).longValue());
    assertEquals(0L, metricTest.get(Metric.MetricType.ROLLBACK_COUNT).longValue());
    assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
 
Example 4
Source File: SimpleErrorChunkUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenChunkError_thenErrorSkipped_CompletesWithSuccess() throws Exception {
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    Long executionId = jobOperator.start("simpleErrorSkipChunk", new Properties());
    JobExecution jobExecution = jobOperator.getJobExecution(executionId);
    jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
    List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
    for (StepExecution stepExecution : stepExecutions) {
        if (stepExecution.getStepName()
            .equals("errorStep")) {
            jobOperator.getStepExecutions(executionId)
            .stream()
            .map(BatchTestHelper::getProcessSkipCount)
            .forEach(skipCount -> assertEquals(1L, skipCount.longValue()));
        }
    }
    assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
 
Example 5
Source File: JobSequenceUnitTest.java    From tutorials with MIT License 6 votes vote down vote up
@Test
public void givenSplit_thenBatch_CompletesWithSuccess() throws Exception {
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    Long executionId = jobOperator.start("splitJobSequence", 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());
    }
    assertEquals(3, stepExecutions.size());
    assertTrue(executedSteps.contains("splitJobSequenceStep1"));
    assertTrue(executedSteps.contains("splitJobSequenceStep2"));
    assertTrue(executedSteps.contains("splitJobSequenceStep3"));
    assertTrue(executedSteps.get(0).equals("splitJobSequenceStep1") || executedSteps.get(0).equals("splitJobSequenceStep2"));
    assertTrue(executedSteps.get(1).equals("splitJobSequenceStep1") || executedSteps.get(1).equals("splitJobSequenceStep2"));
    assertTrue(executedSteps.get(2).equals("splitJobSequenceStep3"));
    assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
 
Example 6
Source File: TxErrorTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void testRolledBackDuringWork() {
    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    long executionId = jobOperator.start("txtest1", null);
    BatchStatus batchStatus = Batches.waitFor(jobOperator, executionId);
    Assert.assertEquals(batchStatus, BatchStatus.FAILED);
    Assert.assertEquals(TxErrorWriter1.written.intValue(), 3);

    List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
    Assert.assertEquals(stepExecutions.size(), 1);
    StepExecution stepExecution = stepExecutions.get(0);
    Metric[] metrics = stepExecution.getMetrics();
    assertMetric(Metric.MetricType.READ_COUNT, 2, metrics);
    assertMetric(Metric.MetricType.WRITE_COUNT, 2, metrics);
    assertMetric(Metric.MetricType.ROLLBACK_COUNT, 1, metrics);
}
 
Example 7
Source File: DeciderTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void testDeciderRestart() {

    JobOperator jobOperator = BatchRuntime.getJobOperator();
    long executionId = jobOperator.start("decider-test", new Properties());

    BatchStatus batchStatus = Batches.waitFor(jobOperator, executionId);
    assertEquals(batchStatus, BatchStatus.STOPPED);
    assertEquals(jobOperator.getJobExecution(executionId).getExitStatus(), "decider-stop");

    List<StepExecution> stepExecutions = jobOperator.getStepExecutions(executionId);
    assertEquals(stepExecutions.size(), 1);

    long restartExecutionId = jobOperator.restart(executionId, new Properties());

    BatchStatus restartStatus = Batches.waitFor(jobOperator, restartExecutionId);
    assertEquals(restartStatus, BatchStatus.COMPLETED);

    String exitStatus = jobOperator.getJobExecution(restartExecutionId).getExitStatus();
    assertEquals("COMPLETED", exitStatus);

    List<StepExecution> restartExecutions = jobOperator.getStepExecutions(restartExecutionId);
    assertEquals(restartExecutions.size(), 1);
    assertEquals(restartExecutions.get(0).getStepName(), "executeOnRestart");
}
 
Example 8
Source File: PartitionMetricsTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void run() {
    final JobOperator op = BatchRuntime.getJobOperator();
    final long id = op.start("partition-metrics", null);
    Batches.waitForEnd(op, id);
    final List<StepExecution> steps = op.getStepExecutions(id);
    assertEquals(1, steps.size());
    final StepExecution exec = steps.iterator().next();
    final Metric[] metrics = exec.getMetrics();
    int checked = 0;
    for (final Metric metric : metrics) {
        if (Metric.MetricType.ROLLBACK_COUNT == metric.getType()) {
            assertEquals(metric.getValue(), 1);
            checked++;
        } else if (Metric.MetricType.READ_SKIP_COUNT == metric.getType()) {
            assertEquals(metric.getValue(), 1);
            checked++;
        }
    }
    assertEquals(checked, 2);
}
 
Example 9
Source File: JobSequenceUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenDecider_thenBatch_CompleteWithSuccess() throws Exception {
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    Long executionId = jobOperator.start("decideJobSequence", 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());
    }
    assertEquals(2, jobOperator.getStepExecutions(executionId).size());
    assertArrayEquals(new String[] { "firstBatchStepStep1", "firstBatchStepStep3" }, executedSteps.toArray());
    assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
 
Example 10
Source File: DefaultDataRepresentationServiceTest.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
@Test
public void testBatchExecutionWithCheckpoints() {
    final JobOperator op = BatchRuntime.getJobOperator();
    final long id = op.start("checkpoint-storage-test", null);
    Batches.waitForEnd(op, id);

    final List<StepExecution> steps = op.getStepExecutions(id);
    assertEquals(1, steps.size());
    final StepExecution exec = steps.iterator().next();
    Assert.assertEquals(BatchStatus.FAILED, exec.getBatchStatus());

    // now try to restart the batch again
    long restartId = op.restart(id, null);
    Batches.waitForEnd(op, restartId);
}
 
Example 11
Source File: StartableCommand.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
private JobExecution report(final JobOperator operator, final long id) {
    final JobExecution execution = operator.getJobExecution(id);

    info("");
    info(LINE);

    info("Batch status: " + statusToString(execution.getBatchStatus()));
    info("Exit status:  " + execution.getExitStatus());
    if (execution.getEndTime() != null && execution.getStartTime() != null) {
        info("Duration:     " + TimeUnit.MILLISECONDS.toSeconds(execution.getEndTime().getTime() - execution.getStartTime().getTime()) + "s");
    }

    if (BatchStatus.FAILED.equals(execution.getBatchStatus())) {
        final Collection<StepExecution> stepExecutions = operator.getStepExecutions(id);
        for (final StepExecution stepExecution : stepExecutions) {
            if (BatchStatus.FAILED.equals(stepExecution.getBatchStatus())) {
                info("");
                info("Step name       : " + stepExecution.getStepName());
                info("Step status     : " + statusToString(stepExecution.getBatchStatus()));
                info("Step exit status: " + stepExecution.getExitStatus());
                break;
            }
        }
    }

    info(LINE);
    return execution;
}