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

The following examples show how to use javax.batch.operations.JobOperator#start() . 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: 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 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: 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 4
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 5
Source File: StartMojo.java    From incubator-batchee with Apache License 2.0 6 votes vote down vote up
@Override
public void execute() throws MojoExecutionException {
    final JobOperator jobOperator = getOrCreateOperator();

    final ClassLoader oldLoader = Thread.currentThread().getContextClassLoader();
    final ClassLoader loader = createStartLoader(oldLoader);
    Thread.currentThread().setContextClassLoader(loader);

    final long id;
    try {
        id = jobOperator.start(jobName, toProperties(jobParameters));
    } finally {
        Thread.currentThread().setContextClassLoader(oldLoader);
    }

    getLog().info("Started job " + jobName + ", id is #" + id);

    if (wait) {
        waitEnd(jobOperator, id);
    }
}
 
Example 6
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 7
Source File: MainTest.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
@Test
public void running() {
    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    final long id = jobOperator.start("long-sample", null);

    try {
        sleep(100); // ensure it is started
    } catch (final InterruptedException e) {
        Thread.interrupted();
    }
    main(new String[]{"running"});
    assertThat(stdout.getLog(), containsString("long-sample -> ["));

    Batches.waitForEnd(jobOperator, id);
}
 
Example 8
Source File: SimpleBatchLetUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenBatchLetProperty_thenBatch_CompleteWithSuccess() throws Exception {
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    Long executionId = jobOperator.start("injectionSimpleBatchLet", new Properties());
    JobExecution jobExecution = jobOperator.getJobExecution(executionId);
    jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
    assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
 
Example 9
Source File: SimpleBatchLetUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenBatchLet_thenBatch_CompleteWithSuccess() throws Exception {
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    Long executionId = jobOperator.start("simpleBatchLet", new Properties());
    JobExecution jobExecution = jobOperator.getJobExecution(executionId);
    jobExecution = BatchTestHelper.keepTestAlive(jobExecution);
    assertEquals(jobExecution.getBatchStatus(), BatchStatus.COMPLETED);
}
 
Example 10
Source File: SimpleBatchLetUnitTest.java    From tutorials with MIT License 5 votes vote down vote up
@Test
public void givenBatchLetStarted_whenStopped_thenBatchStopped() throws Exception {
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    Long executionId = jobOperator.start("simpleBatchLet", new Properties());
    JobExecution jobExecution = jobOperator.getJobExecution(executionId);
    jobOperator.stop(executionId);
    jobExecution = BatchTestHelper.keepTestStopped(jobExecution);
    assertEquals(jobExecution.getBatchStatus(), BatchStatus.STOPPED);
}
 
Example 11
Source File: JobTest.java    From wow-auctions with GNU General Public License v3.0 5 votes vote down vote up
@Test
@InSequence(2)
public void testFilesJob() throws Exception {
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    Long executionId = jobOperator.start("files-job", new Properties());

    JobExecution jobExecution = keepTestAlive(jobOperator, executionId);

    assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());
}
 
Example 12
Source File: BatchExecutionServlet.java    From wow-auctions with GNU General Public License v3.0 5 votes vote down vote up
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
    String batch = req.getParameter("batch");

    JobOperator jobOperator = BatchRuntime.getJobOperator();

    switch (batch) {
        case "prepare":
            jobOperator.start("prepare-job", new Properties());
            break;
        case "files":
            jobOperator.start("files-job", new Properties());
            break;
        case "process":
            Realm realm = woWBusiness.findRealmByNameOrSlug("grim-batol", Realm.Region.EU).get();
            List<AuctionFile> auctionFilesByRealmToProcess =
                    woWBusiness.findAuctionFilesByRealmToProcess(realm.getId());
            System.out.println("Grim Batol files  " + auctionFilesByRealmToProcess.size());
            auctionFilesByRealmToProcess.stream().limit(1).forEach(this::processJob);

            if (auctionFilesByRealmToProcess.isEmpty()) {
                realm = woWBusiness.findRealmByNameOrSlug("aggra-portugues", Realm.Region.EU).get();
                auctionFilesByRealmToProcess = woWBusiness.findAuctionFilesByRealmToProcess(realm.getId());
                System.out.println("Aggra files  " + auctionFilesByRealmToProcess.size());
                auctionFilesByRealmToProcess.stream().limit(1).forEach(this::processJob);
            }

            break;
        default:
            throw new UnsupportedOperationException();
    }

    resp.sendRedirect("batchs.html");
}
 
Example 13
Source File: BatchArquillianTest.java    From ARCHIVE-wildfly-swarm with Apache License 2.0 5 votes vote down vote up
@Test
public void testChunk() {
    final JobOperator jobOperator = BatchRuntime.getJobOperator();
    final Properties jobProperties = new Properties();
    jobProperties.setProperty("chunk.start", "0");
    jobProperties.setProperty("chunk.end", "10");

    final long id = jobOperator.start("simple", jobProperties);

    // Wait for the job to complete
    waitForCompletion(id, 5, TimeUnit.SECONDS);
}
 
Example 14
Source File: CreateSomeJobs.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
@Override
public void contextInitialized(final ServletContextEvent sce) {
    final JobOperator operator = BatchRuntime.getJobOperator();

    try { // initialize only once to ensure we can use in tests ids
        operator.getJobInstances("init", 0, 10);
    } catch (final NoSuchJobException nsje) {
        final Properties jobParameters = new Properties();
        jobParameters.setProperty("test", "jbatch");
        final long id = operator.start("init", jobParameters);
        Batches.waitForEnd(operator, id);
    }
}
 
Example 15
Source File: InjectionsTest.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
@Test
public void run() {
    final JobOperator operator = BatchRuntime.getJobOperator();
    final long id = operator.start("injections", null);
    waitForEnd(operator, id);
    assertEquals(operator.getStepExecutions(id).iterator().next().getExitStatus(), "true");
}
 
Example 16
Source File: PartitionIdTest.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
@Test
public void run() {
    final JobOperator op = BatchRuntime.getJobOperator();
    final long id = op.start("partition-execId", null);
    Batches.waitForEnd(op, id);

    final long stepId = op.getStepExecutions(id).iterator().next().getStepExecutionId();

    assertEquals(2, Reader.jobIds.size());
    assertEquals(2, Reader.stepIds.size());
    assertEquals(id, Reader.jobIds.get(1).longValue());
    assertEquals(Reader.jobIds.get(0), Reader.jobIds.get(1));
    assertEquals(stepId, Reader.stepIds.get(0).longValue());
    assertEquals(Reader.stepIds.get(0), Reader.stepIds.get(1));
}
 
Example 17
Source File: CreateSomeJobs.java    From incubator-batchee with Apache License 2.0 5 votes vote down vote up
@Override
public void contextInitialized(final ServletContextEvent sce) {
    final JobOperator operator = BatchRuntime.getJobOperator();

    try { // initialize only once to ensure we can use in tests ids
        operator.getJobInstances("init", 0, 10);
    } catch (final NoSuchJobException nsje) {
        final Properties jobParameters = new Properties();
        jobParameters.setProperty("test", "jbatch");
        final long id = operator.start("init", jobParameters);
        Batches.waitForEnd(operator, id);
    }
}
 
Example 18
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 19
Source File: UploadDirectoryScanner.java    From pragmatic-microservices-lab with MIT License 4 votes vote down vote up
@Schedule(minute = "*/2", hour = "*") // Runs every fifteen minutes
public void processFiles() {
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    jobOperator.start("EventFilesProcessorJob", null);
}
 
Example 20
Source File: UploadDirectoryScanner.java    From pragmatic-microservices-lab with MIT License 4 votes vote down vote up
@Schedule(minute = "*/2", hour = "*") // Runs every fifteen minutes
public void processFiles() {
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    jobOperator.start("EventFilesProcessorJob", null);
}