Package org.springframework.batch.core

Examples of org.springframework.batch.core.JobParametersBuilder


        new ClassPathXmlApplicationContext("org/springframework/batch/core/repository/dao/OptimisticLockingFailureTests-context.xml");
    Job job = applicationContext.getBean(Job.class);
    JobLauncher jobLauncher = applicationContext.getBean(JobLauncher.class);
    JobOperator jobOperator = applicationContext.getBean(JobOperator.class);

    JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder()
        .addLong("test", 1L)
        .toJobParameters());

    Thread.sleep(1000);

    jobOperator.stop(jobExecution.getId());

    while(jobExecution.isRunning()) {
      // wait for async launched job to complete execution
    }

    int numStepExecutions = jobExecution.getStepExecutions().size();
    StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next();
    String stepName = stepExecution.getStepName();
    BatchStatus stepExecutionStatus = stepExecution.getStatus();
    BatchStatus jobExecutionStatus = jobExecution.getStatus();

    assertTrue("Should only be one StepExecution but got: " + numStepExecutions, numStepExecutions == 1);
    assertTrue("Step name for execution should be step1 but got: " + stepName, "step1".equals(stepName));
    assertTrue("Step execution status should be STOPPED but got: " + stepExecutionStatus, stepExecutionStatus.equals(BatchStatus.STOPPED));
    assertTrue("Job execution status should be STOPPED but got:" + jobExecutionStatus, jobExecutionStatus.equals(BatchStatus.STOPPED));

    JobExecution restartJobExecution = jobLauncher.run(job, new JobParametersBuilder()
        .addLong("test", 1L)
        .toJobParameters());

    while(restartJobExecution.isRunning()) {
      // wait for async launched job to complete execution
View Full Code Here


    assertEquals(2, incrementer.getNext(next).getLong("run.id").intValue());
  }

  @Test
  public void testGetNextAppends() {
    JobParameters next = incrementer.getNext(new JobParametersBuilder().addString("foo", "bar").toJobParameters());
    assertEquals(1, next.getLong("run.id").intValue());
    assertEquals("bar", next.getString("foo"));
  }
View Full Code Here

public class TestJobParametersIncrementer implements JobParametersIncrementer {

  @Override
  public JobParameters getNext(JobParameters parameters) {
    return  new JobParametersBuilder().addString("foo", "spam").toJobParameters();
  }
View Full Code Here

   */
  @Transactional
  @Test
  public void testCreateAndRetrieveWithNullParameter() throws Exception {

    JobParameters jobParameters = new JobParametersBuilder().addString("foo", null).toJobParameters();

    JobInstance fooInstance = dao.createJobInstance(fooJob, jobParameters);
    assertNotNull(fooInstance.getId());
    assertEquals(fooJob, fooInstance.getJobName());

View Full Code Here

    // we need multiple instances of the same job to check ordering
    String multiInstanceJob = "multiInstanceJob";
    String paramKey = "myID";
    int instanceCount = 6;
    for (int i = 1; i <= instanceCount; i++) {
      JobParameters params = new JobParametersBuilder().addLong(paramKey, Long.valueOf(i)).toJobParameters();
      dao.createJobInstance(multiInstanceJob, params);
    }


    int startIndex = 3;
View Full Code Here

    assertEquals(date, props.getDate("schedule.date"));
  }

  public void testGetProperties() throws Exception {

    JobParameters parameters = new JobParametersBuilder().addDate("schedule.date", dateFormat.parse("01/23/2008"))
        .addString("job.key", "myKey").addString("vendor.id", "33243243").toJobParameters();

    Properties props = factory.getProperties(parameters);
    assertNotNull(props);
    assertEquals("myKey", props.getProperty("job.key"));
View Full Code Here

    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);
    assertEquals(1, jobExplorer.getJobInstanceCount(jobName));
View Full Code Here

  }

  @Test
  public void testExplicitHandlerStep() throws Exception {
    assertNotNull(job1);
    JobExecution jobExecution = jobRepository.createJobExecution(job1.getName(), new JobParametersBuilder()
        .addLong("gridSize", 1L).toJobParameters());
    job1.execute(jobExecution);
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
    Collections.sort(savedStepNames);
    assertEquals("[s1:partition0]", savedStepNames.toString());
View Full Code Here

  @Test
  public void testCreateAndFind() throws Exception {

    job.setRestartable(true);

    JobParametersBuilder builder = new JobParametersBuilder();
    builder.addString("stringKey", "stringValue").addLong("longKey", 1L).addDouble("doubleKey", 1.1).addDate(
        "dateKey", new Date(1L));
    JobParameters jobParams = builder.toJobParameters();

    JobExecution firstExecution = jobRepository.createJobExecution(job.getName(), jobParams);
    firstExecution.setStartTime(new Date());
    assertNotNull(firstExecution.getLastUpdated());
View Full Code Here

    List<Step> stepsToExecute = new ArrayList<Step>();
    stepsToExecute.add((Step) applicationContext.getBean(stepName));
    job.setSteps(stepsToExecute);

    JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder().addLong("timestamp",
        new Date().getTime()).toJobParameters());
    return jobExecution.getStepExecutions().iterator().next();
  }
View Full Code Here

TOP

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

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.