Package org.springframework.batch.core

Examples of org.springframework.batch.core.JobExecution


    this.jdbcTemplate = new JdbcTemplate(dataSource);
  }

  @Before
  public void onSetUpBeforeTransaction() throws Exception {
    StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(12L,
        "testJob"), new JobParameters()));
    writer.beforeStep(stepExecution);
  }
View Full Code Here


  public void testLaunchJob() throws Exception {

    final JobParameters jobParameters = new JobParametersBuilder().addLong("timestamp", System.currentTimeMillis())
        .toJobParameters();

    JobExecution jobExecution = jobLauncherTestUtils.launchJob(jobParameters);

    Thread.sleep(1000);

    assertEquals(BatchStatus.STARTED, jobExecution.getStatus());
    assertTrue(jobExecution.isRunning());

    jobExecution.stop();

    int count = 0;
    while (jobExecution.isRunning() && count <= 10) {
      logger.info("Checking for end time in JobExecution: count=" + count);
      Thread.sleep(100);
      count++;
    }

    assertFalse("Timed out waiting for job to end.", jobExecution.isRunning());
    assertEquals(BatchStatus.STOPPED, jobExecution.getStatus());

  }
View Full Code Here

    this.jdbcTemplate = new JdbcTemplate(dataSource);
  }

  @BeforeTransaction
  public void onSetUpBeforeTransaction() throws Exception {
    StepExecution stepExecution = new StepExecution("stepName", new JobExecution(new JobInstance(jobId,
        "testJob"), new JobParameters()));
    writer.beforeStep(stepExecution);
    writer.write(Arrays.asList("FOO", "BAR", "SPAM", "BUCKET"));
    reader.beforeStep(stepExecution);
  }
View Full Code Here

  public List<JobExecution> createJobExecutions(String jobName, String[] stepNames, int count)
      throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException {
    List<JobExecution> list = new ArrayList<JobExecution>();
    JobParameters jobParameters = new JobParameters();
    for (int i = 0; i < count; i++) {
      JobExecution jobExecution = jobRepository.createJobExecution(jobName, jobParametersIncrementer
          .getNext(jobParameters));
      list.add(jobExecution);
      for (String stepName : stepNames) {
        jobRepository.add(jobExecution.createStepExecution(stepName));
      }
    }
    return list;
  }
View Full Code Here

  @Test
  public void integrationTest() throws JobExecutionAlreadyRunningException, JobRestartException, JobInstanceAlreadyCompleteException, JobParametersInvalidException {
   
    // Run the batch job
    JobParameters jobParameters = new JobParametersBuilder().addDate("startTime", new Date()).toJobParameters();
    JobExecution jobEx = jobLauncher.run(simpleJob, jobParameters);
   
    // Validate we have created 20 new records with the new predicate
    // this uses the basic functionality in SnarlTemplate
    List<String> results = snarlTemplate.doWithGetter(null, "urn:test:propertyUpdate", new GetterCallback<String>() {
      @Override
View Full Code Here

    }

    @Override
    public void process(Exchange exchange) throws Exception {
        JobParameters jobParameters = prepareJobParameters(exchange.getIn().getHeaders());
        JobExecution jobExecution = jobLauncher.run(job, jobParameters);
        exchange.getOut().setBody(jobExecution);
    }
View Full Code Here

  @Override
  public long deleteData() {
    try {
      long jobInstanceCount = jobExplorer.getJobInstanceCount(deleteAllDataJob.getName());
      final JobParameters jobParameters = new JobParametersBuilder().addLong(RUN_ID, ++jobInstanceCount).toJobParameters();
      final JobExecution run = jobLauncher.run(deleteAllDataJob, jobParameters);
      assertExitStatus(run.getExitStatus());
      return runtime(run);
    } catch (final Exception e) {
      throw new IllegalStateException(e);
    }
  }
View Full Code Here

  private long importData(final long amountOfData) {
    try {
      long jobInstanceCount = jobExplorer.getJobInstanceCount(importDataJob.getName());
      final JobParameters jobParameters = new JobParametersBuilder().addLong(RUN_ID, ++jobInstanceCount).addLong(NUMBER_OF_DATA, amountOfData)
          .toJobParameters();
      final JobExecution run = jobLauncher.run(importDataJob, jobParameters);
      assertExitStatus(run.getExitStatus());
      return runtime(run);
    } catch (final Exception e) {
      throw new IllegalStateException(e);
    }
  }
View Full Code Here

  @Autowired
  private Job importDataJob;

  @Test
  public void testLaunchJob() throws Exception {
    final JobExecution run = jobLauncher.run(importDataJob, new JobParameters());
    assertTrue("Job not completed: " + run.getExitStatus(), run.getExitStatus().equals(ExitStatus.COMPLETED));

    final JdbcTemplate template = new JdbcTemplate(dataSource);
    assertThat(template.queryForObject("select count(id) from apprentice", Integer.class), is(5));
    assertThat(template.queryForObject("select count(id) from company", Integer.class), is(3));
    assertThat(template.queryForObject("select count(id) from contract", Integer.class), is(5));
View Full Code Here

      long result = Long.MIN_VALUE;
      JobParameter clusterNameParameter =
            param.getParameters().get(JobConstants.CLUSTER_NAME_JOB_PARAM);
      String clusterName = (String) clusterNameParameter.getValue();
      Job preparingJob = jobRegistry.getJob(jobName);
      JobExecution preparingJobExecution = jobLauncher.run(preparingJob, param);
      int subJobNumber = 0;
      waitJobExecution(preparingJobExecution.getId(), Long.MAX_VALUE);
      if (preparingJobExecution.getStatus() == BatchStatus.COMPLETED) {
         subJobNumber =
               preparingJobExecution.getExecutionContext().getInt(
                     (JobConstants.SUB_JOB_NUMBER));
         if (subJobNumber > 0) {
            logger.debug("sub job number: " + subJobNumber);
            List<JobParameters> subJobParametersList =
                  new ArrayList<JobParameters>();
            for (int i = 0; i < subJobNumber; i++) {
               JobParameters subJobParameters =
                     (JobParameters) preparingJobExecution
                           .getExecutionContext()
                           .get(JobConstants.SUB_JOB_PARAMETERS_KEY_PREFIX + i);
               subJobParametersList.add(subJobParameters);
            }
            result =
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.JobExecution

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.