BATCH-63: added <retry-listeners>

This commit is contained in:
trisberg
2008-11-13 22:11:01 +00:00
parent 2c0f0ca8a0
commit 5274b55883
5 changed files with 95 additions and 39 deletions

View File

@@ -31,6 +31,7 @@ import org.springframework.batch.core.repository.JobRepository;
import org.springframework.batch.core.repository.support.MapJobRepositoryFactoryBean;
import org.springframework.batch.core.step.item.FaultTolerantStepFactoryBean;
import org.springframework.batch.item.ItemStream;
import org.springframework.batch.retry.RetryListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.test.context.ContextConfiguration;
@@ -59,6 +60,9 @@ public class StepWithFaultTolerantProcessTaskJobParserTests {
@Qualifier("listener")
private TestListener listener;
@Autowired
private TestRetryListener retryListener;
@Autowired
private TestProcessor processor;
@@ -85,6 +89,8 @@ public class StepWithFaultTolerantProcessTaskJobParserTests {
assertEquals("wrong retry-limit:", 3, rl);
Object listeners = ReflectionTestUtils.getField(factory, "listeners");
assertEquals("wrong number of listeners:", 2, ((StepListener[])listeners).length);
Object retryListeners = ReflectionTestUtils.getField(factory, "retryListeners");
assertEquals("wrong number of retry-listeners:", 1, ((RetryListener[])retryListeners).length);
Object streams = ReflectionTestUtils.getField(factory, "streams");
assertEquals("wrong number of streams:", 1, ((ItemStream[])streams).length);
JobExecution jobExecution = jobRepository.createJobExecution(job.getName(), new JobParameters());
@@ -96,5 +102,6 @@ public class StepWithFaultTolerantProcessTaskJobParserTests {
assertTrue(processor.isExecuted());
assertTrue(writer.isExecuted());
assertTrue(listener.isExecuted());
assertTrue(retryListener.isExecuted());
}
}

View File

@@ -0,0 +1,23 @@
package org.springframework.batch.core.configuration.xml;
import org.springframework.batch.retry.RetryCallback;
import org.springframework.batch.retry.RetryContext;
import org.springframework.batch.retry.RetryListener;
public class TestRetryListener extends AbstractTestComponent implements RetryListener {
public <T> void close(RetryContext context, RetryCallback<T> callback,
Throwable throwable) {
}
public <T> void onError(RetryContext context, RetryCallback<T> callback,
Throwable throwable) {
}
public <T> boolean open(RetryContext context, RetryCallback<T> callback) {
System.out.println("RETRY RETRY RETRY RETRY");
executed = true;
return true;
}
}