Example usage for org.springframework.batch.core StepExecution getWriteCount

List of usage examples for org.springframework.batch.core StepExecution getWriteCount

Introduction

In this page you can find the example usage for org.springframework.batch.core StepExecution getWriteCount.

Prototype

public int getWriteCount() 

Source Link

Document

Returns the current number of items written for this execution

Usage

From source file:org.seedstack.spring.batch.fixtures.FlatFileBatchDemo.java

protected static void printStatistics(JobExecution jobExecution) {
    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        System.out.println("-----------------------------------");
        System.out.println("STEP name: " + stepExecution.getStepName());
        System.out.println("-----------------------------------");
        System.out.println("CommitCount: " + stepExecution.getCommitCount());
        System.out.println("FilterCount: " + stepExecution.getFilterCount());
        System.out.println("ProcessSkipCount: " + stepExecution.getProcessSkipCount());
        System.out.println("ReadCount: " + stepExecution.getReadCount());
        System.out.println("ReadSkipCount: " + stepExecution.getReadSkipCount());
        System.out.println("RollbackCount: " + stepExecution.getRollbackCount());
        System.out.println("SkipCount: " + stepExecution.getSkipCount());
        System.out.println("WriteCount: " + stepExecution.getWriteCount());
        System.out.println("WriteSkipCount: " + stepExecution.getWriteSkipCount());
        if (stepExecution.getFailureExceptions().size() > 0) {
            System.out.println("exceptions:");
            System.out.println("-----------------------------------");
            for (Throwable t : stepExecution.getFailureExceptions()) {
                System.out.println(t.getMessage());
            }//from   w w w .  j a  v  a 2s  .  c  o  m
        }
        System.out.println("-----------------------------------");
    }
}

From source file:org.jasig.ssp.util.importer.job.twodottwo.StageSuccessTest.java

@Test
public void testStageSuccess() throws Exception {

    //Test file should have 1 step which should write successfully
    JobExecution jobExecution = jobLauncherTestUtils.launchJob();
    Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions();
    for (StepExecution stepExecution : stepExecutions) {
        Assert.assertEquals(stepExecution.getWriteCount(), 1);
    }/*w ww.j  a va 2  s.  c  om*/
    BatchStatus exitStatus = jobExecution.getStatus();

    Assert.assertEquals(BatchStatus.COMPLETED, exitStatus);

}

From source file:org.jasig.ssp.util.importer.job.twodottwo.StageSuccessWithSkipTest.java

@Test
public void testStageSuccessWithSkip() throws Exception {

    //Test file should have 1 step which should write successfully but skip 1 line
    JobExecution jobExecution = jobLauncherTestUtils.launchJob();
    Collection<StepExecution> stepExecutions = jobExecution.getStepExecutions();
    for (StepExecution stepExecution : stepExecutions) {
        Assert.assertEquals(1, stepExecution.getWriteCount());
        Assert.assertEquals(1, stepExecution.getSkipCount());
    }/*w ww.j av a 2 s .c o m*/
    BatchStatus exitStatus = jobExecution.getStatus();

    Assert.assertEquals(BatchStatus.COMPLETED, exitStatus);

}

From source file:org.cloudfoundry.identity.uaa.scim.job.BackwardMigrationJobIntegrationTests.java

@Test
public void testJobRuns() throws Exception {
    TestUtils.deleteFrom(cloudControllerDataSource, "users");
    TestUtils.deleteFrom(uaaDataSource, "users");
    JdbcTemplate uaaTemplate = new JdbcTemplate(uaaDataSource);
    uaaTemplate.update(/*from www  . j  a  v  a2  s. c om*/
            "insert into users "
                    + "(id, active, userName, email, password, familyName, givenName, created, lastModified) "
                    + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
            "FOO", true, "uniqua", "uniqua@test.org", "ENCRYPT_ME", "Una", "Uniqua", new Date(), new Date());
    JobExecution execution = jobLauncher.run(job,
            new JobParametersBuilder().addDate("start.date", new Date(0L)).toJobParameters());
    assertEquals(BatchStatus.COMPLETED, execution.getStatus());
    Iterator<StepExecution> iterator = execution.getStepExecutions().iterator();
    StepExecution step = iterator.next();
    assertEquals(1, step.getReadCount());
    assertEquals(1, step.getWriteCount());
    JdbcTemplate jdbcTemplate = new JdbcTemplate(cloudControllerDataSource);
    assertEquals(1, jdbcTemplate.queryForInt("select count(*) from users"));
}

From source file:com.javaetmoi.core.batch.test.EndTasklet.java

@Override
public RepeatStatus execute(StepContribution contribution, ChunkContext chunkContext) {
    JobExecution jobExecution = chunkContext.getStepContext().getStepExecution().getJobExecution();
    StepExecution resume = getUnpartitionedStepResume(jobExecution);
    LOG.info("{} masterpiece(s) have been processed", resume.getWriteCount());
    return RepeatStatus.FINISHED;
}

From source file:org.cloudfoundry.identity.uaa.scim.job.ClearNamesJobIntegrationTests.java

@Test
public void testJobRuns() throws Exception {
    TestUtils.deleteFrom(cloudControllerDataSource, "users");
    TestUtils.deleteFrom(uaaDataSource, "users");
    JdbcTemplate uaaTemplate = new JdbcTemplate(uaaDataSource);
    uaaTemplate.update(//from w  w w. ja va  2s.c  o m
            "insert into users "
                    + "(id, active, userName, email, password, familyName, givenName, created, lastModified) "
                    + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
            "FOO", true, "uniqua", "uniqua@test.org", "ENCRYPT_ME", "Una", "Uniqua", new Date(), new Date());
    uaaTemplate.update(
            "insert into users "
                    + "(id, active, userName, email, password, familyName, givenName, created, lastModified) "
                    + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
            "BAR", true, "username", "uniqua@test.org", "ENCRYPT_ME", "uniqua", "test.org", new Date(),
            new Date());
    uaaTemplate.update(
            "insert into users "
                    + "(id, active, userName, email, password, familyName, givenName, created, lastModified) "
                    + "values (?, ?, ?, ?, ?, ?, ?, ?, ?)",
            "SPAM", true, "another", "uniqua@test.org", "ENCRYPT_ME", "another", "another", new Date(),
            new Date());
    JobExecution execution = jobLauncher.run(job,
            new JobParametersBuilder().addDate("start.date", new Date(0L)).toJobParameters());
    assertEquals(BatchStatus.COMPLETED, execution.getStatus());
    Iterator<StepExecution> iterator = execution.getStepExecutions().iterator();
    StepExecution step = iterator.next();
    assertEquals(3, step.getReadCount());
    assertEquals(2, step.getWriteCount());
    assertEquals(2, uaaTemplate.queryForInt("select count(*) from users where givenName is null"));
}

From source file:com.javaetmoi.elasticsearch.musicbrainz.batch.TestMusicAlbumJob.java

@Test
public void indexMusicAlbum() throws Exception {
    JobExecution execution = testUtils.launchJob();

    // Batch Status
    assertEquals(ExitStatus.COMPLETED, execution.getExitStatus());
    StepExecution indexMusicAlbum = getStepExecution(execution, "indexMusicAlbum");
    assertEquals(13, indexMusicAlbum.getWriteCount());
    assertEquals(2 * 2, indexMusicAlbum.getCommitCount());

    // Elasticsearch status
    ElasticSearchHelper.refreshIndex(client);
    DocsStatus docs = getDocStatus();/*  w w w  .  j  av a2 s  .  c om*/
    assertEquals(13, docs.getNumDocs());
}

From source file:com.javaetmoi.core.batch.test.TestParallelAndPartitioning.java

@Test
public void launchJob() throws Exception {
    // Launch the parallelAndPartitioningJob
    JobExecution execution = testUtils.launchJob();

    // Batch Status
    assertEquals(ExitStatus.COMPLETED, execution.getExitStatus());

    // Movies/*w  ww .j  a  v  a 2s .  c  o m*/
    assertEquals("8 movies", 8, getStepExecution(execution, "stepLogMovie").getWriteCount());

    // Music Albums
    StepExecution stepExecutionMusic = getStepExecution(execution, "stepLogMusicAlbum");
    assertEquals("11 music albums", 11, stepExecutionMusic.getWriteCount());
    Object gridSize = ExecutionContextTestUtils.getValueFromStep(stepExecutionMusic,
            "SimpleStepExecutionSplitter.GRID_SIZE");
    assertEquals("stepLogMusicAlbum divided into 2 partitions", 2L, gridSize);

    StepExecution stepExecPart0 = getStepExecution(execution, "stepLogMusicAlbumPartition:partition0");
    assertEquals("First partition processed 6 music albums", 6, stepExecPart0.getWriteCount());
    StepExecution stepExecPart1 = getStepExecution(execution, "stepLogMusicAlbumPartition:partition1");
    assertEquals("Second partition processed 5 music albums", 5, stepExecPart1.getWriteCount());
}

From source file:admin.jmx.SimpleStepExecutionMetrics.java

public int getLatestWriteCount() {
    StepExecution stepExecution = getLatestStepExecution(stepName);
    return stepExecution == null ? 0 : stepExecution.getWriteCount();
}

From source file:de.langmi.spring.batch.templates.importfile.generic.GenericJobConfigurationTest.java

/** Launch Test. */
@Test/*from ww  w .ja v  a  2s. co m*/
public void launchJob() throws Exception {
    // Job parameters, commit.rate is set with properties file and Spring placeholder 
    Map<String, JobParameter> jobParametersMap = new HashMap<String, JobParameter>();
    jobParametersMap.put("time", new JobParameter(System.currentTimeMillis()));
    jobParametersMap.put("input.files", new JobParameter("file:src/test/resources/input/generic/*.txt"));

    // launch the job
    JobExecution jobExecution = jobLauncherTestUtils.launchJob(new JobParameters(jobParametersMap));

    // assert job run status
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());

    // assert read/written items
    for (StepExecution stepExecution : jobExecution.getStepExecutions()) {
        assertEquals(EXPECTED_COUNT, stepExecution.getReadCount());
        assertEquals(EXPECTED_COUNT, stepExecution.getWriteCount());
    }

    // assert items are written successfully to database
    assertEquals(EXPECTED_COUNT, jdbcTemplate.queryForInt(COUNT_SQL));
}