INT-603: added custom comparator to resequencer
This commit is contained in:
@@ -32,12 +32,10 @@ import org.springframework.integration.store.MessageGroup;
|
||||
*
|
||||
* @since 2.0
|
||||
*/
|
||||
public class Resequencer implements ReleaseStrategy, MessageGroupProcessor {
|
||||
public class ResequencingMessageGroupProcessor implements MessageGroupProcessor {
|
||||
|
||||
private volatile Comparator<Message<?>> comparator = new SequenceNumberComparator();
|
||||
|
||||
private volatile boolean releasePartialSequences;
|
||||
|
||||
/**
|
||||
* A comparator to use to order messages before processing. The default is to order by sequence number.
|
||||
*
|
||||
@@ -47,27 +45,6 @@ public class Resequencer implements ReleaseStrategy, MessageGroupProcessor {
|
||||
this.comparator = comparator;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag that determines if partial sequences are allowed. If true then as soon as enough messages arrive that can be
|
||||
* ordered they will be released, provided they all have sequence numbers greater than those already released.
|
||||
*
|
||||
* @param releasePartialSequences
|
||||
*/
|
||||
public void setReleasePartialSequences(boolean releasePartialSequences) {
|
||||
this.releasePartialSequences = releasePartialSequences;
|
||||
}
|
||||
|
||||
public boolean canRelease(MessageGroup messages) {
|
||||
if (releasePartialSequences) {
|
||||
List<Message<?>> sorted = new ArrayList<Message<?>>(messages.getUnmarked());
|
||||
Collections.sort(sorted, comparator);
|
||||
int head = sorted.get(sorted.size() - 1).getHeaders().getSequenceNumber();
|
||||
int tail = sorted.get(0).getHeaders().getSequenceNumber() - 1;
|
||||
return tail == messages.getMarked().size() && head - tail == sorted.size();
|
||||
}
|
||||
return messages.isComplete();
|
||||
}
|
||||
|
||||
public void processAndSend(MessageGroup group, MessageChannelTemplate channelTemplate, MessageChannel outputChannel) {
|
||||
Collection<Message<?>> messages = group.getUnmarked();
|
||||
if (messages.size() > 0) {
|
||||
@@ -79,10 +56,4 @@ public class Resequencer implements ReleaseStrategy, MessageGroupProcessor {
|
||||
}
|
||||
}
|
||||
|
||||
private static class SequenceNumberComparator implements Comparator<Message<?>> {
|
||||
public int compare(Message<?> o1, Message<?> o2) {
|
||||
return o1.getHeaders().getSequenceNumber().compareTo(o2.getHeaders().getSequenceNumber());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,48 @@
|
||||
/*
|
||||
* Copyright 2002-2010 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.aggregator;
|
||||
|
||||
import java.util.Comparator;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
|
||||
/**
|
||||
* @author Dave Syer
|
||||
*
|
||||
* @since 2.0
|
||||
*
|
||||
*/
|
||||
public class SequenceNumberComparator implements Comparator<Message<?>> {
|
||||
|
||||
/**
|
||||
* If both messages have a sequence number then compare that, otherwise if one has a sequence number and the other
|
||||
* doesn't then the numbered message comes first, or finally of neither has a sequence number then they are equal in
|
||||
* rank.
|
||||
*/
|
||||
public int compare(Message<?> o1, Message<?> o2) {
|
||||
Integer sequenceNumber1 = o1.getHeaders().getSequenceNumber();
|
||||
Integer sequenceNumber2 = o2.getHeaders().getSequenceNumber();
|
||||
if (sequenceNumber1 == sequenceNumber2) {
|
||||
return 0;
|
||||
}
|
||||
if (sequenceNumber1 == null) {
|
||||
return -sequenceNumber2;
|
||||
}
|
||||
if (sequenceNumber2 == null) {
|
||||
return sequenceNumber1;
|
||||
}
|
||||
return sequenceNumber1.compareTo(sequenceNumber2);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -16,6 +16,12 @@
|
||||
|
||||
package org.springframework.integration.aggregator;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collections;
|
||||
import java.util.Comparator;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.integration.core.Message;
|
||||
import org.springframework.integration.store.MessageGroup;
|
||||
|
||||
/**
|
||||
@@ -28,7 +34,36 @@ import org.springframework.integration.store.MessageGroup;
|
||||
*/
|
||||
public class SequenceSizeReleaseStrategy implements ReleaseStrategy {
|
||||
|
||||
private volatile Comparator<Message<?>> comparator = new SequenceNumberComparator();
|
||||
|
||||
private volatile boolean releasePartialSequences;
|
||||
|
||||
public SequenceSizeReleaseStrategy() {
|
||||
this(false);
|
||||
}
|
||||
|
||||
public SequenceSizeReleaseStrategy(boolean releasePartialSequences) {
|
||||
this.releasePartialSequences = releasePartialSequences;
|
||||
}
|
||||
|
||||
/**
|
||||
* Flag that determines if partial sequences are allowed. If true then as soon as enough messages arrive that can be
|
||||
* ordered they will be released, provided they all have sequence numbers greater than those already released.
|
||||
*
|
||||
* @param releasePartialSequences
|
||||
*/
|
||||
public void setReleasePartialSequences(boolean releasePartialSequences) {
|
||||
this.releasePartialSequences = releasePartialSequences;
|
||||
}
|
||||
|
||||
public boolean canRelease(MessageGroup messages) {
|
||||
if (releasePartialSequences) {
|
||||
List<Message<?>> sorted = new ArrayList<Message<?>>(messages.getUnmarked());
|
||||
Collections.sort(sorted, comparator);
|
||||
int head = sorted.get(sorted.size() - 1).getHeaders().getSequenceNumber();
|
||||
int tail = sorted.get(0).getHeaders().getSequenceNumber() - 1;
|
||||
return tail == messages.getMarked().size() && head - tail == sorted.size();
|
||||
}
|
||||
return messages.isComplete();
|
||||
}
|
||||
|
||||
|
||||
@@ -50,7 +50,7 @@ public class AggregatorParser extends AbstractConsumerEndpointParser {
|
||||
|
||||
private static final String SEND_TIMEOUT_ATTRIBUTE = "send-timeout";
|
||||
|
||||
private static final String SEND_PARTIAL_RESULT_ON_TIMEOUT_ATTRIBUTE = "send-partial-result-on-expiry";
|
||||
private static final String SEND_PARTIAL_RESULT_ON_EXPIRY_ATTRIBUTE = "send-partial-result-on-expiry";
|
||||
|
||||
private static final String RELEASE_STRATEGY_PROPERTY = "releaseStrategy";
|
||||
|
||||
@@ -97,7 +97,7 @@ public class AggregatorParser extends AbstractConsumerEndpointParser {
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,
|
||||
SEND_TIMEOUT_ATTRIBUTE);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element,
|
||||
SEND_PARTIAL_RESULT_ON_TIMEOUT_ATTRIBUTE);
|
||||
SEND_PARTIAL_RESULT_ON_EXPIRY_ATTRIBUTE);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup");
|
||||
this.injectPropertyWithBean(RELEASE_STRATEGY_REF_ATTRIBUTE,
|
||||
RELEASE_STRATEGY_METHOD_ATTRIBUTE, RELEASE_STRATEGY_PROPERTY,
|
||||
|
||||
@@ -1,21 +1,19 @@
|
||||
/*
|
||||
* Copyright 2002-2009 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
|
||||
* the License. You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
|
||||
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
|
||||
* specific language governing permissions and limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.integration.config.xml;
|
||||
|
||||
import org.springframework.beans.factory.config.RuntimeBeanReference;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionBuilder;
|
||||
import org.springframework.beans.factory.support.BeanDefinitionReaderUtils;
|
||||
import org.springframework.beans.factory.xml.ParserContext;
|
||||
@@ -30,18 +28,39 @@ import org.w3c.dom.Element;
|
||||
*/
|
||||
public class ResequencerParser extends AbstractConsumerEndpointParser {
|
||||
|
||||
private static final String CORRELATION_STRATEGY_METHOD_ATTRIBUTE = "correlation-strategy-method";
|
||||
|
||||
private static final String CORRELATION_STRATEGY_ATTRIBUTE = "correlation-strategy";
|
||||
|
||||
private static final String SEND_PARTIAL_RESULT_ON_EXPIRY_ATTRIBUTE = "send-partial-result-on-expiry";
|
||||
|
||||
private static final String SEND_TIMEOUT_ATTRIBUTE = "send-timeout";
|
||||
|
||||
private static final String DISCARD_CHANNEL_ATTRIBUTE = "discard-channel";
|
||||
|
||||
private static final String MESSAGE_STORE_ATTRIBUTE = "message-store";
|
||||
|
||||
private static final String COMPARATOR_ATTRIBUTE = "comparator";
|
||||
|
||||
private static final String RELEASE_STRATEGY_REF_ATTRIBUTE = "release-strategy";
|
||||
|
||||
private static final String RELEASE_STRATEGY_METHOD_ATTRIBUTE = "release-strategy-method";
|
||||
|
||||
private static final String RELEASE_PARTIAL_SEQUENCES_ATTRIBUTE = "release-partial-sequences";
|
||||
|
||||
@Override
|
||||
protected BeanDefinitionBuilder parseHandler(Element element, ParserContext parserContext) {
|
||||
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE + ".aggregator.CorrelatingMessageHandler");
|
||||
BeanDefinitionBuilder processorBuilder = BeanDefinitionBuilder.genericBeanDefinition(
|
||||
IntegrationNamespaceUtils.BASE_PACKAGE + ".aggregator.Resequencer");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(processorBuilder, element, "release-partial-sequences");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(processorBuilder, element, "comparator");
|
||||
BeanDefinitionBuilder processorBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE
|
||||
+ ".aggregator.ResequencingMessageGroupProcessor");
|
||||
|
||||
String processorRef = BeanDefinitionReaderUtils.registerWithGeneratedName(processorBuilder
|
||||
.getBeanDefinition(), parserContext.getRegistry());
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(processorBuilder, element, COMPARATOR_ATTRIBUTE);
|
||||
|
||||
String processorRef = BeanDefinitionReaderUtils.registerWithGeneratedName(processorBuilder.getBeanDefinition(),
|
||||
parserContext.getRegistry());
|
||||
|
||||
// Message group processor
|
||||
builder.addConstructorArgReference(processorRef);
|
||||
@@ -53,25 +72,42 @@ public class ResequencerParser extends AbstractConsumerEndpointParser {
|
||||
String correlationStrategyRef = getCorrelationStrategyRef(element, parserContext);
|
||||
if (correlationStrategyRef != null) {
|
||||
builder.addConstructorArgReference(correlationStrategyRef);
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
// Correlation strategy
|
||||
builder.addConstructorArgValue(null);
|
||||
}
|
||||
// Release strategy
|
||||
builder.addConstructorArgReference(processorRef);
|
||||
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "message-store");
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, "discard-channel");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-timeout");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-partial-result-on-expiry");
|
||||
// Release strategy
|
||||
builder.addConstructorArgValue(getReleaseStrategy(element, parserContext));
|
||||
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, MESSAGE_STORE_ATTRIBUTE);
|
||||
IntegrationNamespaceUtils.setReferenceIfAttributeDefined(builder, element, DISCARD_CHANNEL_ATTRIBUTE);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, SEND_TIMEOUT_ATTRIBUTE);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, SEND_PARTIAL_RESULT_ON_EXPIRY_ATTRIBUTE);
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "auto-startup");
|
||||
return builder;
|
||||
}
|
||||
|
||||
private Object getReleaseStrategy(Element element, ParserContext parserContext) {
|
||||
String releaseStrategyRef = getReleasenStrategyRef(element, parserContext);
|
||||
if (releaseStrategyRef == null) {
|
||||
BeanDefinitionBuilder builder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE
|
||||
+ ".aggregator.SequenceSizeReleaseStrategy");
|
||||
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, RELEASE_PARTIAL_SEQUENCES_ATTRIBUTE);
|
||||
return builder.getBeanDefinition();
|
||||
}
|
||||
if (StringUtils.hasText(element.getAttribute(RELEASE_PARTIAL_SEQUENCES_ATTRIBUTE))) {
|
||||
parserContext.getReaderContext().error(
|
||||
"Only one of " + RELEASE_PARTIAL_SEQUENCES_ATTRIBUTE + " and " + RELEASE_STRATEGY_REF_ATTRIBUTE
|
||||
+ " can be specified at once", element);
|
||||
}
|
||||
return new RuntimeBeanReference(releaseStrategyRef);
|
||||
}
|
||||
|
||||
private String getCorrelationStrategyRef(Element element, ParserContext parserContext) {
|
||||
String ref = element.getAttribute("correlation-strategy");
|
||||
String method = element.getAttribute("correlation-strategy-method");
|
||||
String ref = element.getAttribute(CORRELATION_STRATEGY_ATTRIBUTE);
|
||||
String method = element.getAttribute(CORRELATION_STRATEGY_METHOD_ATTRIBUTE);
|
||||
if (StringUtils.hasText(ref)) {
|
||||
if (StringUtils.hasText(method)) {
|
||||
BeanDefinitionBuilder adapterBuilder = BeanDefinitionBuilder
|
||||
@@ -83,8 +119,28 @@ public class ResequencerParser extends AbstractConsumerEndpointParser {
|
||||
String adapterBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(adapterBuilder
|
||||
.getBeanDefinition(), parserContext.getRegistry());
|
||||
return adapterBeanName;
|
||||
} else {
|
||||
return ref;
|
||||
}
|
||||
else {
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getReleasenStrategyRef(Element element, ParserContext parserContext) {
|
||||
String ref = element.getAttribute(RELEASE_STRATEGY_REF_ATTRIBUTE);
|
||||
String method = element.getAttribute(RELEASE_STRATEGY_METHOD_ATTRIBUTE);
|
||||
if (StringUtils.hasText(ref)) {
|
||||
if (StringUtils.hasText(method)) {
|
||||
BeanDefinitionBuilder adapterBuilder = BeanDefinitionBuilder
|
||||
.genericBeanDefinition(IntegrationNamespaceUtils.BASE_PACKAGE
|
||||
+ ".aggregator.ReleaseStrategyAdapter");
|
||||
adapterBuilder.addConstructorArgReference(ref);
|
||||
adapterBuilder.getRawBeanDefinition().getConstructorArgumentValues().addGenericArgumentValue(method,
|
||||
"java.lang.String");
|
||||
String adapterBeanName = BeanDefinitionReaderUtils.registerWithGeneratedName(adapterBuilder
|
||||
.getBeanDefinition(), parserContext.getRegistry());
|
||||
return adapterBeanName;
|
||||
} else {
|
||||
return ref;
|
||||
}
|
||||
}
|
||||
|
||||
File diff suppressed because it is too large
Load Diff
@@ -43,18 +43,17 @@ public class ResequencerTests {
|
||||
|
||||
private CorrelatingMessageHandler resequencer;
|
||||
|
||||
private Resequencer processor = new Resequencer();
|
||||
private ResequencingMessageGroupProcessor processor = new ResequencingMessageGroupProcessor();
|
||||
|
||||
private MessageGroupStore store = new SimpleMessageStore();
|
||||
|
||||
@Before
|
||||
public void configureResequencer() {
|
||||
this.resequencer = new CorrelatingMessageHandler(processor, store, null, processor);
|
||||
this.resequencer = new CorrelatingMessageHandler(processor, store, null, null);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testBasicResequencing() throws InterruptedException {
|
||||
this.processor.setReleasePartialSequences(false);
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
Message<?> message1 = createMessage("123", "ABC", 3, 3, replyChannel);
|
||||
Message<?> message2 = createMessage("456", "ABC", 3, 1, replyChannel);
|
||||
@@ -75,7 +74,6 @@ public class ResequencerTests {
|
||||
|
||||
@Test
|
||||
public void testBasicResequencingWithCustomComparator() throws InterruptedException {
|
||||
this.processor.setReleasePartialSequences(false);
|
||||
this.processor.setComparator(new Comparator<Message<?>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public int compare(Message<?> o1, Message<?> o2) {
|
||||
@@ -102,7 +100,6 @@ public class ResequencerTests {
|
||||
|
||||
@Test
|
||||
public void testResequencingWithDuplicateMessages() {
|
||||
this.processor.setReleasePartialSequences(false);
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
Message<?> message1 = createMessage("123", "ABC", 3, 3, replyChannel);
|
||||
Message<?> message2 = createMessage("456", "ABC", 3, 1, replyChannel);
|
||||
@@ -124,7 +121,7 @@ public class ResequencerTests {
|
||||
|
||||
@Test
|
||||
public void testResequencingWithIncompleteSequenceRelease() throws InterruptedException {
|
||||
this.processor.setReleasePartialSequences(true);
|
||||
this.resequencer.setReleaseStrategy(new SequenceSizeReleaseStrategy(true));
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
Message<?> message1 = createMessage("123", "ABC", 4, 2, replyChannel);
|
||||
Message<?> message2 = createMessage("456", "ABC", 4, 1, replyChannel);
|
||||
@@ -144,6 +141,41 @@ public class ResequencerTests {
|
||||
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(new Integer(3), reply3.getHeaders().getSequenceNumber());
|
||||
assertNotNull(reply4);
|
||||
assertEquals(new Integer(4), reply4.getHeaders().getSequenceNumber());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResequencingWithPartialSequenceAndComparator() throws InterruptedException {
|
||||
this.resequencer.setReleaseStrategy(new SequenceSizeReleaseStrategy(true));
|
||||
this.processor.setComparator(new Comparator<Message<?>>() {
|
||||
@SuppressWarnings("unchecked")
|
||||
public int compare(Message<?> o1, Message<?> o2) {
|
||||
return ((Comparable)o1.getPayload()).compareTo(o2.getPayload());
|
||||
}
|
||||
});
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
Message<?> message1 = createMessage("456", "ABC", 4, 2, replyChannel);
|
||||
Message<?> message2 = createMessage("123", "ABC", 4, 1, replyChannel);
|
||||
Message<?> message3 = createMessage("XYZ", "ABC", 4, 4, replyChannel);
|
||||
Message<?> message4 = createMessage("789", "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(new Integer(1), reply1.getHeaders().getSequenceNumber());
|
||||
assertNotNull(reply2);
|
||||
assertEquals(new Integer(2), reply2.getHeaders().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);
|
||||
@@ -159,7 +191,6 @@ public class ResequencerTests {
|
||||
Message<?> message2 = createMessage("456", "ABC", 4, 1, null);
|
||||
Message<?> message3 = createMessage("789", "ABC", 4, 4, null);
|
||||
this.resequencer.setSendPartialResultOnExpiry(false);
|
||||
this.processor.setReleasePartialSequences(false);
|
||||
this.resequencer.setDiscardChannel(discardChannel);
|
||||
this.resequencer.handleMessage(message1);
|
||||
this.resequencer.handleMessage(message2);
|
||||
@@ -187,7 +218,6 @@ public class ResequencerTests {
|
||||
Message<?> message1 = createMessage("123", "ABC", 4, 2, null);
|
||||
Message<?> message2 = createMessage("456", "ABC", 5, 1, null);
|
||||
this.resequencer.setSendPartialResultOnExpiry(false);
|
||||
this.processor.setReleasePartialSequences(false);
|
||||
this.resequencer.setDiscardChannel(discardChannel);
|
||||
this.resequencer.handleMessage(message1);
|
||||
this.resequencer.handleMessage(message2);
|
||||
@@ -205,7 +235,6 @@ public class ResequencerTests {
|
||||
QueueChannel discardChannel = new QueueChannel();
|
||||
Message<?> message1 = createMessage("123", "ABC", 2, 4, null);
|
||||
this.resequencer.setSendPartialResultOnExpiry(false);
|
||||
this.processor.setReleasePartialSequences(false);
|
||||
this.resequencer.setDiscardChannel(discardChannel);
|
||||
this.resequencer.handleMessage(message1);
|
||||
// this.resequencer.discardBarrier(this.resequencer.barriers.get("ABC"));
|
||||
@@ -216,7 +245,6 @@ public class ResequencerTests {
|
||||
|
||||
@Test
|
||||
public void testResequencingWithCompleteSequenceRelease() throws InterruptedException {
|
||||
this.processor.setReleasePartialSequences(false);
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
Message<?> message1 = createMessage("123", "ABC", 4, 2, replyChannel);
|
||||
Message<?> message2 = createMessage("456", "ABC", 4, 1, replyChannel);
|
||||
|
||||
@@ -30,7 +30,8 @@ import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.aggregator.CorrelatingMessageHandler;
|
||||
import org.springframework.integration.aggregator.CorrelationStrategy;
|
||||
import org.springframework.integration.aggregator.CorrelationStrategyAdapter;
|
||||
import org.springframework.integration.aggregator.Resequencer;
|
||||
import org.springframework.integration.aggregator.ReleaseStrategyAdapter;
|
||||
import org.springframework.integration.aggregator.ResequencingMessageGroupProcessor;
|
||||
import org.springframework.integration.channel.NullChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.core.Message;
|
||||
@@ -88,7 +89,7 @@ public class ResequencerParserTests {
|
||||
"The ResequencerEndpoint is not configured with the appropriate 'send partial results on timeout' flag",
|
||||
false, getPropertyValue(resequencer, "sendPartialResultOnExpiry"));
|
||||
assertEquals("The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag",
|
||||
false, getPropertyValue(getPropertyValue(resequencer, "outputProcessor"), "releasePartialSequences"));
|
||||
false, getPropertyValue(getPropertyValue(resequencer, "releaseStrategy"), "releasePartialSequences"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -108,7 +109,7 @@ public class ResequencerParserTests {
|
||||
"The ResequencerEndpoint is not configured with the appropriate 'send partial results on timeout' flag",
|
||||
true, getPropertyValue(resequencer, "sendPartialResultOnExpiry"));
|
||||
assertEquals("The ResequencerEndpoint is not configured with the appropriate 'release partial sequences' flag",
|
||||
false, getPropertyValue(getPropertyValue(resequencer, "outputProcessor"), "releasePartialSequences"));
|
||||
false, getPropertyValue(getPropertyValue(resequencer, "releaseStrategy"), "releasePartialSequences"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -139,12 +140,23 @@ public class ResequencerParserTests {
|
||||
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("resequencerWithComparator");
|
||||
CorrelatingMessageHandler handler = TestUtils.getPropertyValue(endpoint, "handler",
|
||||
CorrelatingMessageHandler.class);
|
||||
Resequencer resequencer = TestUtils.getPropertyValue(handler, "outputProcessor", Resequencer.class);
|
||||
ResequencingMessageGroupProcessor resequencer = TestUtils.getPropertyValue(handler, "outputProcessor",
|
||||
ResequencingMessageGroupProcessor.class);
|
||||
Object comparator = getPropertyValue(resequencer, "comparator");
|
||||
assertEquals("The Resequencer is not configured with a TestComparator", TestComparator.class, comparator
|
||||
.getClass());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testReleaseStrategy() throws Exception {
|
||||
EventDrivenConsumer endpoint = (EventDrivenConsumer) context.getBean("resequencerWithReleaseStrategy");
|
||||
CorrelatingMessageHandler handler = TestUtils.getPropertyValue(endpoint, "handler",
|
||||
CorrelatingMessageHandler.class);
|
||||
Object releaseStrategy = getPropertyValue(handler, "releaseStrategy");
|
||||
assertEquals("The Resequencer is not configured with an adapter", ReleaseStrategyAdapter.class, releaseStrategy
|
||||
.getClass());
|
||||
}
|
||||
|
||||
private static <T> Message<T> createMessage(T payload, Object correlationId, int sequenceSize, int sequenceNumber,
|
||||
MessageChannel outputChannel) {
|
||||
return MessageBuilder.withPayload(payload).setCorrelationId(correlationId).setSequenceSize(sequenceSize)
|
||||
|
||||
@@ -27,6 +27,8 @@
|
||||
|
||||
<channel id="inputChannel5"/>
|
||||
|
||||
<channel id="inputChannel6"/>
|
||||
|
||||
<resequencer id="completelyDefinedResequencer"
|
||||
input-channel="inputChannel2"
|
||||
output-channel="outputChannel"
|
||||
@@ -47,6 +49,11 @@
|
||||
<resequencer id="resequencerWithComparator"
|
||||
input-channel="inputChannel5"
|
||||
comparator="testComparator"/>
|
||||
|
||||
<resequencer id="resequencerWithReleaseStrategy"
|
||||
input-channel="inputChannel6"
|
||||
release-strategy="pojoReleaseStrategy"
|
||||
release-strategy-method="checkCompleteness"/>
|
||||
|
||||
<beans:bean id="testComparator"
|
||||
class="org.springframework.integration.config.ResequencerParserTests$TestComparator"/>
|
||||
@@ -57,4 +64,9 @@
|
||||
<beans:bean id="testCorrelationStrategyPojo"
|
||||
class="org.springframework.integration.config.ResequencerParserTests$TestCorrelationStrategyPojo"/>
|
||||
|
||||
<beans:bean id="pojoReleaseStrategy"
|
||||
class="org.springframework.integration.config.MaxValueReleaseStrategy">
|
||||
<beans:constructor-arg value="10" />
|
||||
</beans:bean>
|
||||
|
||||
</beans:beans>
|
||||
|
||||
Reference in New Issue
Block a user