Added support for 'apply-sequence' on <publish-subscribe-channel/>. The BroadcastingDispatcher has the 'applySequence' property (INT-321).
This commit is contained in:
@@ -0,0 +1,79 @@
|
||||
/*
|
||||
* Copyright 2002-2008 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.config;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.beans.DirectFieldAccessor;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.dispatcher.BroadcastingDispatcher;
|
||||
import org.springframework.integration.dispatcher.PublishSubscribeChannel;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class PublishSubscribeChannelParserTests {
|
||||
|
||||
@Test
|
||||
public void defaultChannel() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"publishSubscribeChannelParserTests.xml", this.getClass());
|
||||
PublishSubscribeChannel channel = (PublishSubscribeChannel)
|
||||
context.getBean("defaultChannel");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
|
||||
BroadcastingDispatcher dispatcher = (BroadcastingDispatcher)
|
||||
accessor.getPropertyValue("dispatcher");
|
||||
DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
|
||||
assertNull(dispatcherAccessor.getPropertyValue("taskExecutor"));
|
||||
assertFalse((Boolean) dispatcherAccessor.getPropertyValue("applySequence"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applySequenceEnabled() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"publishSubscribeChannelParserTests.xml", this.getClass());
|
||||
PublishSubscribeChannel channel = (PublishSubscribeChannel)
|
||||
context.getBean("channelWithApplySequenceEnabled");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
|
||||
BroadcastingDispatcher dispatcher = (BroadcastingDispatcher)
|
||||
accessor.getPropertyValue("dispatcher");
|
||||
assertTrue((Boolean) new DirectFieldAccessor(dispatcher).getPropertyValue("applySequence"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void channelWithTaskExecutor() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"publishSubscribeChannelParserTests.xml", this.getClass());
|
||||
PublishSubscribeChannel channel = (PublishSubscribeChannel)
|
||||
context.getBean("channelWithTaskExecutor");
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
|
||||
BroadcastingDispatcher dispatcher = (BroadcastingDispatcher)
|
||||
accessor.getPropertyValue("dispatcher");
|
||||
DirectFieldAccessor dispatcherAccessor = new DirectFieldAccessor(dispatcher);
|
||||
TaskExecutor executor = (TaskExecutor) dispatcherAccessor.getPropertyValue("taskExecutor");
|
||||
assertNotNull(executor);
|
||||
assertEquals(context.getBean("pool"), executor);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
<?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">
|
||||
|
||||
<publish-subscribe-channel id="defaultChannel"/>
|
||||
|
||||
<publish-subscribe-channel id="channelWithApplySequenceEnabled" apply-sequence="true"/>
|
||||
|
||||
<publish-subscribe-channel id="channelWithTaskExecutor" task-executor="pool"/>
|
||||
|
||||
<pool-executor id="pool"/>
|
||||
|
||||
</beans:beans>
|
||||
@@ -16,18 +16,31 @@
|
||||
|
||||
package org.springframework.integration.dispatcher;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.easymock.EasyMock.*;
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.EasyMock.getCurrentArguments;
|
||||
import static org.easymock.EasyMock.isA;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.reset;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.atomic.AtomicBoolean;
|
||||
|
||||
import org.easymock.IAnswer;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
@@ -137,6 +150,51 @@ public class BroadcastingDispatcherTests {
|
||||
assertTrue("Timing out Runnable not executed", timingOutStarted.get());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applySequenceDisabledByDefault() {
|
||||
BroadcastingDispatcher dispatcher = new BroadcastingDispatcher();
|
||||
final List<Message<?>> messages = new ArrayList<Message<?>>();
|
||||
MessageTarget target = new MessageTarget() {
|
||||
public boolean send(Message<?> message) {
|
||||
messages.add(message);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
dispatcher.addTarget(target);
|
||||
dispatcher.addTarget(target);
|
||||
dispatcher.send(new StringMessage("test"));
|
||||
assertEquals(2, messages.size());
|
||||
assertEquals(0, (int) messages.get(0).getHeaders().getSequenceNumber());
|
||||
assertEquals(0, (int) messages.get(0).getHeaders().getSequenceSize());
|
||||
assertEquals(0, (int) messages.get(1).getHeaders().getSequenceNumber());
|
||||
assertEquals(0, (int) messages.get(1).getHeaders().getSequenceSize());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void applySequenceEnabled() {
|
||||
BroadcastingDispatcher dispatcher = new BroadcastingDispatcher();
|
||||
dispatcher.setApplySequence(true);
|
||||
final List<Message<?>> messages = new ArrayList<Message<?>>();
|
||||
MessageTarget target = new MessageTarget() {
|
||||
public boolean send(Message<?> message) {
|
||||
messages.add(message);
|
||||
return true;
|
||||
}
|
||||
};
|
||||
dispatcher.addTarget(target);
|
||||
dispatcher.addTarget(target);
|
||||
dispatcher.addTarget(target);
|
||||
dispatcher.send(new StringMessage("test"));
|
||||
assertEquals(3, messages.size());
|
||||
assertEquals(1, (int) messages.get(0).getHeaders().getSequenceNumber());
|
||||
assertEquals(3, (int) messages.get(0).getHeaders().getSequenceSize());
|
||||
assertEquals(2, (int) messages.get(1).getHeaders().getSequenceNumber());
|
||||
assertEquals(3, (int) messages.get(1).getHeaders().getSequenceSize());
|
||||
assertEquals(3, (int) messages.get(2).getHeaders().getSequenceNumber());
|
||||
assertEquals(3, (int) messages.get(2).getHeaders().getSequenceSize());
|
||||
}
|
||||
|
||||
|
||||
private void defaultTaskExecutorMock() {
|
||||
taskExecutorMock.execute(isA(Runnable.class));
|
||||
expectLastCall().andAnswer(new IAnswer<Object>() {
|
||||
|
||||
Reference in New Issue
Block a user