Merge pull request #648 from olegz/INT-2280

This commit is contained in:
Gary Russell
2012-10-11 21:03:35 -04:00
2 changed files with 13 additions and 8 deletions

View File

@@ -32,7 +32,7 @@
<service-activator id="service-activator" input-channel="input" output-channel="output" xmlns="http://www.springframework.org/schema/integration"> <service-activator id="service-activator" input-channel="input" output-channel="output" xmlns="http://www.springframework.org/schema/integration">
<beans:bean class="org.springframework.integration.jdbc.JdbcMessageStoreChannelTests$Service" /> <beans:bean class="org.springframework.integration.jdbc.JdbcMessageStoreChannelTests$Service" />
<poller fixed-rate="200"> <poller fixed-rate="2000">
<transactional /> <transactional />
</poller> </poller>
</service-activator> </service-activator>

View File

@@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2011 the original author or authors. * Copyright 2002-2012 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@@ -44,7 +44,7 @@ public class JdbcMessageStoreChannelTests {
@Autowired @Autowired
private JdbcMessageStore messageStore; private JdbcMessageStore messageStore;
@BeforeTransaction @BeforeTransaction
public void clear() { public void clear() {
for (MessageGroup group : messageStore) { for (MessageGroup group : messageStore) {
@@ -60,7 +60,7 @@ public class JdbcMessageStoreChannelTests {
assertEquals(1, Service.messages.size()); assertEquals(1, Service.messages.size());
assertEquals(0, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size()); assertEquals(0, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size());
} }
@Test @Test
public void testSendAndActivateWithRollback() throws Exception { public void testSendAndActivateWithRollback() throws Exception {
Service.reset(1); Service.reset(1);
@@ -71,7 +71,7 @@ public class JdbcMessageStoreChannelTests {
// After a rollback in the poller the message is still waiting to be delivered // After a rollback in the poller the message is still waiting to be delivered
assertEquals(1, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size()); assertEquals(1, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size());
} }
@Test @Test
@Transactional @Transactional
public void testSendAndActivateTransactionalSend() throws Exception { public void testSendAndActivateTransactionalSend() throws Exception {
@@ -89,13 +89,15 @@ public class JdbcMessageStoreChannelTests {
// But inside the transaction the message is still there // But inside the transaction the message is still there
assertEquals(1, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size()); assertEquals(1, messageStore.getMessageGroup("JdbcMessageStoreChannelTests").size());
} }
public static class Service { public static class Service {
private static boolean fail = false; private static boolean fail = false;
private static boolean alreadyFailed = false;
private static List<String> messages = new CopyOnWriteArrayList<String>(); private static List<String> messages = new CopyOnWriteArrayList<String>();
private static CountDownLatch latch = new CountDownLatch(0); private static CountDownLatch latch = new CountDownLatch(0);
public static void reset(int count) { public static void reset(int count) {
fail = false; fail = false;
alreadyFailed = false;
messages.clear(); messages.clear();
latch = new CountDownLatch(count); latch = new CountDownLatch(count);
} }
@@ -105,9 +107,12 @@ public class JdbcMessageStoreChannelTests {
} }
} }
public String echo(String input) { public String echo(String input) {
messages.add(input); if (!alreadyFailed) {
latch.countDown(); messages.add(input);
latch.countDown();
}
if (fail) { if (fail) {
alreadyFailed = true;
throw new RuntimeException("Planned failure"); throw new RuntimeException("Planned failure");
} }
return input; return input;