javax.batch.runtime.BatchRuntime Java Examples

The following examples show how to use javax.batch.runtime.BatchRuntime. 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: 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 #2
Source File: BatchEEMojoBase.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
protected JobOperator getOrCreateOperator() {
    if (operator == null) {
        synchronized (this) {
            if (operator == null) {
                if (jobOperatorClass != null) {
                    try {
                        operator = JobOperator.class.cast(Thread.currentThread().getContextClassLoader().loadClass(jobOperatorClass).newInstance());
                    } catch (final Exception e) {
                        throw new IllegalArgumentException("JobOperator " + jobOperatorClass + " can't be used", e);
                    }
                } else if (clientConfiguration == null) {
                    configureBatchEE();
                    operator = BatchRuntime.getJobOperator();
                } else {
                    operator = BatchEEJAXRSClientFactory.newClient(clientConfiguration);
                }
            }
        }
    }
    return operator;
}
 
Example #3
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 #4
Source File: MainTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void instances() {
    // ensure we have at least one thing to print
    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    final long id = jobOperator.start("sample", null);

    main(new String[]{"instances", "-name", "sample"});

    // output looks like:
    // sample has 3 job instances
    //
    // instance id
    // -----------
    // 0
    // 1


    assertThat(stdout.getLog(), containsString("sample has"));
    assertThat(stdout.getLog(), containsString("instance id"));

    Batches.waitForEnd(jobOperator, id);
}
 
Example #5
Source File: CamelReaderTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void read() throws Exception {
    final ProducerTemplate tpl = CamelBridge.CONTEXT.createProducerTemplate();

    final JobOperator jobOperator = BatchRuntime.getJobOperator();

    final long id = jobOperator.start("camel-reader", new Properties());

    while (DirectEndpoint.class.cast(CamelBridge.CONTEXT.getEndpoint("direct:reader")).getConsumer() == null) {
        Thread.sleep(100);
    }

    tpl.sendBody("direct:reader", "input#1");
    tpl.sendBody("direct:reader", null);

    Batches.waitForEnd(jobOperator, id);

    assertEquals(StoreItems.ITEMS.size(), 1);
    assertEquals("input#1", StoreItems.ITEMS.get(0));
}
 
Example #6
Source File: CamelProcessorTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void process() throws Exception {
    final List<Exchange> exchanges = new ArrayList<Exchange>(2);
    final Consumer consumer = CamelBridge.CONTEXT.getEndpoint("direct:processor").createConsumer(new Processor() {
        @Override
        public void process(final Exchange exchange) throws Exception {
            exchanges.add(exchange);
        }
    });
    consumer.start();

    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    Batches.waitForEnd(jobOperator, jobOperator.start("camel-processor", new Properties()));
    assertEquals(StoreItems.ITEMS.size(), 2);
    assertEquals(exchanges.size(), 2);

    for (int i = 1; i <= 2; i++) {
        assertEquals("" + i, StoreItems.ITEMS.get(i - 1));
        assertEquals("" + i, exchanges.get(i - 1).getIn().getBody());
    }

    consumer.stop();
}
 
Example #7
Source File: BatchArquillianTest.java    From thorntail with Apache License 2.0 6 votes vote down vote up
private void waitForCompletion(final long executionId, final int timeout, final TimeUnit unit) {
    final JobExecution jobExecution = BatchRuntime.getJobOperator().getJobExecution(executionId);
    long time = unit.toMillis(timeout);
    long sleep = 100;
    boolean complete = false;
    while (!complete && time > 0) {
        switch (jobExecution.getBatchStatus()) {
            case STARTED:
            case STARTING:
            case STOPPING:
                try {
                    TimeUnit.MILLISECONDS.sleep(sleep);
                } catch (InterruptedException e) {
                    throw new RuntimeException(e);
                }
                time -= sleep;
                sleep = Math.max(sleep / 2, 100L);
                break;
            default:
                complete = true;
                break;
        }
    }
    Assert.assertTrue("Batch job did not complete withing allotted time.", complete);
}
 
Example #8
Source File: AsyncEjbBatchThreadPoolService.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Override
public void shutdown() {
    Set<BatchWorkUnit> runningBatchWorkUnits = threadExecutorEjb.getRunningBatchWorkUnits();
    if (!runningBatchWorkUnits.isEmpty()) {
        JobOperator jobOperator = BatchRuntime.getJobOperator();
        for (BatchWorkUnit batchWorkUnit : runningBatchWorkUnits) {
            try {
                long executionId = batchWorkUnit.getJobExecutionImpl().getExecutionId();
                if (executionId >= 0) {
                    jobOperator.stop(executionId);
                }
            } catch(Exception e) {
                logger.log(Level.SEVERE, "Failure while shutting down execution", e);
            }
        }
    }
}
 
Example #9
Source File: JsonpReaderTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void read() {
    IOs.write("target/work/jsonp-input.json", "[" +
        "  {" +
        "    \"v1\":\"record 1 # field 1\"," +
        "    \"v2\":\"record 1 # field 2\"" +
        "  }," +
        "  {" +
        "    \"v1\":\"record 2 # field 1\"," +
        "    \"v2\":\"record 2 # field 2\"" +
        "  }" +
        "]");

    final JobOperator operator = BatchRuntime.getJobOperator();
    Batches.waitForEnd(operator, operator.start("jsonp-reader", new Properties()));
    assertEquals(Writer.ITEMS.size(), 2);
    for (int i = 1; i < Writer.ITEMS.size() + 1; i++) {
        final JsonObject record = Writer.ITEMS.get(i - 1);
        assertEquals("record " + i + " # field 1", record.getString("v1"));
        assertEquals("record " + i + " # field 2", record.getString("v2"));
    }
}
 
Example #10
Source File: CommonsCsvReaderWithMapperTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void read() throws Exception {
    final String path = "target/work/CommonsCsvReaderWithMapperTest.txt";

    final Properties jobParams = new Properties();
    jobParams.setProperty("input", path);

    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    IOs.write(path, "v11,v12\nv21,v22\nv31,v32");
    Batches.waitForEnd(jobOperator, jobOperator.start("csv-reader-mapper", jobParams));

    final int size = StoreItems.ITEMS.size();
    assertEquals(size, 3);
    for (int i = 1; i <= size; i++) {
        final Record record = StoreItems.ITEMS.get(i - 1);
        assertEquals("v" + i + "1", record.c1);
        assertEquals("v" + i + "2", record.c2);
    }
}
 
Example #11
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 #12
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 #13
Source File: MainTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void executions() {
    // ensure we have at least one thing to print
    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    final long id = jobOperator.start("sample", null);

    // output looks like:
    // Executions of sample for instance 5
    // execution id	|	batch status	|	exit status	|	start time	|	end time
    //          5	|	   COMPLETED	|	  COMPLETED	|	sam. janv. 04 17:20:24 CET 2014	|	sam. janv. 04 17:20:24 CET 2014


    Batches.waitForEnd(jobOperator, id);
    main(new String[]{"executions", "-id", Long.toString(id)});

    assertThat(stdout.getLog(), containsString("Executions of sample for instance " + id));
    assertThat(stdout.getLog(), containsString("COMPLETED"));
}
 
Example #14
Source File: BatchTestHelper.java    From tutorials with MIT License 6 votes vote down vote up
public static JobExecution keepTestStopped(JobExecution jobExecution) throws InterruptedException {
    int maxTries = 0;
    while (!jobExecution.getBatchStatus()
        .equals(BatchStatus.STOPPED)) {
        if (maxTries < MAX_TRIES) {
            maxTries++;
            Thread.sleep(THREAD_SLEEP);
            jobExecution = BatchRuntime.getJobOperator()
                .getJobExecution(jobExecution.getExecutionId());
        } else {
            break;
        }
    }
    Thread.sleep(THREAD_SLEEP);
    return jobExecution;
}
 
Example #15
Source File: MainTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void status() {
    // ensure we have at least one thing to print
    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    final long id = jobOperator.start("sample", null);

    main(new String[]{"status"});

    // output looks like
    //      Name   	|	execution id	|	batch status	|	exit status	|	start time	|	end time
    //      sample	|	           1	|	   COMPLETED	|	  COMPLETED	|	sam. janv. 04 17:22:51 CET 2014	|	sam. janv. 04 17:22:51 CET 2014


    assertThat(stdout.getLog(), containsString("sample\t|"));
    assertThat(stdout.getLog(), containsString("COMPLETED"));

    Batches.waitForEnd(jobOperator, id);
}
 
Example #16
Source File: BatchTestHelper.java    From tutorials with MIT License 6 votes vote down vote up
public static JobExecution keepTestAlive(JobExecution jobExecution) throws InterruptedException {
    int maxTries = 0;
    while (!jobExecution.getBatchStatus()
        .equals(BatchStatus.COMPLETED)) {
        if (maxTries < MAX_TRIES) {
            maxTries++;
            Thread.sleep(THREAD_SLEEP);
            jobExecution = BatchRuntime.getJobOperator()
                .getJobExecution(jobExecution.getExecutionId());
        } else {
            break;
        }
    }
    Thread.sleep(THREAD_SLEEP);
    return jobExecution;
}
 
Example #17
Source File: CommonsCsvReaderWithDefaultMapperTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void read() throws Exception {
    final String path = "target/work/CommonsCsvReaderWithDefaultMapperTestread.txt";

    final Properties jobParams = new Properties();
    jobParams.setProperty("input", path);

    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    IOs.write(path, "v11,v12\nv21,v22\nv31,v32");
    Batches.waitForEnd(jobOperator, jobOperator.start("csv-reader-defaultmapper", jobParams));

    final int size = StoreItems.ITEMS.size();
    assertEquals(size, 3);
    for (int i = 1; i <= size; i++) {
        final Indexed record = Indexed.class.cast(StoreItems.ITEMS.get(i - 1));
        assertEquals("v" + i + "1", record.c1);
        assertEquals("v" + i + "2", record.c2);
    }
}
 
Example #18
Source File: JSefaXmlReaderTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void read() throws Exception {
    final String path = "target/work/JSefaXmlReader.txt";

    final Properties jobParams = new Properties();
    jobParams.setProperty("input", path);

    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    IOs.write(path, "<Records><Record><value1>v11</value1><value2>v12</value2></Record><Record><value1>v21</value1><value2>v22</value2></Record><Record><value1>v31</value1><value2>v32</value2></Record></Records>");
    Batches.waitForEnd(jobOperator, jobOperator.start("jsefa-xml-reader", jobParams));

    final int size = StoreItems.ITEMS.size();
    assertEquals(size, 3);
    for (int i = 1; i <= size; i++) {
        final Record Record = StoreItems.ITEMS.get(i - 1);
        assertEquals(Record.getValue1(), "v" + i + "1");
        assertEquals(Record.getValue2(), "v" + i + "2");
    }
}
 
Example #19
Source File: JSefaCsvReaderConverterTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void testRead() throws Exception {
    String path = "target/work/JSefaCsvReaderWithConverter.csv";

    IOs.write(path,
              "string1;123;1;201007161200\n" +
              "string2;345;2;199004041350\n" +
              "string3;987654321;1;197905072358");

    Properties props = new Properties();
    props.setProperty("input", path);
    props.setProperty("specialRecordDelimiter", ";");

    JobOperator operator = BatchRuntime.getJobOperator();
    Batches.waitForEnd(operator, operator.start("jsefa-csv-reader-converter", props));

    Set<RecordWithConverter> expectedItems = new HashSet<RecordWithConverter>();
    expectedItems.add(new RecordWithConverter("string1", 123L, RecordWithConverter.RecordEnum.ONE, new GregorianCalendar(2010, Calendar.JULY, 16, 12, 0).getTime()));
    expectedItems.add(new RecordWithConverter("string2", 345L, RecordWithConverter.RecordEnum.TWO, new GregorianCalendar(1990, Calendar.APRIL, 4, 13, 50).getTime()));
    expectedItems.add(new RecordWithConverter("string3", 987654321L, RecordWithConverter.RecordEnum.ONE, new GregorianCalendar(1979, Calendar.MAY, 7, 23, 58).getTime()));

    Assert.assertEquals(Storage.STORAGE.size(), expectedItems.size());
    Assert.assertTrue(Storage.STORAGE.containsAll(expectedItems));
}
 
Example #20
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 #21
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 #22
Source File: JSefaCsvReaderTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void testReadWithHeader() {
    String path = "target/work/JsefaCsvReaderWithHeader.csv";

    Properties properties = new Properties();
    properties.setProperty("input", path);

    StringBuilder csvBuilder = new StringBuilder(200);
    csvBuilder.append("firstName;lastName;street;zip;city");
    for (int i = 0; i < 10; i++) {
        csvBuilder.append(IOs.LINE_SEPARATOR)
                  .append(CsvUtil.toCsv(new PersonWithAddress("firstName_" + i,
                                                              "lastName_" + i,
                                                              new Address("street_" + i,
                                                                          "zip_" + i,
                                                                          "city_" + i))));
    }

    IOs.write(path, csvBuilder.toString());

    JobOperator operator = BatchRuntime.getJobOperator();
    Batches.waitForEnd(operator, operator.start("jsefa-csv-reader-header", properties));

    Assert.assertEquals(Storage.ITEMS.size(), 10);

}
 
Example #23
Source File: JSefaCsvReaderTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void read() throws Exception {
    final String path = "target/work/JSefaCsvReader.txt";

    final Properties jobParams = new Properties();
    jobParams.setProperty("input", path);

    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    IOs.write(path, "v11;v12\nv21;v22\nv31;v32");
    Batches.waitForEnd(jobOperator, jobOperator.start("jsefa-csv-reader", jobParams));

    final int size = StoreItems.ITEMS.size();
    assertEquals(size, 3);
    for (int i = 1; i <= size; i++) {
        final Record record = StoreItems.ITEMS.get(i - 1);
        assertEquals(record.getValue1(), "v" + i + "1");
        assertEquals(record.getValue2(), "v" + i + "2");
    }
}
 
Example #24
Source File: AbstractThreadPoolService.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Override
public void shutdown() throws BatchContainerServiceException {
    this.shutdown = true;
    if (!runningBatchWorkUnits.isEmpty()) {
        JobOperator jobOperator = BatchRuntime.getJobOperator();
        for (BatchWorkUnit batchWorkUnit : runningBatchWorkUnits) {
            try {
                long executionId = batchWorkUnit.getJobExecutionImpl().getExecutionId();
                if (executionId >= 0) {
                    jobOperator.stop(executionId);
                }
            } catch (Exception e) {
                LOGGER.log(Level.SEVERE, "Failure while shutting down execution", e);
            }
        }
    }

    executorService.shutdownNow();
    executorService = null;
}
 
Example #25
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 #26
Source File: ChainProcessorTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void chain() throws Exception {
    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    Batches.waitForEnd(jobOperator, jobOperator.start("chain-processor", new Properties()));

    assertEquals(P1.instance.items.size(), 2);
    assertEquals(P2.instance.items.size(), 2);

    final int p1Hash = P1.instance.hashCode();
    final int p2Hash = P2.instance.hashCode();

    assertTrue(P1.instance.items.contains("1 " + p1Hash));
    assertTrue(P1.instance.items.contains("2 " + p1Hash));
    assertTrue(P2.instance.items.contains("1 " + p1Hash + " " + p2Hash));
    assertTrue(P2.instance.items.contains("2 " + p1Hash + " " + p2Hash));
}
 
Example #27
Source File: JSefaFlrReaderConverterTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void testRead() throws Exception {
    String path = "target/work/JSefaFlrReaderWithConverter.csv";

    IOs.write(path,
              "string1   123      1  201007161200\n" +
              "string2   345      2  199004041350\n" +
              "string3   9876543211  197905072358");

    Properties props = new Properties();
    props.setProperty("input", path);

    JobOperator operator = BatchRuntime.getJobOperator();
    Batches.waitForEnd(operator, operator.start("jsefa-flr-reader-converter", props));

    Set<RecordWithConverter> expectedItems = new HashSet<RecordWithConverter>();
    expectedItems.add(new RecordWithConverter("string1", 123L, RecordWithConverter.RecordEnum.ONE, new GregorianCalendar(2010, Calendar.JULY, 16, 12, 0).getTime()));
    expectedItems.add(new RecordWithConverter("string2", 345L, RecordWithConverter.RecordEnum.TWO, new GregorianCalendar(1990, Calendar.APRIL, 4, 13, 50).getTime()));
    expectedItems.add(new RecordWithConverter("string3", 987654321L, RecordWithConverter.RecordEnum.ONE, new GregorianCalendar(1979, Calendar.MAY, 7, 23, 58).getTime()));

    Assert.assertEquals(Storage.STORAGE.size(), expectedItems.size());
    Assert.assertTrue(Storage.STORAGE.containsAll(expectedItems));
}
 
Example #28
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 #29
Source File: GroovyProcessorTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void process() {
    IOs.write("target/work/processor.groovy", "package org.apache.batchee.groovy\n" +
        "\n" +
        "import javax.batch.api.chunk.ItemProcessor\n" +
        "\n" +
        "class GProcessor implements ItemProcessor {\n" +
        "    @Override\n" +
        "    Object processItem(final Object item) throws Exception {\n" +
        "        GroovyProcessorTest.ITEMS << item\n" +
        "        item\n" +
        "    }\n" +
        "}\n");
    final JobOperator operator = BatchRuntime.getJobOperator();
    Batches.waitForEnd(operator, operator.start("groovy-processor", new Properties()));
    assertEquals(ITEMS.size(), 2);
    assertEquals("g_1", ITEMS.get(0));
    assertEquals("g_2", ITEMS.get(1));
}
 
Example #30
Source File: JSefaXmlWriterTest.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Test
public void read() throws Exception {
    final String path = "target/work/JSefaXmlWriter.txt";

    final Properties jobParams = new Properties();
    jobParams.setProperty("output", path);

    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    Batches.waitForEnd(jobOperator, jobOperator.start("jsefa-xml-writer", jobParams));
    final String output = IOs.slurp(path);

    assertEquals(output.replace(System.getProperty("line.separator"), ""),
        "<Record>" +
        "  <value1>v1 1</value1>" +
        "  <value2>v1 2</value2>" +
        "</Record>" +
        "<Record>" +
        "  <value1>v2 1</value1>" +
        "  <value2>v2 2</value2>" +
        "</Record>");
}