Added tests for 'dispatcher-policy' in ChannelParser. Added tests for 'concurrency' in EndpointParser.
This commit is contained in:
@@ -29,6 +29,7 @@ import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.dispatcher.DefaultMessageDispatcher;
|
||||
import org.springframework.integration.dispatcher.DispatcherPolicy;
|
||||
import org.springframework.integration.handler.MessageHandler;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
@@ -108,6 +109,32 @@ public class ChannelParserTests {
|
||||
assertEquals(2, counter.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultDispatcherPolicy() throws InterruptedException {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"channelParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("pointToPointChannelByDefault");
|
||||
DispatcherPolicy dispatcherPolicy = channel.getDispatcherPolicy();
|
||||
assertFalse(dispatcherPolicy.isPublishSubscribe());
|
||||
assertEquals(DispatcherPolicy.DEFAULT_MAX_MESSAGES_PER_TASK, dispatcherPolicy.getMaxMessagesPerTask());
|
||||
assertEquals(DispatcherPolicy.DEFAULT_RECEIVE_TIMEOUT, dispatcherPolicy.getReceiveTimeout());
|
||||
assertEquals(DispatcherPolicy.DEFAULT_REJECTION_LIMIT, dispatcherPolicy.getRejectionLimit());
|
||||
assertEquals(DispatcherPolicy.DEFAULT_RETRY_INTERVAL, dispatcherPolicy.getRetryInterval());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDispatcherPolicyConfiguration() throws InterruptedException {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"channelParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("channelWithDispatcherPolicy");
|
||||
DispatcherPolicy dispatcherPolicy = channel.getDispatcherPolicy();
|
||||
assertTrue(dispatcherPolicy.isPublishSubscribe());
|
||||
assertEquals(7, dispatcherPolicy.getMaxMessagesPerTask());
|
||||
assertEquals(77, dispatcherPolicy.getReceiveTimeout());
|
||||
assertEquals(777, dispatcherPolicy.getRejectionLimit());
|
||||
assertEquals(7777, dispatcherPolicy.getRetryInterval());
|
||||
}
|
||||
|
||||
|
||||
private static class TestHandler implements MessageHandler {
|
||||
|
||||
|
||||
@@ -25,6 +25,8 @@ import org.junit.Test;
|
||||
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.endpoint.ConcurrencyPolicy;
|
||||
import org.springframework.integration.endpoint.DefaultMessageEndpoint;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
|
||||
/**
|
||||
@@ -58,4 +60,28 @@ public class EndpointParserTests {
|
||||
assertEquals("test", bean.getMessage());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testDefaultConcurrency() throws InterruptedException {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"endpointConcurrencyTests.xml", this.getClass());
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("defaultConcurrencyEndpoint");
|
||||
ConcurrencyPolicy concurrencyPolicy = endpoint.getConcurrencyPolicy();
|
||||
assertEquals(ConcurrencyPolicy.DEFAULT_CORE_SIZE, concurrencyPolicy.getCoreSize());
|
||||
assertEquals(ConcurrencyPolicy.DEFAULT_MAX_SIZE, concurrencyPolicy.getMaxSize());
|
||||
assertEquals(ConcurrencyPolicy.DEFAULT_QUEUE_CAPACITY, concurrencyPolicy.getQueueCapacity());
|
||||
assertEquals(ConcurrencyPolicy.DEFAULT_KEEP_ALIVE_SECONDS, concurrencyPolicy.getKeepAliveSeconds());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testConfiguredConcurrency() throws InterruptedException {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"endpointConcurrencyTests.xml", this.getClass());
|
||||
DefaultMessageEndpoint endpoint = (DefaultMessageEndpoint) context.getBean("configuredConcurrencyEndpoint");
|
||||
ConcurrencyPolicy concurrencyPolicy = endpoint.getConcurrencyPolicy();
|
||||
assertEquals(7, concurrencyPolicy.getCoreSize());
|
||||
assertEquals(77, concurrencyPolicy.getMaxSize());
|
||||
assertEquals(777, concurrencyPolicy.getQueueCapacity());
|
||||
assertEquals(7777, concurrencyPolicy.getKeepAliveSeconds());
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -15,4 +15,8 @@
|
||||
|
||||
<channel id="publishSubscribeChannel" publish-subscribe="true"/>
|
||||
|
||||
<channel id="channelWithDispatcherPolicy" publish-subscribe="true">
|
||||
<dispatcher-policy max-messages-per-task="7" receive-timeout="77" rejection-limit="777" retry-interval="7777"/>
|
||||
</channel>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
@@ -0,0 +1,26 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<beans:beans xmlns="http://www.springframework.org/schema/integration"
|
||||
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xmlns:beans="http://www.springframework.org/schema/beans"
|
||||
xsi:schemaLocation="http://www.springframework.org/schema/beans
|
||||
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
|
||||
http://www.springframework.org/schema/integration
|
||||
http://www.springframework.org/schema/integration/spring-integration-1.0.xsd">
|
||||
|
||||
<message-bus/>
|
||||
|
||||
<channel id="testChannel"/>
|
||||
|
||||
<endpoint id="defaultConcurrencyEndpoint" input-channel="testChannel" handler-ref="testHandler">
|
||||
<concurrency/>
|
||||
</endpoint>
|
||||
|
||||
<endpoint id="configuredConcurrencyEndpoint" input-channel="testChannel" handler-ref="testHandler">
|
||||
<concurrency core="7" max="77" queue-capacity="777" keep-alive="7777"/>
|
||||
</endpoint>
|
||||
|
||||
<beans:bean id="testHandler" class="org.springframework.integration.config.TestHandler">
|
||||
<beans:constructor-arg value="1"/>
|
||||
</beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user