Package org.springframework.batch.core.launch

Examples of org.springframework.batch.core.launch.JobLauncher


    Class<?>[] configs = new Class<?>[config.length + 1];
    System.arraycopy(config, 0, configs, 1, config.length);
    configs[0] = DataSourceConfiguration.class;
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configs);
    Job job = jobName == null ? context.getBean(Job.class) : context.getBean(JobLocator.class).getJob(jobName);
    JobLauncher jobLauncher = context.getBean(JobLauncher.class);
    execution = jobLauncher
        .run(job, new JobParametersBuilder().addLong("run.id", (long) (Math.random() * Long.MAX_VALUE))
            .toJobParameters());
    assertEquals(status, execution.getStatus());
    assertEquals(stepExecutionCount, execution.getStepExecutions().size());
    JobExplorer jobExplorer = context.getBean(JobExplorer.class);
View Full Code Here


  private TriggerFiredBundle firedBundle;
  private List<Serializable> list = new ArrayList<Serializable>();
 
  @Before
  public void setUp() throws Exception {
    details.setJobLauncher(new JobLauncher() {
      @Override
      public JobExecution run(org.springframework.batch.core.Job job, JobParameters jobParameters)
          throws JobExecutionAlreadyRunningException, JobRestartException {
        list.add(jobParameters);
        return null;
View Full Code Here

    Class<?>[] configs = new Class<?>[config.length + 1];
    System.arraycopy(config, 0, configs, 1, config.length);
    configs[0] = DataSourceConfiguration.class;
    AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(configs);
    Job job = jobName == null ? context.getBean(Job.class) : context.getBean(jobName, Job.class);
    JobLauncher jobLauncher = context.getBean(JobLauncher.class);
    execution = jobLauncher
        .run(job, new JobParametersBuilder().addLong("run.id", (long) (Math.random() * Long.MAX_VALUE))
            .toJobParameters());
    assertEquals(status, execution.getStatus());
    assertEquals(stepExecutionCount, execution.getStepExecutions().size());
    context.close();
View Full Code Here

  @Test
  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

  @Test
  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

  @Test
  @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

  @Test
  @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

  @Test
  @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

  @SuppressWarnings("resource"
  @Test
  public void testMultithreadedSplit() throws Throwable {

    JobLauncher jobLauncher = null;
    Job job = null;
   
    ClassPathXmlApplicationContext context = null;

    for (int i = 0; i < MAX_COUNT; i++) {

      if (i % 100 == 0) {
        if (context!=null) {
          context.close();
        }
        logger.info("Starting job: " + i);
        context = new ClassPathXmlApplicationContext(getClass().getSimpleName()
            + "-context.xml", getClass());
        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

  public void testWorkflowNS() throws Exception {
    startJobs(ctx);
  }
 
  public void startJobs(ApplicationContext ctx) {
    JobLauncher launcher = ctx.getBean(JobLauncher.class);
    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

Related Classes of org.springframework.batch.core.launch.JobLauncher

Copyright © 2018 www.massapicom. 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.