diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/RepeatTransactionalPollingIntegrationTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/RepeatTransactionalPollingIntegrationTests.java index 2955c0530..7123be74b 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/RepeatTransactionalPollingIntegrationTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/RepeatTransactionalPollingIntegrationTests.java @@ -33,6 +33,10 @@ public class RepeatTransactionalPollingIntegrationTests implements ApplicationCo private List processed = new ArrayList(); + private List expected; + + private List handled = new ArrayList(); + private List list = new ArrayList(); private Lifecycle bus; @@ -47,7 +51,10 @@ public class RepeatTransactionalPollingIntegrationTests implements ApplicationCo public String process(String message) { String result = message + ": " + count; logger.debug("Handling: " + message); - processed.add(message); + if (count expected = TransactionAwareProxyFactory.createTransactionalList(Arrays.asList(StringUtils + .commaDelimitedListToStringArray("a,b,c,d"))); + service.setExpected(expected); + waitForResults(bus, expected.size(), 60); assertEquals(4,service.getProcessed().size()); // a,b,c,d - assertEquals(4,count); + assertEquals(expected, service.getProcessed()); } @Test @@ -78,12 +81,14 @@ public class RetryRepeatTransactionalPollingIntegrationTests implements Applicat public void testRollback() throws Exception { list = TransactionAwareProxyFactory.createTransactionalList(Arrays.asList(StringUtils .commaDelimitedListToStringArray("a,b,fail,d,e,f,g,h,j,k"))); + List expected = TransactionAwareProxyFactory.createTransactionalList(Arrays.asList(StringUtils + .commaDelimitedListToStringArray("a,b,fail,fail,d,e,f"))); + service.setExpected(expected); + waitForResults(bus, expected.size(), 60); waitForResults(bus, 6, 100); // (a,b), (fail), (fail), ([fail],d), (e,f) - System.err.println(service.getProcessed()); - System.err.println(recoverer.getRecovered()); assertEquals(7,service.getProcessed().size()); // a,b,fail,fail,d,e,f assertEquals(1,recoverer.getRecovered().size()); // fail - assertEquals(5,count); // a,b,d,e,f + assertEquals(expected, service.getProcessed()); } private void waitForResults(Lifecycle lifecycle, int count, int maxTries) throws InterruptedException { diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/RetryTransactionalPollingIntegrationTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/RetryTransactionalPollingIntegrationTests.java index 103e18334..31085402e 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/RetryTransactionalPollingIntegrationTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/RetryTransactionalPollingIntegrationTests.java @@ -46,7 +46,7 @@ public class RetryTransactionalPollingIntegrationTests implements ApplicationCon } private volatile int count = 0; - + @ChannelAdapter("requests") @Poller(interval=10, transactionManager="transactionManager") public String input() { @@ -68,9 +68,12 @@ public class RetryTransactionalPollingIntegrationTests implements ApplicationCon public void testSunnyDay() throws Exception { list = TransactionAwareProxyFactory.createTransactionalList(Arrays.asList(StringUtils .commaDelimitedListToStringArray("a,b,c,d,e,f,g,h,j,k"))); - waitForResults(bus, 4, 60); + List expected = TransactionAwareProxyFactory.createTransactionalList(Arrays.asList(StringUtils + .commaDelimitedListToStringArray("a,b,c,d"))); + service.setExpected(expected); + waitForResults(bus, expected.size(), 60); assertEquals(4,service.getProcessed().size()); // a,b,c,d - assertEquals(4,count); + assertEquals(expected, service.getProcessed()); } @Test @@ -78,12 +81,15 @@ public class RetryTransactionalPollingIntegrationTests implements ApplicationCon public void testRollback() throws Exception { list = TransactionAwareProxyFactory.createTransactionalList(Arrays.asList(StringUtils .commaDelimitedListToStringArray("a,b,fail,d,e,f,g,h,j,k"))); - waitForResults(bus, 6, 200); // (a), (b), (fail), (fail), ... - System.err.println(service.getProcessed()); - System.err.println(recoverer.getRecovered()); + + List expected = TransactionAwareProxyFactory.createTransactionalList(Arrays.asList(StringUtils + .commaDelimitedListToStringArray("a,b,fail,fail,d,e"))); + service.setExpected(expected); + waitForResults(bus, expected.size(), 60); + waitForResults(bus, 6, 100); // (a,b), (fail), (fail), ([fail],d), (e,f) assertEquals(6,service.getProcessed().size()); // a,b,fail,fail,d,e assertEquals(1,recoverer.getRecovered().size()); // fail - assertEquals(4,count); // a,b,d,e + assertEquals(expected, service.getProcessed()); } private void waitForResults(Lifecycle lifecycle, int count, int maxTries) throws InterruptedException { diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/SimpleService.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/SimpleService.java index 6a72fb424..22d75adf3 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/SimpleService.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/SimpleService.java @@ -1,5 +1,6 @@ package org.springframework.batch.integration.retry; +import java.util.ArrayList; import java.util.List; import java.util.concurrent.CopyOnWriteArrayList; @@ -9,14 +10,20 @@ import org.springframework.integration.annotation.MessageEndpoint; import org.springframework.integration.annotation.ServiceActivator; @MessageEndpoint -public class SimpleService implements Service { +public class SimpleService implements Service { private Log logger = LogFactory.getLog(getClass()); private List processed = new CopyOnWriteArrayList(); + private List expected = new ArrayList(); + private int count = 0; - + + public void setExpected(List expected) { + this.expected = expected; + } + /** * Public getter for the processed. * @return the processed @@ -29,7 +36,9 @@ public class SimpleService implements Service { public String process(String message) { String result = message + ": " + (count++); logger.debug("Handling: " + message); - processed.add(message); + if (count <= expected.size()) { + processed.add(message); + } if ("fail".equals(message)) { throw new RuntimeException("Planned failure"); } diff --git a/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/TransactionalPollingIntegrationTests.java b/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/TransactionalPollingIntegrationTests.java index 2d0ad7bb2..7cade4203 100644 --- a/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/TransactionalPollingIntegrationTests.java +++ b/spring-batch-integration/src/test/java/org/springframework/batch/integration/retry/TransactionalPollingIntegrationTests.java @@ -33,6 +33,10 @@ public class TransactionalPollingIntegrationTests implements ApplicationContextA private List processed = new ArrayList(); + private List handled = new ArrayList(); + + private List expected; + private List list = new ArrayList(); private Lifecycle bus; @@ -47,7 +51,10 @@ public class TransactionalPollingIntegrationTests implements ApplicationContextA public String process(String message) { String result = message + ": " + count; logger.debug("Handling: " + message); - processed.add(message); + if (count