예제 #1
0
  private void testReadWrite0(
      final String writeResource,
      final String start,
      final String end,
      final Class<?> beanType,
      final String expect,
      final String forbid)
      throws Exception {
    final Properties params =
        CsvItemReaderWriterTest.createParams(CsvProperties.BEAN_TYPE_KEY, beanType.getName());
    final File writeResourceFile = new File(CsvItemReaderWriterTest.tmpdir, writeResource);
    params.setProperty("writeResource", writeResourceFile.getPath());
    params.setProperty(CsvProperties.CELL_PROCESSORS_KEY, cellProcessors);

    if (start != null) {
      params.setProperty(CsvProperties.START_KEY, start);
    }
    if (end != null) {
      params.setProperty(CsvProperties.END_KEY, end);
    }
    if (this.partialNameMapping != null) {
      params.setProperty(CsvProperties.NAME_MAPPING_KEY, partialNameMapping);
    }
    params.setProperty(CsvProperties.HEADER_KEY, header);
    CsvItemReaderWriterTest.setRandomWriteMode(params);

    final long jobExecutionId = jobOperator.start(jobName, params);
    final JobExecutionImpl jobExecution =
        (JobExecutionImpl) jobOperator.getJobExecution(jobExecutionId);
    jobExecution.awaitTermination(CsvItemReaderWriterTest.waitTimeoutMinutes, TimeUnit.MINUTES);
    Assert.assertEquals(BatchStatus.COMPLETED, jobExecution.getBatchStatus());

    CsvItemReaderWriterTest.validate(writeResourceFile, expect, forbid);
  }
예제 #2
0
  private static void executeJob(String jobId) {
    long execID = 0;
    // ジョブの開始時はXML読み込みなど同時実行されるとおかしくなる処理があるので、ジョブID単位で同期化しておく。
    JobOperator jobOperator = BatchRuntime.getJobOperator();
    synchronized (jobId) {
      Properties props = new Properties();
      props.setProperty(
          "date", LocalDateTime.now().format(DateTimeFormatter.ofPattern("yyyy-MM-dd")));
      execID = jobOperator.start(jobId, props);
      System.out.println("job stated id:" + execID);
    }
    JobExecution jobExec = null;
    // ジョブが終了するまでポーリング
    while (true) {
      jobExec = jobOperator.getJobExecution(execID);

      if (jobExec.getEndTime() != null) {
        break;
      }

      try {
        Thread.sleep(1000L);
      } catch (InterruptedException ex) {
      }
    }
    System.out.println("JOB END:Status is " + jobExec.getExitStatus());
  }
예제 #3
0
  /**
   * Waits for job to finish. JSR 352 does not provide a mechanism to launch jobs in the synchronous
   * mode. As a result, the polling needs to occur
   *
   * @param jobOperator
   * @param executionId
   * @param pollingWait
   * @param maxTries
   * @return
   */
  public static JobExecution waitForJobToEnd(
      JobOperator jobOperator, final long executionId, final long pollingWait, final int maxTries) {

    int countTries = 0;
    JobExecution jobExecution = null;
    do {
      try {
        countTries++;
        Thread.sleep(pollingWait);
      } catch (InterruptedException e) {
        throw new RuntimeException(e);
      }
      jobExecution = jobOperator.getJobExecution(executionId);
    } while (INCOMPLETE_STATUSES.contains(jobExecution.getBatchStatus())
        || (countTries < maxTries));

    return jobExecution;
  }