use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class RecipientListRouterTests method applySequenceEnabled.
@Test
public void applySequenceEnabled() {
QueueChannel channelA = new QueueChannel(1);
QueueChannel channelB = new QueueChannel(1);
channelA.setBeanName("channelA");
channelB.setBeanName("channelB");
RecipientListRouter router = new RecipientListRouter();
router.setApplySequence(true);
List<MessageChannel> channels = new ArrayList<MessageChannel>();
channels.add(channelA);
channels.add(channelB);
router.setChannels(channels);
Message<String> message = new GenericMessage<String>("test");
router.handleMessage(message);
Message<?> result1a = channelA.receive(0);
Message<?> result1b = channelB.receive(0);
assertNotNull(result1a);
assertNotNull(result1b);
assertEquals("test", result1a.getPayload());
assertEquals(1, new IntegrationMessageHeaderAccessor(result1a).getSequenceNumber());
assertEquals(2, new IntegrationMessageHeaderAccessor(result1a).getSequenceSize());
assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(result1a).getCorrelationId());
assertEquals("test", result1b.getPayload());
assertEquals(2, new IntegrationMessageHeaderAccessor(result1b).getSequenceNumber());
assertEquals(2, new IntegrationMessageHeaderAccessor(result1b).getSequenceSize());
assertEquals(message.getHeaders().getId(), new IntegrationMessageHeaderAccessor(result1b).getCorrelationId());
}
use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class RecipientListRouterTests method applySequenceNotEnabledByDefault.
@Test
public void applySequenceNotEnabledByDefault() {
QueueChannel channelA = new QueueChannel(1);
QueueChannel channelB = new QueueChannel(1);
channelA.setBeanName("channelA");
channelB.setBeanName("channelB");
RecipientListRouter router = new RecipientListRouter();
List<MessageChannel> channels = new ArrayList<MessageChannel>();
channels.add(channelA);
channels.add(channelB);
router.setChannels(channels);
Message<String> message = new GenericMessage<String>("test");
router.handleMessage(message);
Message<?> result1a = channelA.receive(0);
Message<?> result1b = channelB.receive(0);
assertNotNull(result1a);
assertNotNull(result1b);
assertEquals("test", result1a.getPayload());
assertEquals(0, new IntegrationMessageHeaderAccessor(result1a).getSequenceNumber());
assertEquals(0, new IntegrationMessageHeaderAccessor(result1a).getSequenceSize());
assertNull(new IntegrationMessageHeaderAccessor(result1a).getCorrelationId());
assertEquals("test", result1b.getPayload());
assertEquals(0, new IntegrationMessageHeaderAccessor(result1b).getSequenceNumber());
assertEquals(0, new IntegrationMessageHeaderAccessor(result1b).getSequenceSize());
assertNull(new IntegrationMessageHeaderAccessor(result1b).getCorrelationId());
}
use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class ResequencerTests method testResequencingWithIncompleteSequenceRelease.
@Test
public void testResequencingWithIncompleteSequenceRelease() throws InterruptedException {
this.resequencer.setReleaseStrategy(new SequenceSizeReleaseStrategy(true));
// INT-3846
this.resequencer.setMessageStore(new SimpleMessageStore(3));
QueueChannel replyChannel = new QueueChannel();
Message<?> message1 = createMessage("123", "ABC", 4, 4, replyChannel);
Message<?> message2 = createMessage("456", "ABC", 4, 2, replyChannel);
// release 2 after this one
Message<?> message3 = createMessage("789", "ABC", 4, 1, replyChannel);
Message<?> message4 = createMessage("XYZ", "ABC", 4, 3, replyChannel);
this.resequencer.handleMessage(message1);
this.resequencer.handleMessage(message2);
this.resequencer.handleMessage(message3);
Message<?> reply1 = replyChannel.receive(0);
Message<?> reply2 = replyChannel.receive(0);
Message<?> reply3 = replyChannel.receive(0);
// only messages 1 and 2 should have been received by now
assertNotNull(reply1);
assertEquals(1, new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber());
assertNotNull(reply2);
assertEquals(2, new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber());
assertNull(reply3);
// when sending the last message, the whole sequence must have been sent
this.resequencer.handleMessage(message4);
reply3 = replyChannel.receive(0);
Message<?> reply4 = replyChannel.receive(0);
assertNotNull(reply3);
assertEquals(3, new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber());
assertNotNull(reply4);
assertEquals(4, new IntegrationMessageHeaderAccessor(reply4).getSequenceNumber());
}
use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class ResequencerTests method testResequencingWithDuplicateMessages.
@Test
public void testResequencingWithDuplicateMessages() {
QueueChannel replyChannel = new QueueChannel();
Message<?> message1 = createMessage("123", "ABC", 3, 3, replyChannel);
Message<?> message2 = createMessage("456", "ABC", 3, 1, replyChannel);
Message<?> message3 = createMessage("789", "ABC", 3, 2, replyChannel);
this.resequencer.handleMessage(message1);
this.resequencer.handleMessage(message3);
this.resequencer.handleMessage(message3);
this.resequencer.handleMessage(message2);
Message<?> reply1 = replyChannel.receive(0);
Message<?> reply2 = replyChannel.receive(0);
Message<?> reply3 = replyChannel.receive(0);
assertNotNull(reply1);
assertEquals(1, new IntegrationMessageHeaderAccessor(reply1).getSequenceNumber());
assertNotNull(reply2);
assertEquals(2, new IntegrationMessageHeaderAccessor(reply2).getSequenceNumber());
assertNotNull(reply3);
assertEquals(3, new IntegrationMessageHeaderAccessor(reply3).getSequenceNumber());
}
use of org.springframework.integration.IntegrationMessageHeaderAccessor in project spring-integration by spring-projects.
the class ResequencerTests method testResequencingWithDifferentSequenceSizes.
@Test
public void testResequencingWithDifferentSequenceSizes() throws InterruptedException {
QueueChannel discardChannel = new QueueChannel();
Message<?> message1 = createMessage("123", "ABC", 4, 2, null);
Message<?> message2 = createMessage("456", "ABC", 5, 1, null);
this.resequencer.setSendPartialResultOnExpiry(false);
this.resequencer.setDiscardChannel(discardChannel);
// force SequenceSizeReleaseStrategy
this.resequencer.setReleasePartialSequences(true);
this.resequencer.handleMessage(message1);
this.resequencer.handleMessage(message2);
// this.resequencer.discardBarrier(this.resequencer.barriers.get("ABC"));
Message<?> discard1 = discardChannel.receive(0);
Message<?> discard2 = discardChannel.receive(0);
// message2 has been discarded because it came in with the wrong sequence size
assertNotNull(discard1);
assertEquals(1, new IntegrationMessageHeaderAccessor(discard1).getSequenceNumber());
assertNull(discard2);
}
Aggregations