Package org.springframework.batch.core.job

Examples of org.springframework.batch.core.job.SimpleJob


  public Job build() {
    if (builder != null) {
      return builder.end().build();
    }
    SimpleJob job = new SimpleJob(getName());
    super.enhance(job);
    job.setSteps(steps);
    try {
      job.afterPropertiesSet();
    }
    catch (Exception e) {
      throw new JobBuilderException(e);
    }
    return job;
View Full Code Here


  public void testFoo() throws Exception {
    Step testStep1 = buildTestStep("foo");
    Step testStep2 = buildTestStep("bar");
    Step testStep3 = buildTestStep("baz");

    SimpleJob simpleJob = new SimpleJob();   // is a StepLocator
    simpleJob.addStep(testStep1);
    simpleJob.addStep(testStep2);
    simpleJob.addStep(testStep3);

    StepLocatorStepFactoryBean stepLocatorStepFactoryBean = new StepLocatorStepFactoryBean();
    stepLocatorStepFactoryBean.setStepLocator(simpleJob);
    stepLocatorStepFactoryBean.setStepName("bar");
    assertEquals(testStep2, stepLocatorStepFactoryBean.getObject());
View Full Code Here

    assertEquals(BatchStatus.COMPLETED, stepExecution.getStatus());
    assertEquals("[1, 1, 1, 1]", tasklet.getCommitted().toString());
  }

  private StepExecution launchStep(String stepName) throws Exception {
    SimpleJob job = new SimpleJob();
    job.setName("job");
    job.setJobRepository(jobRepository);

    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

      throw new NoSuchJobException(name);
    }
    // Return a simple job that currently supports
    // - Get job name
    // - Get step names of the given job
    SimpleJob job = new SimpleJob(name) {

      @Override
      public Collection<String> getStepNames() {
        return getJobStepNames(name);
      }
View Full Code Here

  private JobExecution execution;

  @Before
  public void before() throws Exception {
    SimpleJob job1 = new SimpleJob("job1");
    SimpleJob job2 = new SimpleJob("job2");
    Collection<String> jobNames = new ArrayList<String>();
    jobNames.add(job1.getName());
    jobNames.add(job2.getName());
    Collection<JobInstance> jobInstances = new ArrayList<JobInstance>();
    JobInstance jobInstance1 = new JobInstance(0l, job1.getName());
    JobInstance jobInstance2 = new JobInstance(2l, job2.getName());
    JobInstance jobInstance3 = new JobInstance(3l, job1.getName());
    jobInstances.add(jobInstance1);
    jobInstances.add(jobInstance3);

    Map<String, JobParameter> parametersMap1 = new HashMap<String, JobParameter>();
    parametersMap1.put("param1", new JobParameter("test", true));
    parametersMap1.put("param2", new JobParameter(123l, false));
    JobParameters jobParameters1 = new JobParameters(parametersMap1);
    JobParameters jobParameters2 = new JobParameters(parametersMap1);
    JobExecution jobExecution1 = new JobExecution(jobInstance1, 0l, jobParameters1, null);
    JobExecution jobExecution2 = new JobExecution(jobInstance2, 3l, jobParameters2, null);

    // Verify XD-999
    StepExecution stepExecution = new StepExecution("s1", jobExecution2);
    List<StepExecution> stepExecutions = new ArrayList<StepExecution>();
    stepExecutions.add(stepExecution);
    jobExecution2.addStepExecutions(stepExecutions);

    Collection<JobExecution> jobExecutions1 = new ArrayList<JobExecution>();
    Collection<JobExecution> jobExecutions2 = new ArrayList<JobExecution>();
    jobExecutions1.add(jobExecution1);
    jobExecutions1.add(jobExecution2);
    jobExecutions2.add(jobExecution2);

    when(jobLocator.getJobNames()).thenReturn(jobNames);
    when(jobService.countJobExecutionsForJob(job1.getName())).thenReturn(2);
    when(jobService.countJobExecutionsForJob(job2.getName())).thenReturn(1);

    when(jobService.isLaunchable(job1.getName())).thenReturn(false);
    when(jobService.isLaunchable(job2.getName())).thenReturn(true);

    when(jobService.isIncrementable(job1.getName())).thenReturn(false);
    when(jobService.isIncrementable(job2.getName())).thenReturn(true);

    when(jobService.listJobInstances(job1.getName(), 0, 20)).thenReturn(jobInstances);

    Date startTime = new Date();
    Date endTime = new Date();
View Full Code Here

    moduleDefinitions.add(moduleJobDefinition);
    when(moduleRegistry.findDefinitions("job")).thenReturn(moduleDefinitions);
    when(moduleRegistry.findDefinition("job", ModuleType.job)).thenReturn(moduleJobDefinition);
    when(jobLocator.getJobNames()).thenReturn(Arrays.asList(new String[] {}));

    SimpleJob job1 = new SimpleJob("job1");
    SimpleJob job2 = new SimpleJob("job2");
    Collection<String> jobNames = new ArrayList<String>();
    jobNames.add(job1.getName());
    jobNames.add(job2.getName());
    Collection<JobInstance> jobInstances = new ArrayList<JobInstance>();
    JobInstance jobInstance1 = new JobInstance(0l, job1.getName());
    JobInstance jobInstance2 = new JobInstance(2l, job2.getName());
    JobInstance jobInstance3 = new JobInstance(3l, job1.getName());
    jobInstances.add(jobInstance1);
    jobInstances.add(jobInstance3);

    Map<String, JobParameter> parametersMap1 = new HashMap<String, JobParameter>();
    parametersMap1.put("param1", new JobParameter("test", true));
    parametersMap1.put("param2", new JobParameter(123l, false));
    JobParameters jobParameters1 = new JobParameters(parametersMap1);
    JobParameters jobParameters2 = new JobParameters(parametersMap1);
    JobExecution jobExecution1 = new JobExecution(jobInstance1, 0l, jobParameters1, null);
    JobExecution jobExecution2 = new JobExecution(jobInstance2, 3l, jobParameters2, null);

    // Verify XD-999
    StepExecution stepExecution = new StepExecution("s1", jobExecution2);
    List<StepExecution> stepExecutions = new ArrayList<StepExecution>();
    stepExecutions.add(stepExecution);
    jobExecution2.addStepExecutions(stepExecutions);

    Collection<JobExecution> jobExecutions1 = new ArrayList<JobExecution>();
    Collection<JobExecution> jobExecutions2 = new ArrayList<JobExecution>();
    jobExecutions1.add(jobExecution1);
    jobExecutions1.add(jobExecution2);
    jobExecutions2.add(jobExecution2);
    when(jobService.countJobExecutionsForJob(job1.getName())).thenReturn(2);
    when(jobService.countJobExecutionsForJob(job2.getName())).thenReturn(1);

    when(jobService.isLaunchable(job1.getName())).thenReturn(false);
    when(jobService.isLaunchable(job2.getName())).thenReturn(true);

    when(jobService.isIncrementable(job1.getName())).thenReturn(false);
    when(jobService.isIncrementable(job2.getName())).thenReturn(true);

    when(jobService.listJobInstances(job1.getName(), 0, 20)).thenReturn(jobInstances);

    Date startTime = new Date();
    Date endTime = new Date();
    Collection<JobExecution> jobExecutions = new ArrayList<JobExecution>();
    execution = new JobExecution(0L,
        new JobParametersBuilder().addString("foo", "bar").addLong("foo2", 0L).toJobParameters());
    execution.setExitStatus(ExitStatus.COMPLETED);
    execution.setStartTime(startTime);
    execution.setEndTime(endTime);
    jobExecutions.add(execution);

    when(jobService.listJobExecutionsForJob("job1", 0, 1)).thenReturn(jobExecutions);
    when(jobService.listJobExecutions(0, 20)).thenReturn(jobExecutions1);
    when(jobService.listJobExecutionsForJob(job2.getName(), 0, 20)).thenReturn(jobExecutions2);

  }
View Full Code Here

  @BeforeClass
  public static void setup() {
    // use a different job repo database for this test
    System.setProperty("hsql.server.database", "jobrepotest");
    job = new SimpleJob(SIMPLE_JOB_NAME) {

      @Override
      public Collection<String> getStepNames() {
        return Arrays.asList(("step1,step2").split(","));
      }
View Full Code Here

    assertEquals("The number of step names returned from hsqldb did not match.", 2, count);
  }

  @Test
  public void checkThatContainerHasRepo() throws Exception {
    Job job = new SimpleJob(SIMPLE_JOB_NAME);
    try {
      launcher.run(job, new JobParameters());
    }
    catch (Exception ex) {
      // we can ignore this. Just want to create a fake job instance.
View Full Code Here

  private DistributedJobLocator jobLocator;

  @Before
  public void before() throws Exception {

    final SimpleJob job1 = new SimpleJob("job1.job");

    final JobInstance jobInstance1 = new JobInstance(0L, job1.getName());
    final Map<String, JobParameter> parametersMap1 = new HashMap<String, JobParameter>();
    parametersMap1.put("param1", new JobParameter("test", true));
    parametersMap1.put("param2", new JobParameter(123L, false));
    final JobParameters jobParameters1 = new JobParameters(parametersMap1);
    final JobExecution jobExecution1 = new JobExecution(jobInstance1, 2L, jobParameters1, null);

    final StepExecution step1 = new StepExecution("step1", jobExecution1, 1L);
    final StepExecution step2 = new StepExecution("step2", jobExecution1, 2L);
    final StepExecution step3 = new StepExecution("step3", jobExecution1, 3L);

    step1.getExecutionContext().put("contextTestKey", "howdy!");

    final List<StepExecution> stepExecutions1 = new ArrayList<StepExecution>();
    stepExecutions1.add(step1);
    stepExecutions1.add(step2);
    stepExecutions1.add(step3);

    final List<StepExecution> stepExecutions2 = new ArrayList<StepExecution>();
    stepExecutions2.add(step2);
    jobExecution1.addStepExecutions(stepExecutions1);

    when(jobService.getStepExecutions(5555L)).thenThrow(
        new NoSuchJobExecutionException("No JobExecution with id=5555L"));
    when(jobService.getStepExecutions(2L)).thenReturn(stepExecutions1);

    when(jobService.getStepExecution(2L, 1L)).thenReturn(step1);
    when(jobService.getStepExecution(5555L, 1L)).thenThrow(
        new NoSuchJobExecutionException("No JobExecution with id=5555L"));
    when(jobService.getStepExecution(2L, 5555L)).thenThrow(
        new NoSuchStepExecutionException("No StepExecution with id=5555L"));
    when(jobService.countStepExecutionsForStep(job1.getName(), step1.getStepName())).thenReturn(1);
    when(jobService.listStepExecutionsForStep(job1.getName(), step1.getStepName(), 0, 1000)).thenReturn(
        stepExecutions2);

  }
View Full Code Here

    ModuleDefinition moduleJobDefinition = ModuleDefinitions.dummy("job", ModuleType.job);
    ArrayList<ModuleDefinition> moduleDefinitions = new ArrayList<ModuleDefinition>();
    moduleDefinitions.add(moduleJobDefinition);
    when(moduleRegistry.findDefinitions("job")).thenReturn(moduleDefinitions);
    when(moduleRegistry.findDefinition("job", ModuleType.job)).thenReturn(moduleJobDefinition);
    SimpleJob job1 = new SimpleJob("job1");
    SimpleJob job2 = new SimpleJob("job2");
    job2.setRestartable(false);

    SimpleJob job3 = new SimpleJob("job3complete");
    SimpleJob job4 = new SimpleJob("job4running");
    SimpleJob job5 = new SimpleJob("job5with-null-parameters");
    Collection<String> jobNames = new ArrayList<String>();
    jobNames.add(job1.getName());
    jobNames.add(job2.getName());
    jobNames.add(job3.getName());
    jobNames.add(job4.getName());
    jobNames.add(job5.getName());
    JobInstance jobInstance1 = new JobInstance(0l, job1.getName());
    JobInstance jobInstance2 = new JobInstance(2l, job2.getName());
    JobInstance jobInstance3 = new JobInstance(3l, job3.getName());
    JobInstance jobInstance4 = new JobInstance(4l, job4.getName());
    JobInstance jobInstance5 = new JobInstance(5l, job5.getName());
    Map<String, JobParameter> parametersMap1 = new HashMap<String, JobParameter>();
    parametersMap1.put("param1", new JobParameter("test", true));
    parametersMap1.put("param2", new JobParameter(123l, false));

    DefaultJobParametersValidator jobParametersValidator = new DefaultJobParametersValidator();
    String[] requiredStrings = new String[] {"myRequiredString"};
    jobParametersValidator.setRequiredKeys(requiredStrings);
    job5.setJobParametersValidator(jobParametersValidator);

    Map<String, JobParameter> parametersMap5 = new HashMap<String, JobParameter>();
    parametersMap5.put("somthingElse", new JobParameter("test", true));

View Full Code Here

TOP

Related Classes of org.springframework.batch.core.job.SimpleJob

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.