Example usage for org.springframework.batch.core.test.repository JobSupport JobSupport

List of usage examples for org.springframework.batch.core.test.repository JobSupport JobSupport

Introduction

In this page you can find the example usage for org.springframework.batch.core.test.repository JobSupport JobSupport.

Prototype

public JobSupport(String name) 

Source Link

Document

Convenience constructor to immediately add name (which is mandatory but not final).

Usage

From source file:org.springframework.batch.core.test.repository.JdbcJobRepositoryTests.java

@Before
public void onSetUpInTransaction() throws Exception {
    job = new JobSupport("test-job");
    job.setRestartable(true);
}

From source file:org.springframework.batch.core.test.repository.JdbcJobRepositoryTests.java

@Test
public void testFindOrCreateJobConcurrentlyWhenJobAlreadyExists() throws Exception {

    job = new JobSupport("test-job");
    job.setRestartable(true);//  ww  w  .  java 2 s  .com
    job.setName("spam");

    JobExecution execution = repository.createJobExecution(job.getName(), new JobParameters());
    cacheJobIds(execution);
    execution.setEndTime(new Timestamp(System.currentTimeMillis()));
    repository.update(execution);
    execution.setStatus(BatchStatus.FAILED);

    int before = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE", Integer.class);
    assertEquals(1, before);

    long t0 = System.currentTimeMillis();
    try {
        doConcurrentStart();
        fail("Expected JobExecutionAlreadyRunningException");
    } catch (JobExecutionAlreadyRunningException e) {
        // expected
    }
    long t1 = System.currentTimeMillis();

    int after = jdbcTemplate.queryForObject("SELECT COUNT(*) FROM BATCH_JOB_INSTANCE", Integer.class);
    assertNotNull(execution.getId());
    assertEquals(before, after);

    logger.info("Duration: " + (t1 - t0)
            + " - the second transaction did not block if this number is less than about 1000.");
}