@Test
  public void testRunRestartableJobInstanceTwice() throws Exception {
    job =
        new JobSupport("foo") {
          @Override
          public boolean isRestartable() {
            return true;
          }

          @Override
          public void execute(JobExecution execution) {
            execution.setExitStatus(ExitStatus.COMPLETED);
            return;
          }
        };

    testRun();
    reset(jobRepository);
    expect(jobRepository.getLastJobExecution(job.getName(), jobParameters))
        .andReturn(new JobExecution(new JobInstance(1L, jobParameters, job.getName())));
    expect(jobRepository.createJobExecution(job.getName(), jobParameters))
        .andReturn(new JobExecution(new JobInstance(1L, jobParameters, job.getName())));
    replay(jobRepository);
    jobLauncher.run(job, jobParameters);
    verify(jobRepository);
  }
  @Test
  public void testTaskExecutorRejects() throws Exception {

    final List<String> list = new ArrayList<String>();
    jobLauncher.setTaskExecutor(
        new TaskExecutor() {
          @Override
          public void execute(Runnable task) {
            list.add("execute");
            throw new TaskRejectedException("Planned failure");
          }
        });

    JobExecution jobExecution = new JobExecution(null, null);

    expect(jobRepository.getLastJobExecution(job.getName(), jobParameters)).andReturn(null);
    expect(jobRepository.createJobExecution(job.getName(), jobParameters)).andReturn(jobExecution);
    jobRepository.update(jobExecution);
    expectLastCall();
    replay(jobRepository);

    jobLauncher.afterPropertiesSet();
    try {
      jobLauncher.run(job, jobParameters);
    } finally {
      assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
      assertEquals(ExitStatus.FAILED.getExitCode(), jobExecution.getExitStatus().getExitCode());
      verify(jobRepository);
    }

    assertEquals(1, list.size());
  }
예제 #3
0
  public void run()
      throws JobExecutionAlreadyRunningException, JobRestartException,
          JobInstanceAlreadyCompleteException, JobParametersInvalidException {

    JobParameters parameters =
        new JobParametersBuilder()
            .addLong("currentTime", new Long(System.currentTimeMillis()))
            .toJobParameters();

    jobLauncher.run(job, parameters);
  }
  private void run(ExitStatus exitStatus) throws Exception {
    JobExecution jobExecution = new JobExecution(null, null);

    expect(jobRepository.getLastJobExecution(job.getName(), jobParameters)).andReturn(null);
    expect(jobRepository.createJobExecution(job.getName(), jobParameters)).andReturn(jobExecution);
    replay(jobRepository);

    jobLauncher.afterPropertiesSet();
    try {
      jobLauncher.run(job, jobParameters);
    } finally {
      assertEquals(exitStatus, jobExecution.getExitStatus());
      verify(jobRepository);
    }
  }
  @Test(expected = JobParametersInvalidException.class)
  public void testRunWithValidator() throws Exception {

    job.setJobParametersValidator(
        new DefaultJobParametersValidator(new String[] {"missing-and-required"}, new String[0]));

    expect(jobRepository.getLastJobExecution(job.getName(), jobParameters)).andReturn(null);
    replay(jobRepository);

    jobLauncher.afterPropertiesSet();
    try {
      jobLauncher.run(job, jobParameters);
    } finally {
      verify(jobRepository);
    }
  }
예제 #6
0
  @Override
  public void runner() { // job runner
    log.info("RUNNER: PymkMain");
    try {
      Job job = (Job) PymkMain.getContext().getBean("pymkJob");
      JobParameters params =
          new JobParametersBuilder().addString("task", job.getName()).toJobParameters();
      jobLauncher.run(job, params);
    } catch (Exception e) {
      e.printStackTrace();
    }

    // TaskScheduler scheduler = PymkMain.getContext().getBean("scheduler", TaskScheduler.class);
    // scheduler.schedule(new Runnable() {
    // public void run() {
    // System.out.println(new Date());
    // }
    // }, new Date());

    // PymkDbSyncMain r1 = PymkMain.getContext().getBean("pymkDbSyncMain", PymkDbSyncMain.class);
    // r1.runner();
    // AddressBookMain r2 = PymkMain.getContext().getBean("addressBookMain", AddressBookMain.class);
    // r2.runner();
  }