Package org.springframework.batch.core

Examples of org.springframework.batch.core.StepExecution


  @Test(expected = MessageTimeoutException.class)
  public void messageReceiveTimeout() throws Exception {
    //execute with no default set
    messageChannelPartitionHandler = new MessageChannelPartitionHandler();
    //mock
    StepExecution masterStepExecution = mock(StepExecution.class);
    StepExecutionSplitter stepExecutionSplitter = mock(StepExecutionSplitter.class);
    MessagingTemplate operations = mock(MessagingTemplate.class);
    Message message = mock(Message.class);
    //when
    HashSet<StepExecution> stepExecutions = new HashSet<StepExecution>();
    stepExecutions.add(new StepExecution("step1", new JobExecution(5l)));
    when(stepExecutionSplitter.split((StepExecution) anyObject(), eq(1))).thenReturn(stepExecutions);
    when(message.getPayload()).thenReturn(Collections.emptyList());
    //set
    messageChannelPartitionHandler.setMessagingOperations(operations);
View Full Code Here


  @DirtiesContext
  public void testFailedStep() throws Exception {
    JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three",
        new JobParameter("unsupported"))));
    assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
    StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next();
    assertEquals(9, stepExecution.getReadCount());
    // In principle the write count could be more than 2 and less than 9...
    assertEquals(7, stepExecution.getWriteCount());
  }
View Full Code Here

  @DirtiesContext
  public void testFailedStepOnError() throws Exception {
    JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three",
        new JobParameter("error"))));
    assertEquals(BatchStatus.FAILED, jobExecution.getStatus());
    StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next();
    assertEquals(9, stepExecution.getReadCount());
    // In principle the write count could be more than 2 and less than 9...
    assertEquals(7, stepExecution.getWriteCount());
  }
View Full Code Here

  @DirtiesContext
  public void testSunnyDayFaultTolerant() throws Exception {
    JobExecution jobExecution = jobLauncher.run(job, new JobParameters(Collections.singletonMap("item.three",
        new JobParameter("3"))));
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
    StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next();
    assertEquals(9, stepExecution.getReadCount());
    assertEquals(9, stepExecution.getWriteCount());
  }
View Full Code Here

  public void testSkipsInWriter() throws Exception {
    JobExecution jobExecution = jobLauncher.run(job, new JobParametersBuilder().addString("item.three", "fail")
        .addLong("run.id", 1L).toJobParameters());
    // System.err.println(new SimpleJdbcTemplate(dataSource).queryForList("SELECT * FROM INT_MESSAGE_GROUP"));
    assertEquals(BatchStatus.COMPLETED, jobExecution.getStatus());
    StepExecution stepExecution = jobExecution.getStepExecutions().iterator().next();
    assertEquals(9, stepExecution.getReadCount());
    assertEquals(7, stepExecution.getWriteCount());
    // The whole chunk gets skipped...
    assertEquals(2, stepExecution.getWriteSkipCount());
  }
View Full Code Here

    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

    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

    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"));

    waitForResults(1, 10);

    assertEquals(1, TestItemWriter.count);
    assertEquals(0, stepExecution.getReadCount());

  }
View Full Code Here

        .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"));

    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.
    assertTrue(1 <= TestItemWriter.count);
    assertTrue(6 >= TestItemWriter.count);
    // But it should fail the step in any case
    assertEquals(BatchStatus.FAILED, stepExecution.getStatus());

  }
View Full Code Here

    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 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"));

    assertEquals(0, TestItemWriter.count);
    assertEquals(0, stepExecution.getReadCount());

  }
View Full Code Here

TOP

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

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.