Example usage for org.springframework.batch.core.step AbstractStep setName

List of usage examples for org.springframework.batch.core.step AbstractStep setName

Introduction

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

Prototype

public void setName(String name) 

Source Link

Document

Set the name property.

Usage

From source file:org.springframework.batch.core.configuration.xml.StepParserStepFactoryBean.java

private void configureAbstractStep(AbstractStep ts) {
    if (name != null) {
        ts.setName(name);
    }//from w w w.  j a va  2 s.c o  m
    if (allowStartIfComplete != null) {
        ts.setAllowStartIfComplete(allowStartIfComplete);
    }
    if (jobRepository != null) {
        ts.setJobRepository(jobRepository);
    }
    if (startLimit != null) {
        ts.setStartLimit(startLimit);
    }
    if (listeners != null) {
        List<StepExecutionListener> newListeners = new ArrayList<StepExecutionListener>();
        for (StepListener listener : listeners) {
            if (listener instanceof StepExecutionListener) {
                newListeners.add((StepExecutionListener) listener);
            }
        }
        ts.setStepExecutionListeners(newListeners.toArray(new StepExecutionListener[0]));
    }
}

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

@SuppressWarnings("unchecked")
@Test//from   w w  w .j a va 2  s. c om
public void testSkipAndRetryWithWriteFailure() throws Exception {

    factory.setListeners(new StepListener[] { new SkipListenerSupport<String, String>() {
        @Override
        public void onSkipInWrite(String item, Throwable t) {
            recovered.add(item);
            assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
        }
    } });
    factory.setSkipLimit(2);
    ItemReader<String> provider = new ListItemReader<String>(Arrays.asList("a", "b", "c", "d", "e", "f")) {
        @Override
        public String read() {
            String item = super.read();
            logger.debug("Read Called! Item: [" + item + "]");
            provided.add(item);
            count++;
            return item;
        }
    };

    ItemWriter<String> itemWriter = new ItemWriter<String>() {
        @Override
        public void write(List<? extends String> item) throws Exception {
            logger.debug("Write Called! Item: [" + item + "]");
            processed.addAll(item);
            written.addAll(item);
            if (item.contains("b") || item.contains("d")) {
                throw new RuntimeException("Write error - planned but recoverable.");
            }
        }
    };
    factory.setItemReader(provider);
    factory.setItemWriter(itemWriter);
    factory.setRetryLimit(5);
    factory.setRetryableExceptionClasses(getExceptionMap(RuntimeException.class));
    AbstractStep step = (AbstractStep) factory.getObject();
    step.setName("mytest");
    StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
    repository.add(stepExecution);
    step.execute(stepExecution);

    assertEquals(2, recovered.size());
    assertEquals(2, stepExecution.getSkipCount());
    assertEquals(2, stepExecution.getWriteSkipCount());

    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("a,c,e,f"));
    assertEquals(expectedOutput, written);

    assertEquals("[a, b, c, d, e, f, null]", provided.toString());
    assertEquals("[a, b, b, b, b, b, b, c, d, d, d, d, d, d, e, f]", processed.toString());
    assertEquals("[b, d]", recovered.toString());
}

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

@SuppressWarnings("unchecked")
@Test/*from   w w  w . j a  v a 2 s .  co m*/
public void testSkipAndRetryWithWriteFailureAndNonTrivialCommitInterval() throws Exception {

    factory.setCommitInterval(3);
    factory.setListeners(new StepListener[] { new SkipListenerSupport<String, String>() {
        @Override
        public void onSkipInWrite(String item, Throwable t) {
            recovered.add(item);
            assertTrue(TransactionSynchronizationManager.isActualTransactionActive());
        }
    } });
    factory.setSkipLimit(2);
    ItemReader<String> provider = new ListItemReader<String>(Arrays.asList("a", "b", "c", "d", "e", "f")) {
        @Override
        public String read() {
            String item = super.read();
            logger.debug("Read Called! Item: [" + item + "]");
            provided.add(item);
            count++;
            return item;
        }
    };

    ItemWriter<String> itemWriter = new ItemWriter<String>() {
        @Override
        public void write(List<? extends String> item) throws Exception {
            logger.debug("Write Called! Item: [" + item + "]");
            processed.addAll(item);
            written.addAll(item);
            if (item.contains("b") || item.contains("d")) {
                throw new RuntimeException("Write error - planned but recoverable.");
            }
        }
    };
    factory.setItemReader(provider);
    factory.setItemWriter(itemWriter);
    factory.setRetryLimit(5);
    factory.setRetryableExceptionClasses(getExceptionMap(RuntimeException.class));
    AbstractStep step = (AbstractStep) factory.getObject();
    step.setName("mytest");
    StepExecution stepExecution = new StepExecution(step.getName(), jobExecution);
    repository.add(stepExecution);
    step.execute(stepExecution);

    assertEquals(2, recovered.size());
    assertEquals(2, stepExecution.getSkipCount());
    assertEquals(2, stepExecution.getWriteSkipCount());

    List<String> expectedOutput = Arrays.asList(StringUtils.commaDelimitedListToStringArray("a,c,e,f"));
    assertEquals(expectedOutput, written);

    // [a, b, c, d, e, f, null]
    assertEquals(7, provided.size());
    // [a, b, c, a, b, c, a, b, c, a, b, c, a, b, c, a, b, c, d, e, f, d,
    // e, f, d, e, f, d, e, f, d, e, f, d, e, f]
    // System.err.println(processed);
    assertEquals(36, processed.size());
    // [b, d]
    assertEquals(2, recovered.size());
}