Example usage for org.springframework.batch.core.step.item FatalRuntimeException FatalRuntimeException

List of usage examples for org.springframework.batch.core.step.item FatalRuntimeException FatalRuntimeException

Introduction

In this page you can find the example usage for org.springframework.batch.core.step.item FatalRuntimeException FatalRuntimeException.

Prototype

public FatalRuntimeException(String message) 

Source Link

Usage

From source file:org.springframework.batch.core.step.item.FaultTolerantStepFactoryBeanTests.java

/**
 * Fatal exception should cause immediate termination provided the exception
 * is not skippable (note the fatal exception is also classified as
 * rollback).//  ww  w.j a v  a2s  .  c  o  m
 */
@Test
public void testFatalException() throws Exception {
    reader.setFailures("2");

    Map<Class<? extends Throwable>, Boolean> map = new HashMap<Class<? extends Throwable>, Boolean>();
    map.put(SkippableException.class, true);
    map.put(SkippableRuntimeException.class, true);
    map.put(FatalRuntimeException.class, false);
    factory.setSkippableExceptionClasses(map);
    factory.setItemWriter(new ItemWriter<String>() {
        @Override
        public void write(List<? extends String> items) {
            throw new FatalRuntimeException("Ouch!");
        }
    });

    Step step = factory.getObject();

    step.execute(stepExecution);
    String message = stepExecution.getFailureExceptions().get(0).getCause().getMessage();
    assertEquals("Wrong message: ", "Ouch!", message);
    assertStepExecutionsAreEqual(stepExecution,
            repository.getLastStepExecution(jobExecution.getJobInstance(), step.getName()));
}