INT-3877: BarrierParser and requires-reply

JIRA: https://jira.spring.io/browse/INT-3877

Failed to set the `requires-reply` boolean.
This commit is contained in:
Gary Russell
2015-11-04 16:45:11 -05:00
committed by Artem Bilan
parent c75a95c555
commit 895336f60a
4 changed files with 24 additions and 3 deletions

View File

@@ -44,6 +44,7 @@ public class BarrierParser extends AbstractConsumerEndpointParser {
IntegrationNamespaceUtils.injectConstructorWithAdapter("correlation-strategy",
"correlation-strategy-method", "correlation-strategy-expression",
"CorrelationStrategy", element, handlerBuilder, null, parserContext);
IntegrationNamespaceUtils.setValueIfAttributeDefined(handlerBuilder, element, "requires-reply");
return handlerBuilder;
}

View File

@@ -22,6 +22,7 @@ import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.spy;
import static org.mockito.Mockito.verify;
@@ -46,12 +47,12 @@ import org.springframework.beans.factory.BeanFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.integration.aggregator.BarrierMessageHandler;
import org.springframework.integration.annotation.Poller;
import org.springframework.integration.annotation.ServiceActivator;
import org.springframework.integration.channel.DirectChannel;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.config.EnableIntegration;
import org.springframework.integration.handler.ReplyRequiredException;
import org.springframework.integration.support.MessageBuilder;
import org.springframework.integration.test.util.TestUtils;
import org.springframework.messaging.Message;
@@ -194,6 +195,23 @@ public class BarrierMessageHandlerTests {
assertEquals(0, suspensions.size());
}
@Test
public void testRequiresReply() throws Exception {
final BarrierMessageHandler handler = new BarrierMessageHandler(0);
QueueChannel outputChannel = new QueueChannel();
handler.setOutputChannel(outputChannel);
handler.setBeanFactory(mock(BeanFactory.class));
handler.setRequiresReply(true);
handler.afterPropertiesSet();
try {
handler.handleMessage(MessageBuilder.withPayload("foo").setCorrelationId("foo").build());
fail("exception expected");
}
catch (Exception e) {
assertThat(e, Matchers.instanceOf(ReplyRequiredException.class));
}
}
@Test
public void testExceptionReply() throws Exception {
final BarrierMessageHandler handler = new BarrierMessageHandler(10000);

View File

@@ -9,7 +9,8 @@
<int:queue />
</int:channel>
<int:barrier id="barrier1" input-channel="in" output-channel="out" correlation-strategy-expression="'foo'"
<int:barrier id="barrier1" input-channel="in" output-channel="out" correlation-strategy-expression="'foo'"
requires-reply="true"
timeout="10000">
<int:poller fixed-delay="100" />
</int:barrier>

View File

@@ -20,6 +20,7 @@ import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -83,13 +84,13 @@ public class BarrierParserTests {
BarrierMessageHandler handler = TestUtils.getPropertyValue(this.barrier1, "handler",
BarrierMessageHandler.class);
assertEquals(10000L, TestUtils.getPropertyValue(handler, "timeout"));
assertTrue(TestUtils.getPropertyValue(handler, "requiresReply", Boolean.class));
assertThat(TestUtils.getPropertyValue(this.barrier2, "handler.correlationStrategy"),
instanceOf(HeaderAttributeCorrelationStrategy.class));
assertThat(TestUtils.getPropertyValue(this.barrier3, "handler.messageGroupProcessor"),
instanceOf(TestMGP.class));
assertThat(TestUtils.getPropertyValue(this.barrier3, "handler.correlationStrategy"),
instanceOf(TestCS.class));
}
public static class TestMGP implements MessageGroupProcessor {