Added namespace support for <priority-channel/> (INT-131).
This commit is contained in:
@@ -91,7 +91,7 @@ public class PriorityChannelTests {
|
||||
}
|
||||
|
||||
|
||||
private static class StringPayloadComparator implements Comparator<Message<?>> {
|
||||
public static class StringPayloadComparator implements Comparator<Message<?>> {
|
||||
|
||||
public int compare(Message<?> message1, Message<?> message2) {
|
||||
String s1 = (String) message1.getPayload();
|
||||
|
||||
@@ -205,6 +205,47 @@ public class ChannelParserTests {
|
||||
assertEquals(1, interceptor.getReceiveCount());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPriorityChannelWithDefaultComparator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"priorityChannelParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("priorityChannelWithDefaultComparator");
|
||||
Message<?> lowPriorityMessage = new StringMessage("low");
|
||||
lowPriorityMessage.getHeader().setPriority(777);
|
||||
Message<?> midPriorityMessage = new StringMessage("mid");
|
||||
midPriorityMessage.getHeader().setPriority(77);
|
||||
Message<?> highPriorityMessage = new StringMessage("high");
|
||||
highPriorityMessage.getHeader().setPriority(7);
|
||||
channel.send(lowPriorityMessage);
|
||||
channel.send(highPriorityMessage);
|
||||
channel.send(midPriorityMessage);
|
||||
Message<?> reply1 = channel.receive(0);
|
||||
Message<?> reply2 = channel.receive(0);
|
||||
Message<?> reply3 = channel.receive(0);
|
||||
assertEquals("high", reply1.getPayload());
|
||||
assertEquals("mid", reply2.getPayload());
|
||||
assertEquals("low", reply3.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testPriorityChannelWithCustomComparator() {
|
||||
ApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"priorityChannelParserTests.xml", this.getClass());
|
||||
MessageChannel channel = (MessageChannel) context.getBean("priorityChannelWithCustomComparator");
|
||||
channel.send(new StringMessage("C"));
|
||||
channel.send(new StringMessage("A"));
|
||||
channel.send(new StringMessage("D"));
|
||||
channel.send(new StringMessage("B"));
|
||||
Message<?> reply1 = channel.receive(0);
|
||||
Message<?> reply2 = channel.receive(0);
|
||||
Message<?> reply3 = channel.receive(0);
|
||||
Message<?> reply4 = channel.receive(0);
|
||||
assertEquals("A", reply1.getPayload());
|
||||
assertEquals("B", reply2.getPayload());
|
||||
assertEquals("C", reply3.getPayload());
|
||||
assertEquals("D", reply4.getPayload());
|
||||
}
|
||||
|
||||
|
||||
private static class TestHandler implements MessageHandler {
|
||||
|
||||
|
||||
@@ -0,0 +1,17 @@
|
||||
<?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-core-1.0.xsd">
|
||||
|
||||
<priority-channel id="priorityChannelWithDefaultComparator"/>
|
||||
|
||||
<priority-channel id="priorityChannelWithCustomComparator" comparator-ref="stringPayloadComparator"/>
|
||||
|
||||
<beans:bean id="stringPayloadComparator"
|
||||
class="org.springframework.integration.channel.PriorityChannelTests$StringPayloadComparator"/>
|
||||
|
||||
</beans:beans>
|
||||
Reference in New Issue
Block a user