Package org.springframework.batch.core.launch

Examples of org.springframework.batch.core.launch.JobLauncher.run()


  public void testCommitIntervalJobParameter() throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml");
    Job job = context.getBean(Job.class);
    JobLauncher launcher = context.getBean(JobLauncher.class);

    JobExecution execution = launcher.run(job, new JobParametersBuilder().addLong("commit.interval", 1l).toJobParameters());

    assertEquals(BatchStatus.COMPLETED, execution.getStatus());
    assertEquals(2, execution.getStepExecutions().iterator().next().getReadCount());
    assertEquals(2, execution.getStepExecutions().iterator().next().getWriteCount());
  }
View Full Code Here


  public void testInvalidCommitIntervalJobParameter() throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("/org/springframework/batch/core/scope/context/CommitIntervalJobParameter-context.xml");
    Job job = context.getBean(Job.class);
    JobLauncher launcher = context.getBean(JobLauncher.class);

    JobExecution execution = launcher.run(job, new JobParametersBuilder().addLong("commit.intervall", 1l).toJobParameters());

    assertEquals(BatchStatus.FAILED, execution.getStatus());
  }
}
View Full Code Here

  @SuppressWarnings("resource")
  public void testReadRetryExhausted() throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/batch/core/jsr/configuration/xml/RetryReadListenerExhausted.xml");

    JobLauncher jobLauncher = context.getBean(JobLauncher.class);
    JobExecution jobExecution = jobLauncher.run(context.getBean(Job.class), new JobParameters());

    List<Throwable> failureExceptions = jobExecution.getAllFailureExceptions();
    assertTrue("Expected 1 failure exceptions", failureExceptions.size() == 1);
    assertTrue("Failure exception must be of type RetryException", (failureExceptions.get(0) instanceof RetryException));
    assertTrue("Exception cause must be of type IllegalArgumentException", (failureExceptions.get(0).getCause() instanceof IllegalArgumentException));
View Full Code Here

  @SuppressWarnings("resource")
  public void testReadRetryOnce() throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/batch/core/jsr/configuration/xml/RetryReadListenerRetryOnce.xml");

    JobLauncher jobLauncher = context.getBean(JobLauncher.class);
    JobExecution jobExecution = jobLauncher.run(context.getBean(Job.class), new JobParameters());

    Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions();
    assertEquals(1, stepExecutions.size());

    StepExecution stepExecution = stepExecutions.iterator().next();
View Full Code Here

  @SuppressWarnings("resource")
  public void testReadRetryExceptionInListener() throws Exception {
    ApplicationContext context = new ClassPathXmlApplicationContext("org/springframework/batch/core/jsr/configuration/xml/RetryReadListenerListenerException.xml");

    JobLauncher jobLauncher = context.getBean(JobLauncher.class);
    JobExecution jobExecution = jobLauncher.run(context.getBean(Job.class), new JobParameters());

    List<Throwable> failureExceptions = jobExecution.getAllFailureExceptions();
    assertTrue("Failure exceptions must equal one", failureExceptions.size() == 1);
    assertTrue("Failure exception must be of type RetryException", (failureExceptions.get(0) instanceof RetryException));
    assertTrue("Exception cause must be of type BatchRuntimeException", (failureExceptions.get(0).getCause() instanceof BatchRuntimeException));
View Full Code Here

        jobLauncher = context.getBean("jobLauncher", JobLauncher.class);
        job = context.getBean("job", Job.class);
      }

      try {
        JobExecution execution = jobLauncher.run(job, new JobParametersBuilder().addLong("count", new Long(i))
            .toJobParameters());
        assertEquals(BatchStatus.COMPLETED, execution.getStatus());
      }
      catch (Throwable e) {
        logger.info("Failed on iteration " + i + " of " + MAX_COUNT);
View Full Code Here

    Map<String, Job> jobs = ctx.getBeansOfType(Job.class);

    for (Map.Entry<String, Job> entry : jobs.entrySet()) {
      System.out.println("Executing job " + entry.getKey());
      try {
        if (launcher.run(entry.getValue(), new JobParameters()).getStatus().equals(BatchStatus.FAILED)){
          throw new BeanInitializationException("Failed executing job " + entry.getKey());
        }
      } catch (Exception ex) {
        throw new BeanInitializationException("Cannot execute job " + entry.getKey(), ex);
      }
View Full Code Here

TOP
Copyright © 2018 www.massapi.com. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.