Skip to content

Instantly share code, notes, and snippets.

@cheongwy
Created June 18, 2012 03:18
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save cheongwy/2946687 to your computer and use it in GitHub Desktop.
Save cheongwy/2946687 to your computer and use it in GitHub Desktop.
Spring Integration Resequencer Bug
import static org.junit.Assert.assertNotNull;
import java.util.Comparator;
import org.junit.Before;
import org.junit.Test;
import org.springframework.integration.Message;
import org.springframework.integration.MessageChannel;
import org.springframework.integration.aggregator.ResequencingMessageGroupProcessor;
import org.springframework.integration.aggregator.ResequencingMessageHandler;
import org.springframework.integration.channel.QueueChannel;
import org.springframework.integration.store.MessageGroupStore;
import org.springframework.integration.store.SimpleMessageStore;
import org.springframework.integration.support.MessageBuilder;
public class TestResequencer {
private ResequencingMessageHandler resequencer;
private ResequencingMessageGroupProcessor processor = new ResequencingMessageGroupProcessor();
private MessageGroupStore store = new SimpleMessageStore();
@Before
public void configureResequencer() {
this.resequencer = new ResequencingMessageHandler(processor, store, null, null);
}
@Test
public void testBasicResequencingWithCustomComparator() throws InterruptedException {
this.processor.setComparator(new Comparator<Message<?>>() {
@SuppressWarnings({ "unchecked", "rawtypes" })
public int compare(Message<?> o1, Message<?> o2) {
return ((Comparable)o1.getPayload()).compareTo(o2.getPayload());
}
});
QueueChannel replyChannel = new QueueChannel();
// swap payload of message (1 and 2) or (2 and 3) and the test will fail
Message<?> message1 = createMessage("a", "ABC", 3, 1, replyChannel);
Message<?> message2 = createMessage("b", "ABC", 3, 2, replyChannel);
Message<?> message3 = createMessage("c", "ABC", 3, 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);
assertNotNull(reply1);
// reply 2 will be null if messages are swapped as described above
assertNotNull(reply2);
assertNotNull(reply3);
}
private static Message<?> createMessage(String payload, Object correlationId, int sequenceSize, int sequenceNumber,
MessageChannel replyChannel) {
return MessageBuilder.withPayload(payload).setCorrelationId(correlationId).setSequenceSize(sequenceSize)
.setSequenceNumber(sequenceNumber).setReplyChannel(replyChannel).build();
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment