Package org.springframework.batch.core

Examples of org.springframework.batch.core.Step


  public void testVanillaIteration() throws Exception {

    factory.setItemReader(new ListItemReader<String>(Arrays.asList(StringUtils
        .commaDelimitedListToStringArray("1,2,3,4,5,6"))));

    Step step = (Step) factory.getObject();

    StepExecution stepExecution = getStepExecution(step);
    step.execute(stepExecution);

    waitForResults(6, 10);

    assertEquals(6, TestItemWriter.count);
    assertEquals(6, stepExecution.getReadCount());
View Full Code Here


  public void testSimulatedRestart() throws Exception {

    factory.setItemReader(new ListItemReader<String>(Arrays.asList(StringUtils
        .commaDelimitedListToStringArray("1,2,3,4,5,6"))));

    Step step = (Step) factory.getObject();

    StepExecution stepExecution = getStepExecution(step);

    // Set up context with two messages (chunks) in the backlog
    stepExecution.getExecutionContext().putInt(ChunkMessageChannelItemWriter.EXPECTED, 6);
    stepExecution.getExecutionContext().putInt(ChunkMessageChannelItemWriter.ACTUAL, 4);
    // And make the back log real
    requests.send(getSimpleMessage("foo", stepExecution.getJobExecution().getJobId()));
    requests.send(getSimpleMessage("bar", stepExecution.getJobExecution().getJobId()));
    step.execute(stepExecution);

    waitForResults(8, 10);

    assertEquals(8, TestItemWriter.count);
    assertEquals(6, stepExecution.getReadCount());
View Full Code Here

  public void testSimulatedRestartWithBadMessagesFromAnotherJob() throws Exception {

    factory.setItemReader(new ListItemReader<String>(Arrays.asList(StringUtils
        .commaDelimitedListToStringArray("1,2,3,4,5,6"))));

    Step step = (Step) factory.getObject();

    StepExecution stepExecution = getStepExecution(step);

    // Set up context with two messages (chunks) in the backlog
    stepExecution.getExecutionContext().putInt(ChunkMessageChannelItemWriter.EXPECTED, 3);
    stepExecution.getExecutionContext().putInt(ChunkMessageChannelItemWriter.ACTUAL, 2);

    // Speed up the eventual failure
    writer.setMaxWaitTimeouts(2);

    // And make the back log real
    requests.send(getSimpleMessage("foo", 4321L));
    step.execute(stepExecution);
    assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
    assertEquals(ExitStatus.FAILED.getExitCode(), stepExecution.getExitStatus().getExitCode());
    String message = stepExecution.getExitStatus().getExitDescription();
    assertTrue("Message does not contain 'wrong job': " + message, message.contains("wrong job"));
View Full Code Here

    factory.setItemReader(new ListItemReader<String>(Arrays.asList(StringUtils
        .commaDelimitedListToStringArray("1,fail,3,4,5,6"))));
    factory.setCommitInterval(2);

    Step step = (Step) factory.getObject();

    StepExecution stepExecution = getStepExecution(step);
    step.execute(stepExecution);
    assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
    assertEquals(ExitStatus.FAILED.getExitCode(), stepExecution.getExitStatus().getExitCode());
    String message = stepExecution.getExitStatus().getExitDescription();
    assertTrue("Message does not contain 'fail': " + message, message.contains("fail"));
View Full Code Here

  public void testSimulatedRestartWithNoBacklog() throws Exception {

    factory.setItemReader(new ListItemReader<String>(Arrays.asList(StringUtils
        .commaDelimitedListToStringArray("1,2,3,4,5,6"))));

    Step step = (Step) factory.getObject();

    StepExecution stepExecution = getStepExecution(step);

    // Set up expectation of three messages (chunks) in the backlog
    stepExecution.getExecutionContext().putInt(ChunkMessageChannelItemWriter.EXPECTED, 6);
    stepExecution.getExecutionContext().putInt(ChunkMessageChannelItemWriter.ACTUAL, 3);

    writer.setMaxWaitTimeouts(2);

    /*
     * With no backlog we process all the items, but the listener can't
     * reconcile the expected number of items with the actual. An infinite
     * loop would be bad, so the best we can do is fail as fast as possible.
     */
    step.execute(stepExecution);
    assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
    assertEquals(ExitStatus.FAILED.getExitCode(), stepExecution.getExitStatus().getExitCode());
    String message = stepExecution.getExitStatus().getExitDescription();
    assertTrue("Message did not contain 'timed out': " + message, message.toLowerCase().contains("timed out"));

View Full Code Here

  public void testFailureInStepListener() throws Exception {

    factory.setItemReader(new ListItemReader<String>(Arrays.asList(StringUtils
        .commaDelimitedListToStringArray("wait,fail,3,4,5,6"))));

    Step step = (Step) factory.getObject();

    StepExecution stepExecution = getStepExecution(step);
    step.execute(stepExecution);

    waitForResults(2, 10);

    // The number of items processed is actually between 1 and 6, because
    // the one that failed might have been processed out of order.
View Full Code Here

  public void testVanillaIteration() throws Exception {

    factory.setItemReader(new ListItemReader<String>(Arrays.asList(StringUtils
        .commaDelimitedListToStringArray("1,2,3,4,5,6"))));

    Step step = factory.getObject();

    StepExecution stepExecution = getStepExecution(step);
    step.execute(stepExecution);

    waitForResults(6, 10);

    assertEquals(6, TestItemWriter.count);
    assertEquals(6, stepExecution.getReadCount());
View Full Code Here

  public void testSimulatedRestart() throws Exception {

    factory.setItemReader(new ListItemReader<String>(Arrays.asList(StringUtils
        .commaDelimitedListToStringArray("1,2,3,4,5,6"))));

    Step step = factory.getObject();

    StepExecution stepExecution = getStepExecution(step);

    // Set up context with two messages (chunks) in the backlog
    stepExecution.getExecutionContext().putInt(ChunkMessageChannelItemWriter.EXPECTED, 6);
    stepExecution.getExecutionContext().putInt(ChunkMessageChannelItemWriter.ACTUAL, 4);
    // And make the back log real
    requests.send(getSimpleMessage("foo", stepExecution.getJobExecution().getJobId()));
    requests.send(getSimpleMessage("bar", stepExecution.getJobExecution().getJobId()));
    step.execute(stepExecution);

    waitForResults(8, 10);

    assertEquals(8, TestItemWriter.count);
    assertEquals(6, stepExecution.getReadCount());
View Full Code Here

  public void testSimulatedRestartWithBadMessagesFromAnotherJob() throws Exception {

    factory.setItemReader(new ListItemReader<String>(Arrays.asList(StringUtils
        .commaDelimitedListToStringArray("1,2,3,4,5,6"))));

    Step step = factory.getObject();

    StepExecution stepExecution = getStepExecution(step);

    // Set up context with two messages (chunks) in the backlog
    stepExecution.getExecutionContext().putInt(ChunkMessageChannelItemWriter.EXPECTED, 3);
    stepExecution.getExecutionContext().putInt(ChunkMessageChannelItemWriter.ACTUAL, 2);

    // Speed up the eventual failure
    writer.setMaxWaitTimeouts(2);

    // And make the back log real
    requests.send(getSimpleMessage("foo", 4321L));
    step.execute(stepExecution);
    assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
    assertEquals(ExitStatus.FAILED.getExitCode(), stepExecution.getExitStatus().getExitCode());
    String message = stepExecution.getExitStatus().getExitDescription();
    assertTrue("Message does not contain 'wrong job': " + message, message.contains("wrong job"));
View Full Code Here

    factory.setItemReader(new ListItemReader<String>(Arrays.asList(StringUtils
        .commaDelimitedListToStringArray("1,fail,3,4,5,6"))));
    factory.setCommitInterval(2);

    Step step = factory.getObject();

    StepExecution stepExecution = getStepExecution(step);
    step.execute(stepExecution);
    assertEquals(BatchStatus.FAILED, stepExecution.getStatus());
    assertEquals(ExitStatus.FAILED.getExitCode(), stepExecution.getExitStatus().getExitCode());
    String message = stepExecution.getExitStatus().getExitDescription();
    assertTrue("Message does not contain 'fail': " + message, message.contains("fail"));
View Full Code Here

TOP

Related Classes of org.springframework.batch.core.Step

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.