Added AbstractMessageConsumingEndpoint. MessageDispatchers now expect MessageConsumer instances as subscribers, and the MessageEndpoint no longer has a send() method or a getSource() method. All consumer endpoints now use 'inputChannel' as the property (instead of source). The MessageBus is less involved in endpoint activation now, since endpoints that need to poll a channel can create, configure, and schedule their own poller.
This commit is contained in:
@@ -34,7 +34,6 @@ import org.springframework.integration.channel.PublishSubscribeChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.AbstractInOutEndpoint;
|
||||
import org.springframework.integration.endpoint.InboundChannelAdapter;
|
||||
import org.springframework.integration.endpoint.SourcePoller;
|
||||
import org.springframework.integration.message.ErrorMessage;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
@@ -66,7 +65,7 @@ public class DefaultMessageBusTests {
|
||||
}
|
||||
};
|
||||
endpoint.setBeanName("testEndpoint");
|
||||
endpoint.setSource(sourceChannel);
|
||||
endpoint.setInputChannel(sourceChannel);
|
||||
bus.registerEndpoint(endpoint);
|
||||
bus.start();
|
||||
Message<?> result = targetChannel.receive(3000);
|
||||
@@ -126,10 +125,10 @@ public class DefaultMessageBusTests {
|
||||
bus.registerChannel(outputChannel1);
|
||||
bus.registerChannel(outputChannel2);
|
||||
endpoint1.setBeanName("testEndpoint1");
|
||||
endpoint1.setSource(inputChannel);
|
||||
endpoint1.setInputChannel(inputChannel);
|
||||
endpoint1.setOutputChannel(outputChannel1);
|
||||
endpoint2.setBeanName("testEndpoint2");
|
||||
endpoint2.setSource(inputChannel);
|
||||
endpoint2.setInputChannel(inputChannel);
|
||||
endpoint2.setOutputChannel(outputChannel2);
|
||||
bus.registerEndpoint(endpoint1);
|
||||
bus.registerEndpoint(endpoint2);
|
||||
@@ -169,10 +168,10 @@ public class DefaultMessageBusTests {
|
||||
bus.registerChannel(outputChannel1);
|
||||
bus.registerChannel(outputChannel2);
|
||||
endpoint1.setBeanName("testEndpoint1");
|
||||
endpoint1.setSource(inputChannel);
|
||||
endpoint1.setInputChannel(inputChannel);
|
||||
endpoint1.setOutputChannel(outputChannel1);
|
||||
endpoint2.setBeanName("testEndpoint2");
|
||||
endpoint2.setSource(inputChannel);
|
||||
endpoint2.setInputChannel(inputChannel);
|
||||
endpoint2.setOutputChannel(outputChannel2);
|
||||
bus.registerEndpoint(endpoint1);
|
||||
bus.registerEndpoint(endpoint2);
|
||||
@@ -191,18 +190,21 @@ public class DefaultMessageBusTests {
|
||||
public void testErrorChannelWithFailedDispatch() throws InterruptedException {
|
||||
MessageBus bus = new DefaultMessageBus();
|
||||
QueueChannel errorChannel = new QueueChannel();
|
||||
QueueChannel outputChannel = new QueueChannel();
|
||||
errorChannel.setBeanName("errorChannel");
|
||||
bus.registerChannel(errorChannel);
|
||||
CountDownLatch latch = new CountDownLatch(1);
|
||||
InboundChannelAdapter channelAdapter = new InboundChannelAdapter();
|
||||
SourcePoller poller = new SourcePoller(new FailingSource(latch), new PollingSchedule(1000));
|
||||
channelAdapter.setSource(poller);
|
||||
channelAdapter.setSource(new FailingSource(latch));
|
||||
channelAdapter.setSchedule(new PollingSchedule(1000));
|
||||
channelAdapter.setChannel(outputChannel);
|
||||
channelAdapter.setBeanName("testChannel");
|
||||
bus.registerEndpoint(channelAdapter);
|
||||
bus.start();
|
||||
latch.await(2000, TimeUnit.MILLISECONDS);
|
||||
Message<?> message = errorChannel.receive(5000);
|
||||
bus.stop();
|
||||
assertNull(outputChannel.receive(0));
|
||||
assertNotNull("message should not be null", message);
|
||||
assertTrue(message instanceof ErrorMessage);
|
||||
Throwable exception = ((ErrorMessage) message).getPayload();
|
||||
@@ -237,7 +239,7 @@ public class DefaultMessageBusTests {
|
||||
}
|
||||
};
|
||||
endpoint.setBeanName("testEndpoint");
|
||||
endpoint.setSource(errorChannel);
|
||||
endpoint.setInputChannel(errorChannel);
|
||||
bus.registerEndpoint(endpoint);
|
||||
bus.start();
|
||||
errorChannel.send(new ErrorMessage(new RuntimeException("test-exception")));
|
||||
|
||||
@@ -61,7 +61,7 @@ public class DirectChannelSubscriptionTests {
|
||||
public void testSendAndReceiveForRegisteredEndpoint() {
|
||||
MethodInvoker invoker = new MessageMappingMethodInvoker(new TestBean(), "handle");
|
||||
ServiceActivatorEndpoint endpoint = new ServiceActivatorEndpoint(invoker);
|
||||
endpoint.setSource(sourceChannel);
|
||||
endpoint.setInputChannel(sourceChannel);
|
||||
endpoint.setOutputChannel(targetChannel);
|
||||
endpoint.setBeanName("testEndpoint");
|
||||
bus.registerEndpoint(endpoint);
|
||||
@@ -95,7 +95,7 @@ public class DirectChannelSubscriptionTests {
|
||||
throw new RuntimeException("intentional test failure");
|
||||
}
|
||||
};
|
||||
endpoint.setSource(sourceChannel);
|
||||
endpoint.setInputChannel(sourceChannel);
|
||||
endpoint.setOutputChannel(targetChannel);
|
||||
endpoint.setBeanName("testEndpoint");
|
||||
bus.registerEndpoint(endpoint);
|
||||
|
||||
@@ -12,7 +12,7 @@
|
||||
|
||||
<bean id="endpoint" class="org.springframework.integration.endpoint.ServiceActivatorEndpoint">
|
||||
<constructor-arg ref="handler"/>
|
||||
<property name="source" ref="sourceChannel"/>
|
||||
<property name="inputChannel" ref="sourceChannel"/>
|
||||
<property name="outputChannel" ref="targetChannel"/>
|
||||
</bean>
|
||||
|
||||
|
||||
@@ -24,10 +24,8 @@ import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.MessageConsumer;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
@@ -62,7 +60,7 @@ public class DirectChannelTests {
|
||||
}
|
||||
|
||||
|
||||
private static class ThreadNameExtractingTestTarget implements MessageEndpoint {
|
||||
private static class ThreadNameExtractingTestTarget implements MessageConsumer {
|
||||
|
||||
private String threadName;
|
||||
|
||||
@@ -77,21 +75,11 @@ public class DirectChannelTests {
|
||||
this.latch = latch;
|
||||
}
|
||||
|
||||
public boolean send(Message<?> message) {
|
||||
public void onMessage(Message<?> message) {
|
||||
this.threadName = Thread.currentThread().getName();
|
||||
if (this.latch != null) {
|
||||
this.latch.countDown();
|
||||
}
|
||||
return true;
|
||||
}
|
||||
|
||||
// TODO: remove once this is a consumer instead of endpoint
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MessageSource<?> getSource() {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -19,8 +19,8 @@ package org.springframework.integration.channel.config;
|
||||
import java.util.List;
|
||||
import java.util.concurrent.CopyOnWriteArrayList;
|
||||
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageConsumer;
|
||||
import org.springframework.integration.message.SubscribableSource;
|
||||
|
||||
/**
|
||||
@@ -28,20 +28,20 @@ import org.springframework.integration.message.SubscribableSource;
|
||||
*/
|
||||
public class TestSubscribableSource implements SubscribableSource {
|
||||
|
||||
private final List<MessageEndpoint> endpoints = new CopyOnWriteArrayList<MessageEndpoint>();
|
||||
private final List<MessageConsumer> subscibers = new CopyOnWriteArrayList<MessageConsumer>();
|
||||
|
||||
|
||||
public boolean subscribe(MessageEndpoint endpoint) {
|
||||
return this.endpoints.add(endpoint);
|
||||
public boolean subscribe(MessageConsumer subsciber) {
|
||||
return this.subscibers.add(subsciber);
|
||||
}
|
||||
|
||||
public boolean unsubscribe(MessageEndpoint endpoint) {
|
||||
return this.endpoints.remove(endpoint);
|
||||
public boolean unsubscribe(MessageConsumer subsciber) {
|
||||
return this.subscibers.remove(subsciber);
|
||||
}
|
||||
|
||||
public void publishMessage(Message<?> message) {
|
||||
for (MessageEndpoint endpoint : this.endpoints) {
|
||||
endpoint.send(message);
|
||||
for (MessageConsumer subsciber : this.subscibers) {
|
||||
subsciber.onMessage(message);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -61,7 +61,7 @@ public class AggregatorParserTests {
|
||||
outboundMessages.add(createMessage("789", "id1", 3, 3, null));
|
||||
outboundMessages.add(createMessage("456", "id1", 3, 2, null));
|
||||
for (Message<?> message : outboundMessages) {
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
Assert.assertEquals("One and only one message must have been aggregated", 1, aggregatorBean
|
||||
.getAggregatedMessages().size());
|
||||
@@ -111,7 +111,7 @@ public class AggregatorParserTests {
|
||||
outboundMessages.add(createMessage(2l, "id1", 3, 3, null));
|
||||
outboundMessages.add(createMessage(3l, "id1", 3, 2, null));
|
||||
for (Message<?> message : outboundMessages) {
|
||||
addingAggregator.send(message);
|
||||
addingAggregator.onMessage(message);
|
||||
}
|
||||
PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
|
||||
Message<?> response = outputChannel.receive();
|
||||
@@ -140,13 +140,13 @@ public class AggregatorParserTests {
|
||||
MethodInvoker invoker = (MethodInvoker) completionStrategyAccessor.getPropertyValue("invoker");
|
||||
Assert.assertTrue(new DirectFieldAccessor(invoker).getPropertyValue("object") instanceof MaxValueCompletionStrategy);
|
||||
Assert.assertTrue(((Method)completionStrategyAccessor.getPropertyValue("method")).getName().equals("checkCompleteness"));
|
||||
aggregatorWithPojoCompletionStrategy.send(createMessage(1l, "id1", 0 , 0, null));
|
||||
aggregatorWithPojoCompletionStrategy.send(createMessage(2l, "id1", 0 , 0, null));
|
||||
aggregatorWithPojoCompletionStrategy.send(createMessage(3l, "id1", 0 , 0, null));
|
||||
aggregatorWithPojoCompletionStrategy.onMessage(createMessage(1l, "id1", 0 , 0, null));
|
||||
aggregatorWithPojoCompletionStrategy.onMessage(createMessage(2l, "id1", 0 , 0, null));
|
||||
aggregatorWithPojoCompletionStrategy.onMessage(createMessage(3l, "id1", 0 , 0, null));
|
||||
PollableChannel outputChannel = (PollableChannel) context.getBean("outputChannel");
|
||||
Message<?> reply = outputChannel.receive(0);
|
||||
Assert.assertNull(reply);
|
||||
aggregatorWithPojoCompletionStrategy.send(createMessage(5l, "id1", 0 , 0, null));
|
||||
aggregatorWithPojoCompletionStrategy.onMessage(createMessage(5l, "id1", 0 , 0, null));
|
||||
reply = outputChannel.receive(0);
|
||||
Assert.assertNotNull(reply);
|
||||
Assert.assertEquals(11l, reply.getPayload());
|
||||
|
||||
@@ -19,7 +19,6 @@ package org.springframework.integration.config;
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
import static org.junit.Assert.assertNull;
|
||||
import static org.junit.Assert.assertTrue;
|
||||
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
@@ -28,10 +27,10 @@ import org.junit.Test;
|
||||
import org.springframework.context.support.ClassPathXmlApplicationContext;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.GenericMessage;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageBuilder;
|
||||
import org.springframework.integration.message.MessageConsumer;
|
||||
import org.springframework.integration.message.MessageRejectedException;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
@@ -57,11 +56,11 @@ public class EndpointParserTests {
|
||||
public void testEndpointWithSelectorAccepts() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"endpointWithSelector.xml", this.getClass());
|
||||
MessageEndpoint endpoint = (MessageEndpoint) context.getBean("endpoint");
|
||||
MessageConsumer endpoint = (MessageConsumer) context.getBean("endpoint");
|
||||
QueueChannel replyChannel = new QueueChannel();
|
||||
Message<?> message = MessageBuilder.fromPayload("test")
|
||||
.setReturnAddress(replyChannel).build();
|
||||
assertTrue(endpoint.send(message));
|
||||
endpoint.onMessage(message);
|
||||
Message<?> reply = replyChannel.receive(500);
|
||||
assertNotNull(reply);
|
||||
assertEquals("foo", reply.getPayload());
|
||||
@@ -71,11 +70,11 @@ public class EndpointParserTests {
|
||||
public void testEndpointWithSelectorRejects() {
|
||||
ClassPathXmlApplicationContext context = new ClassPathXmlApplicationContext(
|
||||
"endpointWithSelector.xml", this.getClass());
|
||||
MessageEndpoint endpoint = (MessageEndpoint) context.getBean("endpoint");
|
||||
MessageConsumer endpoint = (MessageConsumer) context.getBean("endpoint");
|
||||
MessageChannel replyChannel = new QueueChannel();
|
||||
Message<?> message = MessageBuilder.fromPayload(123)
|
||||
.setReturnAddress(replyChannel).build();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
@@ -44,11 +44,11 @@ import org.springframework.integration.channel.DirectChannel;
|
||||
import org.springframework.integration.channel.MessageChannel;
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.channel.QueueChannel;
|
||||
import org.springframework.integration.endpoint.ChannelPoller;
|
||||
import org.springframework.integration.endpoint.ServiceActivatorEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.MessageConsumer;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.message.SubscribableSource;
|
||||
import org.springframework.integration.scheduling.PollingSchedule;
|
||||
import org.springframework.integration.scheduling.Schedule;
|
||||
import org.springframework.integration.util.MethodInvoker;
|
||||
@@ -295,10 +295,10 @@ public class MessagingAnnotationPostProcessorTests {
|
||||
AnnotatedEndpointWithPolledAnnotation endpoint = new AnnotatedEndpointWithPolledAnnotation();
|
||||
postProcessor.postProcessAfterInitialization(endpoint, "testBean");
|
||||
ServiceActivatorEndpoint processedEndpoint = (ServiceActivatorEndpoint) messageBus.lookupEndpoint("testBean.serviceActivator");
|
||||
processedEndpoint.afterPropertiesSet();
|
||||
DirectFieldAccessor accessor = new DirectFieldAccessor(processedEndpoint);
|
||||
MessageSource<?> source = (MessageSource<?>) accessor.getPropertyValue("source");
|
||||
assertTrue(source instanceof SubscribableSource);
|
||||
Schedule schedule = (Schedule) new DirectFieldAccessor(source).getPropertyValue("schedule");
|
||||
ChannelPoller poller = (ChannelPoller) accessor.getPropertyValue("poller");
|
||||
Schedule schedule = (Schedule) new DirectFieldAccessor(poller).getPropertyValue("schedule");
|
||||
assertEquals(PollingSchedule.class, schedule.getClass());
|
||||
PollingSchedule pollingSchedule = (PollingSchedule) schedule;
|
||||
assertEquals(1234, pollingSchedule.getPeriod());
|
||||
@@ -318,17 +318,10 @@ public class MessagingAnnotationPostProcessorTests {
|
||||
DirectChannel testChannel = (DirectChannel) messageBus.lookupChannel("testChannel");
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
final AtomicReference<Message<?>> receivedMessage = new AtomicReference<Message<?>>();
|
||||
testChannel.subscribe(new org.springframework.integration.endpoint.MessageEndpoint() {
|
||||
public boolean send(Message<?> message) {
|
||||
testChannel.subscribe(new MessageConsumer() {
|
||||
public void onMessage(Message<?> message) {
|
||||
receivedMessage.set(message);
|
||||
latch.countDown();
|
||||
return false;
|
||||
}
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
public MessageSource<?> getSource() {
|
||||
return null;
|
||||
}
|
||||
});
|
||||
latch.await(3, TimeUnit.SECONDS);
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.integration.dispatcher;
|
||||
|
||||
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;
|
||||
@@ -35,9 +34,8 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.core.task.TaskExecutor;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.MessageConsumer;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
|
||||
/**
|
||||
@@ -52,11 +50,11 @@ public class BroadcastingDispatcherTests {
|
||||
|
||||
private Message<?> messageMock = createMock(Message.class);
|
||||
|
||||
private MessageEndpoint targetMock1 = createMock(MessageEndpoint.class);
|
||||
private MessageConsumer targetMock1 = createMock(MessageConsumer.class);
|
||||
|
||||
private MessageEndpoint targetMock2 = createMock(MessageEndpoint.class);
|
||||
private MessageConsumer targetMock2 = createMock(MessageConsumer.class);
|
||||
|
||||
private MessageEndpoint targetMock3 = createMock(MessageEndpoint.class);
|
||||
private MessageConsumer targetMock3 = createMock(MessageConsumer.class);
|
||||
|
||||
private Object[] globalMocks = new Object[] {
|
||||
messageMock, taskExecutorMock, targetMock1, targetMock2, targetMock3 };
|
||||
@@ -75,7 +73,8 @@ public class BroadcastingDispatcherTests {
|
||||
public void singleTargetWithoutTaskExecutor() throws Exception {
|
||||
dispatcher.setTaskExecutor(null);
|
||||
dispatcher.subscribe(targetMock1);
|
||||
expect(targetMock1.send(messageMock)).andReturn(true);
|
||||
targetMock1.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
replay(globalMocks);
|
||||
dispatcher.dispatch(messageMock);
|
||||
verify(globalMocks);
|
||||
@@ -84,7 +83,8 @@ public class BroadcastingDispatcherTests {
|
||||
@Test
|
||||
public void singleTargetWithTaskExecutor() throws Exception {
|
||||
dispatcher.subscribe(targetMock1);
|
||||
expect(targetMock1.send(messageMock)).andReturn(true);
|
||||
targetMock1.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
replay(globalMocks);
|
||||
dispatcher.dispatch(messageMock);
|
||||
verify(globalMocks);
|
||||
@@ -96,9 +96,12 @@ public class BroadcastingDispatcherTests {
|
||||
dispatcher.subscribe(targetMock1);
|
||||
dispatcher.subscribe(targetMock2);
|
||||
dispatcher.subscribe(targetMock3);
|
||||
expect(targetMock1.send(messageMock)).andReturn(true);
|
||||
expect(targetMock2.send(messageMock)).andReturn(true);
|
||||
expect(targetMock3.send(messageMock)).andReturn(true);
|
||||
targetMock1.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
targetMock2.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
targetMock3.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
replay(globalMocks);
|
||||
dispatcher.dispatch(messageMock);
|
||||
verify(globalMocks);
|
||||
@@ -109,9 +112,12 @@ public class BroadcastingDispatcherTests {
|
||||
dispatcher.subscribe(targetMock1);
|
||||
dispatcher.subscribe(targetMock2);
|
||||
dispatcher.subscribe(targetMock3);
|
||||
expect(targetMock1.send(messageMock)).andReturn(true);
|
||||
expect(targetMock2.send(messageMock)).andReturn(true);
|
||||
expect(targetMock3.send(messageMock)).andReturn(true);
|
||||
targetMock1.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
targetMock2.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
targetMock3.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
replay(globalMocks);
|
||||
dispatcher.dispatch(messageMock);
|
||||
verify(globalMocks);
|
||||
@@ -124,8 +130,10 @@ public class BroadcastingDispatcherTests {
|
||||
dispatcher.subscribe(targetMock2);
|
||||
dispatcher.subscribe(targetMock3);
|
||||
partialFailingExecutorMock(false, true, true);
|
||||
expect(targetMock2.send(messageMock)).andReturn(true);
|
||||
expect(targetMock3.send(messageMock)).andReturn(true);
|
||||
targetMock2.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
targetMock3.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
replay(globalMocks);
|
||||
dispatcher.dispatch(messageMock);
|
||||
verify(globalMocks);
|
||||
@@ -138,8 +146,10 @@ public class BroadcastingDispatcherTests {
|
||||
dispatcher.subscribe(targetMock2);
|
||||
dispatcher.subscribe(targetMock3);
|
||||
partialFailingExecutorMock(true, false, true);
|
||||
expect(targetMock1.send(messageMock)).andReturn(true);
|
||||
expect(targetMock3.send(messageMock)).andReturn(true);
|
||||
targetMock1.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
targetMock3.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
replay(globalMocks);
|
||||
dispatcher.dispatch(messageMock);
|
||||
verify(globalMocks);
|
||||
@@ -152,8 +162,10 @@ public class BroadcastingDispatcherTests {
|
||||
dispatcher.subscribe(targetMock2);
|
||||
dispatcher.subscribe(targetMock3);
|
||||
partialFailingExecutorMock(true, true, false);
|
||||
expect(targetMock1.send(messageMock)).andReturn(true);
|
||||
expect(targetMock2.send(messageMock)).andReturn(true);
|
||||
targetMock1.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
targetMock2.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
replay(globalMocks);
|
||||
dispatcher.dispatch(messageMock);
|
||||
verify(globalMocks);
|
||||
@@ -176,7 +188,8 @@ public class BroadcastingDispatcherTests {
|
||||
dispatcher.subscribe(targetMock1);
|
||||
dispatcher.subscribe(targetMock1);
|
||||
dispatcher.subscribe(targetMock1);
|
||||
expect(targetMock1.send(messageMock)).andReturn(true);
|
||||
targetMock1.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
replay(globalMocks);
|
||||
dispatcher.dispatch(messageMock);
|
||||
verify(globalMocks);
|
||||
@@ -188,8 +201,10 @@ public class BroadcastingDispatcherTests {
|
||||
dispatcher.subscribe(targetMock2);
|
||||
dispatcher.subscribe(targetMock3);
|
||||
dispatcher.unsubscribe(targetMock2);
|
||||
expect(targetMock1.send(messageMock)).andReturn(true);
|
||||
expect(targetMock3.send(messageMock)).andReturn(true);
|
||||
targetMock1.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
targetMock3.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
replay(globalMocks);
|
||||
dispatcher.dispatch(messageMock);
|
||||
verify(globalMocks);
|
||||
@@ -200,9 +215,12 @@ public class BroadcastingDispatcherTests {
|
||||
dispatcher.subscribe(targetMock1);
|
||||
dispatcher.subscribe(targetMock2);
|
||||
dispatcher.subscribe(targetMock3);
|
||||
expect(targetMock1.send(messageMock)).andReturn(true).times(2);
|
||||
expect(targetMock2.send(messageMock)).andReturn(true);
|
||||
expect(targetMock3.send(messageMock)).andReturn(true).times(2);
|
||||
targetMock1.onMessage(messageMock);
|
||||
expectLastCall().times(2);
|
||||
targetMock2.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
targetMock3.onMessage(messageMock);
|
||||
expectLastCall().times(2);
|
||||
replay(globalMocks);
|
||||
dispatcher.dispatch(messageMock);
|
||||
dispatcher.unsubscribe(targetMock2);
|
||||
@@ -214,8 +232,8 @@ public class BroadcastingDispatcherTests {
|
||||
public void applySequenceDisabledByDefault() {
|
||||
BroadcastingDispatcher dispatcher = new BroadcastingDispatcher();
|
||||
final List<Message<?>> messages = Collections.synchronizedList(new ArrayList<Message<?>>());
|
||||
MessageEndpoint target1 = new MessageStoringTestEndpoint(messages);
|
||||
MessageEndpoint target2 = new MessageStoringTestEndpoint(messages);
|
||||
MessageConsumer target1 = new MessageStoringTestEndpoint(messages);
|
||||
MessageConsumer target2 = new MessageStoringTestEndpoint(messages);
|
||||
dispatcher.subscribe(target1);
|
||||
dispatcher.subscribe(target2);
|
||||
dispatcher.dispatch(new StringMessage("test"));
|
||||
@@ -231,9 +249,9 @@ public class BroadcastingDispatcherTests {
|
||||
BroadcastingDispatcher dispatcher = new BroadcastingDispatcher();
|
||||
dispatcher.setApplySequence(true);
|
||||
final List<Message<?>> messages = Collections.synchronizedList(new ArrayList<Message<?>>());
|
||||
MessageEndpoint target1 = new MessageStoringTestEndpoint(messages);
|
||||
MessageEndpoint target2 = new MessageStoringTestEndpoint(messages);
|
||||
MessageEndpoint target3 = new MessageStoringTestEndpoint(messages);
|
||||
MessageConsumer target1 = new MessageStoringTestEndpoint(messages);
|
||||
MessageConsumer target2 = new MessageStoringTestEndpoint(messages);
|
||||
MessageConsumer target3 = new MessageStoringTestEndpoint(messages);
|
||||
dispatcher.subscribe(target1);
|
||||
dispatcher.subscribe(target2);
|
||||
dispatcher.subscribe(target3);
|
||||
@@ -276,7 +294,7 @@ public class BroadcastingDispatcherTests {
|
||||
}
|
||||
|
||||
|
||||
private static class MessageStoringTestEndpoint implements MessageEndpoint {
|
||||
private static class MessageStoringTestEndpoint implements MessageConsumer {
|
||||
|
||||
private final List<Message<?>> messageList;
|
||||
|
||||
@@ -284,17 +302,8 @@ public class BroadcastingDispatcherTests {
|
||||
this.messageList = messageList;
|
||||
}
|
||||
|
||||
public boolean send(Message<?> message) {
|
||||
public void onMessage(Message<?> message) {
|
||||
this.messageList.add(message);
|
||||
return true;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MessageSource<?> getSource() {
|
||||
return null;
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
@@ -27,13 +27,12 @@ import java.util.concurrent.atomic.AtomicInteger;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.endpoint.AbstractInOutEndpoint;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.endpoint.ServiceActivatorEndpoint;
|
||||
import org.springframework.integration.handler.TestHandlers;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageConsumer;
|
||||
import org.springframework.integration.message.MessageDeliveryException;
|
||||
import org.springframework.integration.message.MessageRejectedException;
|
||||
import org.springframework.integration.message.MessageSource;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.message.selector.MessageSelector;
|
||||
|
||||
@@ -70,10 +69,15 @@ public class SimpleDispatcherTests {
|
||||
public void noDuplicateSubscriptions() {
|
||||
SimpleDispatcher dispatcher = new SimpleDispatcher();
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
MessageEndpoint target = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target = new CountingTestEndpoint(counter, false);
|
||||
dispatcher.subscribe(target);
|
||||
dispatcher.subscribe(target);
|
||||
dispatcher.dispatch(new StringMessage("test"));
|
||||
try {
|
||||
dispatcher.dispatch(new StringMessage("test"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
assertEquals("target should not have duplicate subscriptions", 1, counter.get());
|
||||
}
|
||||
|
||||
@@ -81,14 +85,19 @@ public class SimpleDispatcherTests {
|
||||
public void unsubscribeBeforeSend() {
|
||||
SimpleDispatcher dispatcher = new SimpleDispatcher();
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
MessageEndpoint target1 = new CountingTestEndpoint(counter, false);
|
||||
MessageEndpoint target2 = new CountingTestEndpoint(counter, false);
|
||||
MessageEndpoint target3 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target1 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target2 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target3 = new CountingTestEndpoint(counter, false);
|
||||
dispatcher.subscribe(target1);
|
||||
dispatcher.subscribe(target2);
|
||||
dispatcher.subscribe(target3);
|
||||
dispatcher.unsubscribe(target2);
|
||||
dispatcher.dispatch(new StringMessage("test"));
|
||||
try {
|
||||
dispatcher.dispatch(new StringMessage("test"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
assertEquals(2, counter.get());
|
||||
}
|
||||
|
||||
@@ -96,19 +105,34 @@ public class SimpleDispatcherTests {
|
||||
public void unsubscribeBetweenSends() {
|
||||
SimpleDispatcher dispatcher = new SimpleDispatcher();
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
MessageEndpoint target1 = new CountingTestEndpoint(counter, false);
|
||||
MessageEndpoint target2 = new CountingTestEndpoint(counter, false);
|
||||
MessageEndpoint target3 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target1 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target2 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target3 = new CountingTestEndpoint(counter, false);
|
||||
dispatcher.subscribe(target1);
|
||||
dispatcher.subscribe(target2);
|
||||
dispatcher.subscribe(target3);
|
||||
dispatcher.dispatch(new StringMessage("test1"));
|
||||
try {
|
||||
dispatcher.dispatch(new StringMessage("test1"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
assertEquals(3, counter.get());
|
||||
dispatcher.unsubscribe(target2);
|
||||
dispatcher.dispatch(new StringMessage("test2"));
|
||||
try {
|
||||
dispatcher.dispatch(new StringMessage("test2"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
assertEquals(5, counter.get());
|
||||
dispatcher.unsubscribe(target1);
|
||||
dispatcher.dispatch(new StringMessage("test3"));
|
||||
try {
|
||||
dispatcher.dispatch(new StringMessage("test3"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
assertEquals(6, counter.get());
|
||||
}
|
||||
|
||||
@@ -116,9 +140,14 @@ public class SimpleDispatcherTests {
|
||||
public void unsubscribeLastTargetCausesDeliveryException() {
|
||||
SimpleDispatcher dispatcher = new SimpleDispatcher();
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
MessageEndpoint target = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target = new CountingTestEndpoint(counter, false);
|
||||
dispatcher.subscribe(target);
|
||||
dispatcher.dispatch(new StringMessage("test1"));
|
||||
try {
|
||||
dispatcher.dispatch(new StringMessage("test1"));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
assertEquals(1, counter.get());
|
||||
dispatcher.unsubscribe(target);
|
||||
dispatcher.dispatch(new StringMessage("test2"));
|
||||
@@ -184,9 +213,9 @@ public class SimpleDispatcherTests {
|
||||
public void firstHandlerReturnsTrue() {
|
||||
SimpleDispatcher dispatcher = new SimpleDispatcher();
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
MessageEndpoint target1 = new CountingTestEndpoint(counter, true);
|
||||
MessageEndpoint target2 = new CountingTestEndpoint(counter, false);
|
||||
MessageEndpoint target3 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target1 = new CountingTestEndpoint(counter, true);
|
||||
MessageConsumer target2 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target3 = new CountingTestEndpoint(counter, false);
|
||||
dispatcher.subscribe(target1);
|
||||
dispatcher.subscribe(target2);
|
||||
dispatcher.subscribe(target3);
|
||||
@@ -198,9 +227,9 @@ public class SimpleDispatcherTests {
|
||||
public void middleHandlerReturnsTrue() {
|
||||
SimpleDispatcher dispatcher = new SimpleDispatcher();
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
MessageEndpoint target1 = new CountingTestEndpoint(counter, false);
|
||||
MessageEndpoint target2 = new CountingTestEndpoint(counter, true);
|
||||
MessageEndpoint target3 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target1 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target2 = new CountingTestEndpoint(counter, true);
|
||||
MessageConsumer target3 = new CountingTestEndpoint(counter, false);
|
||||
dispatcher.subscribe(target1);
|
||||
dispatcher.subscribe(target2);
|
||||
dispatcher.subscribe(target3);
|
||||
@@ -212,13 +241,18 @@ public class SimpleDispatcherTests {
|
||||
public void allHandlersReturnFalse() {
|
||||
SimpleDispatcher dispatcher = new SimpleDispatcher();
|
||||
final AtomicInteger counter = new AtomicInteger();
|
||||
MessageEndpoint target1 = new CountingTestEndpoint(counter, false);
|
||||
MessageEndpoint target2 = new CountingTestEndpoint(counter, false);
|
||||
MessageEndpoint target3 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target1 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target2 = new CountingTestEndpoint(counter, false);
|
||||
MessageConsumer target3 = new CountingTestEndpoint(counter, false);
|
||||
dispatcher.subscribe(target1);
|
||||
dispatcher.subscribe(target2);
|
||||
dispatcher.subscribe(target3);
|
||||
assertFalse(dispatcher.dispatch(new StringMessage("test")));
|
||||
try {
|
||||
assertFalse(dispatcher.dispatch(new StringMessage("test")));
|
||||
}
|
||||
catch (Exception e) {
|
||||
// ignore
|
||||
}
|
||||
assertEquals("each target should have been invoked", 3, counter.get());
|
||||
}
|
||||
|
||||
@@ -246,28 +280,22 @@ public class SimpleDispatcherTests {
|
||||
}
|
||||
|
||||
|
||||
private static class CountingTestEndpoint implements MessageEndpoint {
|
||||
private static class CountingTestEndpoint implements MessageConsumer {
|
||||
|
||||
private final AtomicInteger counter;
|
||||
|
||||
private final boolean returnValue;
|
||||
private final boolean shouldAccept;
|
||||
|
||||
CountingTestEndpoint(AtomicInteger counter, boolean returnValue) {
|
||||
CountingTestEndpoint(AtomicInteger counter, boolean shouldAccept) {
|
||||
this.counter = counter;
|
||||
this.returnValue = returnValue;
|
||||
this.shouldAccept = shouldAccept;
|
||||
}
|
||||
|
||||
public boolean send(Message<?> message) {
|
||||
public void onMessage(Message<?> message) {
|
||||
this.counter.incrementAndGet();
|
||||
return this.returnValue;
|
||||
}
|
||||
|
||||
public String getName() {
|
||||
return null;
|
||||
}
|
||||
|
||||
public MessageSource<?> getSource() {
|
||||
return null;
|
||||
if (!this.shouldAccept) {
|
||||
throw new MessageRejectedException(message, "intentional test failure");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -18,6 +18,7 @@ package org.springframework.integration.endpoint;
|
||||
|
||||
import static org.easymock.EasyMock.createMock;
|
||||
import static org.easymock.EasyMock.expect;
|
||||
import static org.easymock.EasyMock.expectLastCall;
|
||||
import static org.easymock.EasyMock.replay;
|
||||
import static org.easymock.EasyMock.reset;
|
||||
import static org.easymock.EasyMock.verify;
|
||||
@@ -26,9 +27,9 @@ import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.channel.PollableChannel;
|
||||
import org.springframework.integration.endpoint.ChannelPoller;
|
||||
import org.springframework.integration.endpoint.MessageEndpoint;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageConsumer;
|
||||
import org.springframework.integration.message.MessageRejectedException;
|
||||
import org.springframework.integration.scheduling.Schedule;
|
||||
|
||||
/**
|
||||
@@ -40,7 +41,7 @@ public class ChannelPollerTests {
|
||||
private ChannelPoller poller;
|
||||
private Schedule scheduleMock = createMock(Schedule.class);
|
||||
private PollableChannel channelMock = createMock(PollableChannel.class);
|
||||
private MessageEndpoint endpointMock = createMock(MessageEndpoint.class);
|
||||
private MessageConsumer endpointMock = createMock(MessageConsumer.class);
|
||||
private Message messageMock = createMock(Message.class);
|
||||
private Object[] globalMocks = new Object[] { scheduleMock, channelMock, endpointMock, messageMock };
|
||||
|
||||
@@ -57,7 +58,8 @@ public class ChannelPollerTests {
|
||||
@Test
|
||||
public void singleMessage() {
|
||||
expect(channelMock.receive()).andReturn(messageMock);
|
||||
expect(endpointMock.send(messageMock)).andReturn(true);
|
||||
endpointMock.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
replay(globalMocks);
|
||||
poller.setMaxMessagesPerPoll(1);
|
||||
poller.run();
|
||||
@@ -67,7 +69,8 @@ public class ChannelPollerTests {
|
||||
@Test
|
||||
public void multipleMessages() {
|
||||
expect(channelMock.receive()).andReturn(messageMock).times(5);
|
||||
expect(endpointMock.send(messageMock)).andReturn(true).times(5);
|
||||
endpointMock.onMessage(messageMock);
|
||||
expectLastCall().times(5);
|
||||
replay(globalMocks);
|
||||
poller.setMaxMessagesPerPoll(5);
|
||||
poller.run();
|
||||
@@ -78,26 +81,29 @@ public class ChannelPollerTests {
|
||||
public void multipleMessages_underrun() {
|
||||
expect(channelMock.receive()).andReturn(messageMock).times(5);
|
||||
expect(channelMock.receive()).andReturn(null);
|
||||
expect(endpointMock.send(messageMock)).andReturn(true).times(5);
|
||||
endpointMock.onMessage(messageMock);
|
||||
expectLastCall().times(5);
|
||||
replay(globalMocks);
|
||||
poller.setMaxMessagesPerPoll(6);
|
||||
poller.run();
|
||||
verify(globalMocks);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void droppedMessage() {
|
||||
@Test(expected = MessageRejectedException.class)
|
||||
public void rejectedMessage() {
|
||||
expect(channelMock.receive()).andReturn(messageMock);
|
||||
expect(endpointMock.send(messageMock)).andReturn(false);
|
||||
endpointMock.onMessage(messageMock);
|
||||
expectLastCall().andThrow(new MessageRejectedException(messageMock, "intentional test failure"));
|
||||
replay(globalMocks);
|
||||
poller.run();
|
||||
verify(globalMocks);
|
||||
}
|
||||
|
||||
@Test
|
||||
@Test(expected = MessageRejectedException.class)
|
||||
public void droppedMessage_onePerPoll() {
|
||||
expect(channelMock.receive()).andReturn(messageMock).times(1);
|
||||
expect(endpointMock.send(messageMock)).andReturn(false).anyTimes();
|
||||
endpointMock.onMessage(messageMock);
|
||||
expectLastCall().andThrow(new MessageRejectedException(messageMock, "intentional test failure")).anyTimes();
|
||||
replay(globalMocks);
|
||||
poller.setMaxMessagesPerPoll(10);
|
||||
poller.run();
|
||||
@@ -121,9 +127,11 @@ public class ChannelPollerTests {
|
||||
poller = new ChannelPoller(channelMock, scheduleMock);
|
||||
poller.subscribe(endpointMock);
|
||||
expect(channelMock.receive(1)).andReturn(messageMock);
|
||||
expect(endpointMock.send(messageMock)).andReturn(false);
|
||||
endpointMock.onMessage(messageMock);
|
||||
expectLastCall();
|
||||
replay(globalMocks);
|
||||
poller.setReceiveTimeout(1);
|
||||
poller.setMaxMessagesPerPoll(1);
|
||||
poller.run();
|
||||
verify(globalMocks);
|
||||
}
|
||||
|
||||
@@ -1,64 +0,0 @@
|
||||
/*
|
||||
* 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.endpoint;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
|
||||
import java.util.concurrent.CountDownLatch;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import org.junit.Test;
|
||||
|
||||
import org.springframework.integration.bus.DefaultMessageBus;
|
||||
import org.springframework.integration.message.Message;
|
||||
import org.springframework.integration.message.MessageTarget;
|
||||
import org.springframework.integration.message.PollableSource;
|
||||
import org.springframework.integration.message.StringMessage;
|
||||
import org.springframework.integration.scheduling.PollingSchedule;
|
||||
|
||||
/**
|
||||
* @author Mark Fisher
|
||||
*/
|
||||
public class MessagingBridgeTests {
|
||||
|
||||
@Test
|
||||
public void simplePassThrough() throws InterruptedException {
|
||||
final CountDownLatch latch = new CountDownLatch(1);
|
||||
DefaultMessageBus bus = new DefaultMessageBus();
|
||||
MessagingBridge bridge = new MessagingBridge(new MessageTarget() {
|
||||
public boolean send(Message<?> message) {
|
||||
latch.countDown();
|
||||
return true;
|
||||
}
|
||||
});
|
||||
bridge.setBeanName("bridge");
|
||||
PollableSource<String> source = new PollableSource<String>() {
|
||||
public Message<String> receive() {
|
||||
return new StringMessage("test");
|
||||
}
|
||||
};
|
||||
SourcePoller poller = new SourcePoller(source, new PollingSchedule(1000));
|
||||
poller.setMaxMessagesPerPoll(1);
|
||||
bridge.setSource(poller);
|
||||
bus.registerEndpoint(bridge);
|
||||
bus.start();
|
||||
latch.await(1, TimeUnit.SECONDS);
|
||||
bus.stop();
|
||||
assertEquals(0, latch.getCount());
|
||||
}
|
||||
|
||||
}
|
||||
@@ -54,7 +54,7 @@ public class ServiceActivatorEndpointTests {
|
||||
ServiceActivatorEndpoint endpoint = this.createEndpoint();
|
||||
endpoint.setOutputChannel(channel);
|
||||
Message<?> message = MessageBuilder.fromPayload("foo").build();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> reply = channel.receive(0);
|
||||
assertNotNull(reply);
|
||||
assertEquals("FOO", reply.getPayload());
|
||||
@@ -67,7 +67,7 @@ public class ServiceActivatorEndpointTests {
|
||||
ServiceActivatorEndpoint endpoint = this.createEndpoint();
|
||||
endpoint.setOutputChannel(channel1);
|
||||
Message<?> message = MessageBuilder.fromPayload("foo").setReturnAddress(channel2).build();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> reply1 = channel1.receive(0);
|
||||
assertNotNull(reply1);
|
||||
assertEquals("FOO", reply1.getPayload());
|
||||
@@ -80,7 +80,7 @@ public class ServiceActivatorEndpointTests {
|
||||
QueueChannel channel = new QueueChannel(1);
|
||||
ServiceActivatorEndpoint endpoint = this.createEndpoint();
|
||||
Message<?> message = MessageBuilder.fromPayload("foo").setReturnAddress(channel).build();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> reply = channel.receive(0);
|
||||
assertNotNull(reply);
|
||||
assertEquals("FOO", reply.getPayload());
|
||||
@@ -95,7 +95,7 @@ public class ServiceActivatorEndpointTests {
|
||||
ServiceActivatorEndpoint endpoint = this.createEndpoint();
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<?> message = MessageBuilder.fromPayload("foo").setReturnAddress("testChannel").build();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> reply = channel.receive(0);
|
||||
assertNotNull(reply);
|
||||
assertEquals("FOO", reply.getPayload());
|
||||
@@ -118,7 +118,7 @@ public class ServiceActivatorEndpointTests {
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> testMessage1 = MessageBuilder.fromPayload("bar")
|
||||
.setReturnAddress(replyChannel1).build();
|
||||
endpoint.send(testMessage1);
|
||||
endpoint.onMessage(testMessage1);
|
||||
Message<?> reply1 = replyChannel1.receive(50);
|
||||
assertNotNull(reply1);
|
||||
assertEquals("foobar", reply1.getPayload());
|
||||
@@ -126,7 +126,7 @@ public class ServiceActivatorEndpointTests {
|
||||
assertNull(reply2);
|
||||
Message<String> testMessage2 = MessageBuilder.fromMessage(testMessage1)
|
||||
.setReturnAddress("replyChannel2").build();
|
||||
endpoint.send(testMessage2);
|
||||
endpoint.onMessage(testMessage2);
|
||||
reply1 = replyChannel1.receive(0);
|
||||
assertNull(reply1);
|
||||
reply2 = replyChannel2.receive(0);
|
||||
@@ -139,7 +139,7 @@ public class ServiceActivatorEndpointTests {
|
||||
QueueChannel channel = new QueueChannel(1);
|
||||
ServiceActivatorEndpoint endpoint = this.createEndpoint();
|
||||
Message<?> message = MessageBuilder.fromPayload("foo").setReturnAddress(channel).build();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> reply = channel.receive(0);
|
||||
assertNotNull(reply);
|
||||
assertEquals("FOO", reply.getPayload());
|
||||
@@ -149,7 +149,7 @@ public class ServiceActivatorEndpointTests {
|
||||
public void noReplyTarget() {
|
||||
ServiceActivatorEndpoint endpoint = this.createEndpoint();
|
||||
Message<?> message = MessageBuilder.fromPayload("foo").build();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -159,7 +159,7 @@ public class ServiceActivatorEndpointTests {
|
||||
new TestNullReplyBean(), "handle");
|
||||
endpoint.setOutputChannel(channel);
|
||||
Message<?> message = MessageBuilder.fromPayload("foo").build();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
assertNull(channel.receive(0));
|
||||
}
|
||||
|
||||
@@ -171,7 +171,7 @@ public class ServiceActivatorEndpointTests {
|
||||
endpoint.setRequiresReply(true);
|
||||
endpoint.setOutputChannel(channel);
|
||||
Message<?> message = MessageBuilder.fromPayload("foo").build();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test(expected=MessageRejectedException.class)
|
||||
@@ -183,7 +183,7 @@ public class ServiceActivatorEndpointTests {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
endpoint.send(new StringMessage("test"));
|
||||
endpoint.onMessage(new StringMessage("test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -196,7 +196,7 @@ public class ServiceActivatorEndpointTests {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
endpoint.send(new StringMessage("test"));
|
||||
endpoint.onMessage(new StringMessage("test"));
|
||||
latch.await(100, TimeUnit.MILLISECONDS);
|
||||
assertEquals("handler should have been invoked", 0, latch.getCount());
|
||||
}
|
||||
@@ -222,7 +222,7 @@ public class ServiceActivatorEndpointTests {
|
||||
endpoint.setSelector(selectorChain);
|
||||
boolean exceptionWasThrown = false;
|
||||
try {
|
||||
endpoint.send(new StringMessage("test"));
|
||||
endpoint.onMessage(new StringMessage("test"));
|
||||
}
|
||||
catch (MessageRejectedException e) {
|
||||
exceptionWasThrown = true;
|
||||
@@ -253,7 +253,7 @@ public class ServiceActivatorEndpointTests {
|
||||
endpoint.setSelector(selectorChain);
|
||||
boolean exceptionWasThrown = false;
|
||||
try {
|
||||
endpoint.send(new StringMessage("test"));
|
||||
endpoint.onMessage(new StringMessage("test"));
|
||||
}
|
||||
catch (MessageRejectedException e) {
|
||||
exceptionWasThrown = true;
|
||||
@@ -282,7 +282,7 @@ public class ServiceActivatorEndpointTests {
|
||||
}
|
||||
});
|
||||
endpoint.setSelector(selectorChain);
|
||||
assertTrue(endpoint.send(new StringMessage("test")));
|
||||
endpoint.onMessage(new StringMessage("test"));
|
||||
assertEquals("both selectors and handler should have been invoked", 3, counter.get());
|
||||
}
|
||||
|
||||
@@ -297,7 +297,7 @@ public class ServiceActivatorEndpointTests {
|
||||
}, "handle");
|
||||
Message<String> message = MessageBuilder.fromPayload("test")
|
||||
.setReturnAddress(replyChannel).build();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> reply = replyChannel.receive(500);
|
||||
assertNull(reply.getHeaders().getCorrelationId());
|
||||
}
|
||||
@@ -313,7 +313,7 @@ public class ServiceActivatorEndpointTests {
|
||||
}, "handle");
|
||||
Message<String> message = MessageBuilder.fromPayload("test")
|
||||
.setReturnAddress(replyChannel).build();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> reply = replyChannel.receive(500);
|
||||
assertEquals(message.getHeaders().getId(), reply.getHeaders().getCorrelationId());
|
||||
}
|
||||
@@ -330,7 +330,7 @@ public class ServiceActivatorEndpointTests {
|
||||
}, "handle");
|
||||
Message<String> message = MessageBuilder.fromPayload("test")
|
||||
.setReturnAddress(replyChannel).build();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> reply = replyChannel.receive(500);
|
||||
Object correlationId = reply.getHeaders().getCorrelationId();
|
||||
assertFalse(message.getHeaders().getId().equals(correlationId));
|
||||
|
||||
@@ -44,9 +44,9 @@ public class CorrelationIdTests {
|
||||
DirectChannel inputChannel = new DirectChannel();
|
||||
QueueChannel outputChannel = new QueueChannel(1);
|
||||
ServiceActivatorEndpoint endpoint = new ServiceActivatorEndpoint(new TestBean(), "upperCase");
|
||||
endpoint.setSource(inputChannel);
|
||||
endpoint.setInputChannel(inputChannel);
|
||||
endpoint.setOutputChannel(outputChannel);
|
||||
endpoint.afterPropertiesSet();
|
||||
endpoint.start();
|
||||
assertTrue(inputChannel.send(message));
|
||||
Message<?> reply = outputChannel.receive(0);
|
||||
assertEquals(correlationId, reply.getHeaders().getCorrelationId());
|
||||
@@ -58,9 +58,9 @@ public class CorrelationIdTests {
|
||||
DirectChannel inputChannel = new DirectChannel();
|
||||
QueueChannel outputChannel = new QueueChannel(1);
|
||||
ServiceActivatorEndpoint endpoint = new ServiceActivatorEndpoint(new TestBean(), "upperCase");
|
||||
endpoint.setSource(inputChannel);
|
||||
endpoint.setInputChannel(inputChannel);
|
||||
endpoint.setOutputChannel(outputChannel);
|
||||
endpoint.afterPropertiesSet();
|
||||
endpoint.start();
|
||||
assertTrue(inputChannel.send(message));
|
||||
Message<?> reply = outputChannel.receive(0);
|
||||
assertEquals(message.getHeaders().getId(), reply.getHeaders().getCorrelationId());
|
||||
@@ -73,9 +73,9 @@ public class CorrelationIdTests {
|
||||
DirectChannel inputChannel = new DirectChannel();
|
||||
QueueChannel outputChannel = new QueueChannel(1);
|
||||
ServiceActivatorEndpoint endpoint = new ServiceActivatorEndpoint(new TestBean(), "upperCase");
|
||||
endpoint.setSource(inputChannel);
|
||||
endpoint.setInputChannel(inputChannel);
|
||||
endpoint.setOutputChannel(outputChannel);
|
||||
endpoint.afterPropertiesSet();
|
||||
endpoint.start();
|
||||
assertTrue(inputChannel.send(message));
|
||||
Message<?> reply = outputChannel.receive(0);
|
||||
assertEquals(message.getHeaders().getCorrelationId(), reply.getHeaders().getCorrelationId());
|
||||
@@ -90,9 +90,9 @@ public class CorrelationIdTests {
|
||||
DirectChannel inputChannel = new DirectChannel();
|
||||
QueueChannel outputChannel = new QueueChannel(1);
|
||||
ServiceActivatorEndpoint endpoint = new ServiceActivatorEndpoint(new TestBean(), "createMessage");
|
||||
endpoint.setSource(inputChannel);
|
||||
endpoint.setInputChannel(inputChannel);
|
||||
endpoint.setOutputChannel(outputChannel);
|
||||
endpoint.afterPropertiesSet();
|
||||
endpoint.start();
|
||||
assertTrue(inputChannel.send(message));
|
||||
Message<?> reply = outputChannel.receive(0);
|
||||
assertEquals("456-XYZ", reply.getHeaders().getCorrelationId());
|
||||
@@ -104,9 +104,9 @@ public class CorrelationIdTests {
|
||||
DirectChannel inputChannel = new DirectChannel();
|
||||
QueueChannel outputChannel = new QueueChannel(1);
|
||||
ServiceActivatorEndpoint endpoint = new ServiceActivatorEndpoint(new TestBean(), "createMessage");
|
||||
endpoint.setSource(inputChannel);
|
||||
endpoint.setInputChannel(inputChannel);
|
||||
endpoint.setOutputChannel(outputChannel);
|
||||
endpoint.afterPropertiesSet();
|
||||
endpoint.start();
|
||||
assertTrue(inputChannel.send(message));
|
||||
Message<?> reply = outputChannel.receive(0);
|
||||
assertEquals("456-XYZ", reply.getHeaders().getCorrelationId());
|
||||
@@ -121,7 +121,7 @@ public class CorrelationIdTests {
|
||||
SplitterEndpoint endpoint = new SplitterEndpoint(splitter);
|
||||
endpoint.setOutputChannel(testChannel);
|
||||
splitter.afterPropertiesSet();
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> reply1 = testChannel.receive(100);
|
||||
Message<?> reply2 = testChannel.receive(100);
|
||||
assertEquals(message.getHeaders().getId(), reply1.getHeaders().getCorrelationId());
|
||||
|
||||
@@ -64,9 +64,9 @@ public class MessageFilterTests {
|
||||
return true;
|
||||
}
|
||||
});
|
||||
filter.setSource(inputChannel);
|
||||
filter.setInputChannel(inputChannel);
|
||||
filter.setOutputChannel(outputChannel);
|
||||
filter.afterPropertiesSet();
|
||||
filter.start();
|
||||
Message<?> message = new StringMessage("test");
|
||||
assertTrue(inputChannel.send(message));
|
||||
Message<?> reply = outputChannel.receive(0);
|
||||
@@ -83,9 +83,9 @@ public class MessageFilterTests {
|
||||
return false;
|
||||
}
|
||||
});
|
||||
filter.setSource(inputChannel);
|
||||
filter.setInputChannel(inputChannel);
|
||||
filter.setOutputChannel(outputChannel);
|
||||
filter.afterPropertiesSet();
|
||||
filter.start();
|
||||
Message<?> message = new StringMessage("test");
|
||||
assertTrue(inputChannel.send(message));
|
||||
assertNull(outputChannel.receive(0));
|
||||
|
||||
@@ -91,7 +91,7 @@ public class MethodInvokingTargetTests {
|
||||
bus.registerChannel(channel);
|
||||
ServiceActivatorEndpoint endpoint = new ServiceActivatorEndpoint(target);
|
||||
endpoint.setBeanName("testEndpoint");
|
||||
endpoint.setSource(channel);
|
||||
endpoint.setInputChannel(channel);
|
||||
bus.registerEndpoint(endpoint);
|
||||
bus.start();
|
||||
String result = queue.poll(1000, TimeUnit.MILLISECONDS);
|
||||
|
||||
@@ -53,7 +53,7 @@ public class MessageExchangeTemplateTests {
|
||||
MessageBus bus = new DefaultMessageBus();
|
||||
bus.registerChannel(requestChannel);
|
||||
endpoint.setBeanName("testEndpoint");
|
||||
endpoint.setSource(requestChannel);
|
||||
endpoint.setInputChannel(requestChannel);
|
||||
bus.registerEndpoint(endpoint);
|
||||
bus.start();
|
||||
}
|
||||
|
||||
@@ -17,10 +17,8 @@
|
||||
package org.springframework.integration.router;
|
||||
|
||||
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 java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
@@ -57,7 +55,7 @@ public class MethodInvokingRouterTests {
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> message = new GenericMessage<String>("bar");
|
||||
assertTrue(endpoint.send(message));
|
||||
endpoint.onMessage(message);
|
||||
Message<?> replyMessage = barChannel.receive();
|
||||
assertNotNull(replyMessage);
|
||||
assertEquals(message, replyMessage);
|
||||
@@ -74,7 +72,7 @@ public class MethodInvokingRouterTests {
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> message = new GenericMessage<String>("bar");
|
||||
assertTrue(endpoint.send(message));
|
||||
endpoint.onMessage(message);
|
||||
Message<?> replyMessage = barChannel.receive();
|
||||
assertNotNull(replyMessage);
|
||||
assertEquals(message, replyMessage);
|
||||
@@ -96,7 +94,7 @@ public class MethodInvokingRouterTests {
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> message = MessageBuilder.fromPayload("bar")
|
||||
.setHeader("targetChannel", "foo").build();
|
||||
assertTrue(endpoint.send(message));
|
||||
endpoint.onMessage(message);
|
||||
Message<?> fooReply = fooChannel.receive(0);
|
||||
Message<?> barReply = barChannel.receive(0);
|
||||
assertNotNull(fooReply);
|
||||
@@ -110,7 +108,7 @@ public class MethodInvokingRouterTests {
|
||||
Method routingMethod = testBean.getClass().getMethod("routeByHeader", String.class);
|
||||
MethodInvokingChannelResolver resolver = new MethodInvokingChannelResolver(testBean, routingMethod);
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
endpoint.send(new GenericMessage<String>("testing"));
|
||||
endpoint.onMessage(new GenericMessage<String>("testing"));
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -142,15 +140,15 @@ public class MethodInvokingRouterTests {
|
||||
Message<String> fooMessage = new StringMessage("foo");
|
||||
Message<String> barMessage = new StringMessage("bar");
|
||||
Message<String> badMessage = new StringMessage("bad");
|
||||
assertTrue(endpoint.send(fooMessage));
|
||||
endpoint.onMessage(fooMessage);
|
||||
Message<?> result1 = fooChannel.receive(0);
|
||||
assertNotNull(result1);
|
||||
assertEquals("foo", result1.getPayload());
|
||||
assertTrue(endpoint.send(barMessage));
|
||||
endpoint.onMessage(barMessage);
|
||||
Message<?> result2 = barChannel.receive(0);
|
||||
assertNotNull(result2);
|
||||
assertEquals("bar", result2.getPayload());
|
||||
assertFalse(endpoint.send(badMessage));
|
||||
endpoint.onMessage(badMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -183,15 +181,15 @@ public class MethodInvokingRouterTests {
|
||||
channelRegistry.registerChannel(fooChannel);
|
||||
channelRegistry.registerChannel(barChannel);
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
assertTrue(endpoint.send(fooMessage));
|
||||
endpoint.onMessage(fooMessage);
|
||||
Message<?> result1 = fooChannel.receive(0);
|
||||
assertNotNull(result1);
|
||||
assertEquals("foo", result1.getPayload());
|
||||
assertTrue(endpoint.send(barMessage));
|
||||
endpoint.onMessage(barMessage);
|
||||
Message<?> result2 = barChannel.receive(0);
|
||||
assertNotNull(result2);
|
||||
assertEquals("bar", result2.getPayload());
|
||||
assertFalse(endpoint.send(badMessage));
|
||||
endpoint.onMessage(badMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -224,15 +222,15 @@ public class MethodInvokingRouterTests {
|
||||
Message<String> fooMessage = new StringMessage("foo");
|
||||
Message<String> barMessage = new StringMessage("bar");
|
||||
Message<String> badMessage = new StringMessage("bad");
|
||||
assertTrue(endpoint.send(fooMessage));
|
||||
endpoint.onMessage(fooMessage);
|
||||
Message<?> result1 = fooChannel.receive(0);
|
||||
assertNotNull(result1);
|
||||
assertEquals("foo", result1.getPayload());
|
||||
assertTrue(endpoint.send(barMessage));
|
||||
endpoint.onMessage(barMessage);
|
||||
Message<?> result2 = barChannel.receive(0);
|
||||
assertNotNull(result2);
|
||||
assertEquals("bar", result2.getPayload());
|
||||
assertFalse(endpoint.send(badMessage));
|
||||
endpoint.onMessage(badMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -265,21 +263,21 @@ public class MethodInvokingRouterTests {
|
||||
Message<String> fooMessage = new StringMessage("foo");
|
||||
Message<String> barMessage = new StringMessage("bar");
|
||||
Message<String> badMessage = new StringMessage("bad");
|
||||
assertTrue(endpoint.send(fooMessage));
|
||||
endpoint.onMessage(fooMessage);
|
||||
Message<?> result1a = fooChannel.receive(0);
|
||||
Message<?> result1b = barChannel.receive(0);
|
||||
assertNotNull(result1a);
|
||||
assertEquals("foo", result1a.getPayload());
|
||||
assertNotNull(result1b);
|
||||
assertEquals("foo", result1b.getPayload());
|
||||
assertTrue(endpoint.send(barMessage));
|
||||
endpoint.onMessage(barMessage);
|
||||
Message<?> result2a = fooChannel.receive(0);
|
||||
Message<?> result2b = barChannel.receive(0);
|
||||
assertNotNull(result2a);
|
||||
assertEquals("bar", result2a.getPayload());
|
||||
assertNotNull(result2b);
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
assertFalse(endpoint.send(badMessage));
|
||||
endpoint.onMessage(badMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -312,21 +310,21 @@ public class MethodInvokingRouterTests {
|
||||
Message<String> fooMessage = new StringMessage("foo");
|
||||
Message<String> barMessage = new StringMessage("bar");
|
||||
Message<String> badMessage = new StringMessage("bad");
|
||||
assertTrue(endpoint.send(fooMessage));
|
||||
endpoint.onMessage(fooMessage);
|
||||
Message<?> result1a = fooChannel.receive(0);
|
||||
assertNotNull(result1a);
|
||||
assertEquals("foo", result1a.getPayload());
|
||||
Message<?> result1b = barChannel.receive(0);
|
||||
assertNotNull(result1b);
|
||||
assertEquals("foo", result1b.getPayload());
|
||||
assertTrue(endpoint.send(barMessage));
|
||||
endpoint.onMessage(barMessage);
|
||||
Message<?> result2a = fooChannel.receive(0);
|
||||
assertNotNull(result2a);
|
||||
assertEquals("bar", result2a.getPayload());
|
||||
Message<?> result2b = barChannel.receive(0);
|
||||
assertNotNull(result2b);
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
assertFalse(endpoint.send(badMessage));
|
||||
endpoint.onMessage(badMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -359,21 +357,21 @@ public class MethodInvokingRouterTests {
|
||||
Message<String> fooMessage = new StringMessage("foo");
|
||||
Message<String> barMessage = new StringMessage("bar");
|
||||
Message<String> badMessage = new StringMessage("bad");
|
||||
assertTrue(endpoint.send(fooMessage));
|
||||
endpoint.onMessage(fooMessage);
|
||||
Message<?> result1a = fooChannel.receive(0);
|
||||
assertNotNull(result1a);
|
||||
assertEquals("foo", result1a.getPayload());
|
||||
Message<?> result1b = barChannel.receive(0);
|
||||
assertNotNull(result1b);
|
||||
assertEquals("foo", result1b.getPayload());
|
||||
assertTrue(endpoint.send(barMessage));
|
||||
endpoint.onMessage(barMessage);
|
||||
Message<?> result2a = fooChannel.receive(0);
|
||||
assertNotNull(result2a);
|
||||
assertEquals("bar", result2a.getPayload());
|
||||
Message<?> result2b = barChannel.receive(0);
|
||||
assertNotNull(result2b);
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
assertFalse(endpoint.send(badMessage));
|
||||
endpoint.onMessage(badMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -406,21 +404,21 @@ public class MethodInvokingRouterTests {
|
||||
Message<String> fooMessage = new StringMessage("foo");
|
||||
Message<String> barMessage = new StringMessage("bar");
|
||||
Message<String> badMessage = new StringMessage("bad");
|
||||
assertTrue(endpoint.send(fooMessage));
|
||||
endpoint.onMessage(fooMessage);
|
||||
Message<?> result1a = fooChannel.receive(0);
|
||||
Message<?> result1b = barChannel.receive(0);
|
||||
assertNotNull(result1a);
|
||||
assertEquals("foo", result1a.getPayload());
|
||||
assertNotNull(result1b);
|
||||
assertEquals("foo", result1b.getPayload());
|
||||
assertTrue(endpoint.send(barMessage));
|
||||
endpoint.onMessage(barMessage);
|
||||
Message<?> result2a = fooChannel.receive(0);
|
||||
Message<?> result2b = barChannel.receive(0);
|
||||
assertNotNull(result2a);
|
||||
assertEquals("bar", result2a.getPayload());
|
||||
assertNotNull(result2b);
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
assertFalse(endpoint.send(badMessage));
|
||||
endpoint.onMessage(badMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -453,21 +451,21 @@ public class MethodInvokingRouterTests {
|
||||
Message<String> fooMessage = new StringMessage("foo");
|
||||
Message<String> barMessage = new StringMessage("bar");
|
||||
Message<String> badMessage = new StringMessage("bad");
|
||||
assertTrue(endpoint.send(fooMessage));
|
||||
endpoint.onMessage(fooMessage);
|
||||
Message<?> result1a = fooChannel.receive(0);
|
||||
Message<?> result1b = barChannel.receive(0);
|
||||
assertNotNull(result1a);
|
||||
assertEquals("foo", result1a.getPayload());
|
||||
assertNotNull(result1b);
|
||||
assertEquals("foo", result1b.getPayload());
|
||||
assertTrue(endpoint.send(barMessage));
|
||||
endpoint.onMessage(barMessage);
|
||||
Message<?> result2a = fooChannel.receive(0);
|
||||
Message<?> result2b = barChannel.receive(0);
|
||||
assertNotNull(result2a);
|
||||
assertEquals("bar", result2a.getPayload());
|
||||
assertNotNull(result2b);
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
assertFalse(endpoint.send(badMessage));
|
||||
endpoint.onMessage(badMessage);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -500,21 +498,21 @@ public class MethodInvokingRouterTests {
|
||||
Message<String> fooMessage = new StringMessage("foo");
|
||||
Message<String> barMessage = new StringMessage("bar");
|
||||
Message<String> badMessage = new StringMessage("bad");
|
||||
assertTrue(endpoint.send(fooMessage));
|
||||
endpoint.onMessage(fooMessage);
|
||||
Message<?> result1a = fooChannel.receive(0);
|
||||
Message<?> result1b = barChannel.receive(0);
|
||||
assertNotNull(result1a);
|
||||
assertEquals("foo", result1a.getPayload());
|
||||
assertNotNull(result1b);
|
||||
assertEquals("foo", result1b.getPayload());
|
||||
assertTrue(endpoint.send(barMessage));
|
||||
endpoint.onMessage(barMessage);
|
||||
Message<?> result2a = fooChannel.receive(0);
|
||||
Message<?> result2b = barChannel.receive(0);
|
||||
assertNotNull(result2a);
|
||||
assertEquals("bar", result2a.getPayload());
|
||||
assertNotNull(result2b);
|
||||
assertEquals("bar", result2b.getPayload());
|
||||
assertFalse(endpoint.send(badMessage));
|
||||
endpoint.onMessage(badMessage);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -51,7 +51,7 @@ public class MultiChannelRouterTests {
|
||||
};
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelResolver);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> result1 = channel1.receive(25);
|
||||
assertNotNull(result1);
|
||||
assertEquals("test", result1.getPayload());
|
||||
@@ -77,7 +77,7 @@ public class MultiChannelRouterTests {
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelNameResolver);
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> result1 = channel1.receive(25);
|
||||
assertNotNull(result1);
|
||||
assertEquals("test", result1.getPayload());
|
||||
@@ -97,7 +97,7 @@ public class MultiChannelRouterTests {
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelNameResolver);
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
@@ -109,7 +109,7 @@ public class MultiChannelRouterTests {
|
||||
};
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelNameResolver);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -71,8 +71,8 @@ public class PayloadTypeRouterTests {
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> message1 = new StringMessage("test");
|
||||
Message<Integer> message2 = new GenericMessage<Integer>(123);
|
||||
endpoint.send(message1);
|
||||
endpoint.send(message2);
|
||||
endpoint.onMessage(message1);
|
||||
endpoint.onMessage(message2);
|
||||
Message<?> reply1 = stringChannel.receive(0);
|
||||
Message<?> reply2 = integerChannel.receive(0);
|
||||
assertEquals("test", reply1.getPayload());
|
||||
@@ -96,8 +96,8 @@ public class PayloadTypeRouterTests {
|
||||
endpoint.setDefaultOutputChannel(defaultChannel);
|
||||
Message<String> message1 = new StringMessage("test");
|
||||
Message<Integer> message2 = new GenericMessage<Integer>(123);
|
||||
endpoint.send(message1);
|
||||
endpoint.send(message2);
|
||||
endpoint.onMessage(message1);
|
||||
endpoint.onMessage(message2);
|
||||
Message<?> result1 = stringChannel.receive(25);
|
||||
assertNotNull(result1);
|
||||
assertEquals("test", result1.getPayload());
|
||||
|
||||
@@ -69,7 +69,7 @@ public class RecipientListRouterTests {
|
||||
resolver.afterPropertiesSet();
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> result1 = channel1.receive(25);
|
||||
assertNotNull(result1);
|
||||
assertEquals("test", result1.getPayload());
|
||||
@@ -93,7 +93,7 @@ public class RecipientListRouterTests {
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> result1 = channel1.receive(25);
|
||||
assertNotNull(result1);
|
||||
assertEquals("test", result1.getPayload());
|
||||
@@ -117,7 +117,7 @@ public class RecipientListRouterTests {
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> result1 = channel1.receive(25);
|
||||
assertNotNull(result1);
|
||||
assertEquals("test", result1.getPayload());
|
||||
|
||||
@@ -65,7 +65,7 @@ public class RootCauseErrorMessageRouterTests {
|
||||
resolver.setChannelMappings(channelMappings);
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
endpoint.setDefaultOutputChannel(defaultChannel);
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
assertNotNull(illegalArgumentChannel.receive(1000));
|
||||
assertNull(defaultChannel.receive(0));
|
||||
assertNull(runtimeExceptionChannel.receive(0));
|
||||
@@ -87,7 +87,7 @@ public class RootCauseErrorMessageRouterTests {
|
||||
resolver.setChannelMappings(channelMappings);
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
endpoint.setDefaultOutputChannel(defaultChannel);
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
assertNotNull(runtimeExceptionChannel.receive(1000));
|
||||
assertNull(illegalArgumentChannel.receive(0));
|
||||
assertNull(defaultChannel.receive(0));
|
||||
@@ -108,7 +108,7 @@ public class RootCauseErrorMessageRouterTests {
|
||||
resolver.setChannelMappings(channelMappings);
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
endpoint.setDefaultOutputChannel(defaultChannel);
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
assertNotNull(messageHandlingExceptionChannel.receive(1000));
|
||||
assertNull(runtimeExceptionChannel.receive(0));
|
||||
assertNull(illegalArgumentChannel.receive(0));
|
||||
@@ -125,7 +125,7 @@ public class RootCauseErrorMessageRouterTests {
|
||||
RootCauseErrorMessageChannelResolver resolver = new RootCauseErrorMessageChannelResolver();
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
endpoint.setDefaultOutputChannel(defaultChannel);
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
assertNotNull(defaultChannel.receive(1000));
|
||||
assertNull(runtimeExceptionChannel.receive(0));
|
||||
assertNull(illegalArgumentChannel.receive(0));
|
||||
@@ -146,7 +146,7 @@ public class RootCauseErrorMessageRouterTests {
|
||||
resolver.setChannelMappings(channelMappings);
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
endpoint.setResolutionRequired(true);
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -165,7 +165,7 @@ public class RootCauseErrorMessageRouterTests {
|
||||
resolver.setChannelMappings(channelMappings);
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
endpoint.setDefaultOutputChannel(defaultChannel);
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
assertNotNull(illegalArgumentChannel.receive(1000));
|
||||
assertNull(defaultChannel.receive(0));
|
||||
assertNull(runtimeExceptionChannel.receive(0));
|
||||
@@ -187,7 +187,7 @@ public class RootCauseErrorMessageRouterTests {
|
||||
resolver.setChannelMappings(channelMappings);
|
||||
RouterEndpoint endpoint = new RouterEndpoint(resolver);
|
||||
endpoint.setDefaultOutputChannel(defaultChannel);
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
assertNotNull(illegalArgumentChannel.receive(1000));
|
||||
assertNull(defaultChannel.receive(0));
|
||||
assertNull(runtimeExceptionChannel.receive(0));
|
||||
|
||||
@@ -16,8 +16,6 @@
|
||||
|
||||
package org.springframework.integration.router;
|
||||
|
||||
import static org.junit.Assert.assertFalse;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
@@ -45,7 +43,7 @@ public class RouterEndpointTests {
|
||||
};
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelResolver);
|
||||
Message<String> message = new StringMessage("test");
|
||||
assertFalse(endpoint.send(message));
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
@@ -58,7 +56,7 @@ public class RouterEndpointTests {
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelResolver);
|
||||
endpoint.setResolutionRequired(true);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -70,7 +68,7 @@ public class RouterEndpointTests {
|
||||
};
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelResolver);
|
||||
Message<String> message = new StringMessage("test");
|
||||
assertFalse(endpoint.send(message));
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
@@ -83,7 +81,7 @@ public class RouterEndpointTests {
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelResolver);
|
||||
endpoint.setResolutionRequired(true);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test
|
||||
@@ -97,7 +95,7 @@ public class RouterEndpointTests {
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelNameResolver);
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> message = new StringMessage("test");
|
||||
assertFalse(endpoint.send(message));
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
@@ -112,7 +110,7 @@ public class RouterEndpointTests {
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
endpoint.setResolutionRequired(true);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
|
||||
@@ -127,7 +125,7 @@ public class RouterEndpointTests {
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelNameResolver);
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> message = new StringMessage("test");
|
||||
assertFalse(endpoint.send(message));
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test(expected = MessageDeliveryException.class)
|
||||
@@ -142,7 +140,7 @@ public class RouterEndpointTests {
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
endpoint.setResolutionRequired(true);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
@@ -153,7 +151,7 @@ public class RouterEndpointTests {
|
||||
}
|
||||
};
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelNameResolver);
|
||||
endpoint.send(new StringMessage("this should fail"));
|
||||
endpoint.onMessage(new StringMessage("this should fail"));
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
@@ -164,7 +162,7 @@ public class RouterEndpointTests {
|
||||
}
|
||||
};
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelNameResolver);
|
||||
endpoint.send(new StringMessage("this should fail"));
|
||||
endpoint.onMessage(new StringMessage("this should fail"));
|
||||
}
|
||||
|
||||
@Test(expected = IllegalArgumentException.class)
|
||||
|
||||
@@ -17,7 +17,6 @@
|
||||
package org.springframework.integration.router;
|
||||
|
||||
import static org.junit.Assert.assertEquals;
|
||||
import static org.junit.Assert.assertFalse;
|
||||
import static org.junit.Assert.assertNotNull;
|
||||
|
||||
import org.junit.Test;
|
||||
@@ -45,7 +44,7 @@ public class SingleChannelRouterTests {
|
||||
};
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelResolver);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> result = channel.receive(25);
|
||||
assertNotNull(result);
|
||||
assertEquals("test", result.getPayload());
|
||||
@@ -65,14 +64,14 @@ public class SingleChannelRouterTests {
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelNameResolver);
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
Message<?> result = channel.receive(25);
|
||||
assertNotNull(result);
|
||||
assertEquals("test", result.getPayload());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void nullChannelResult() {
|
||||
public void nullChannelResultIgnored() {
|
||||
AbstractSingleChannelResolver channelResolver = new AbstractSingleChannelResolver() {
|
||||
public MessageChannel resolveChannel(Message<?> message) {
|
||||
return null;
|
||||
@@ -80,7 +79,7 @@ public class SingleChannelRouterTests {
|
||||
};
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelResolver);
|
||||
Message<String> message = new StringMessage("test");
|
||||
assertFalse(endpoint.send(message));
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
@Test(expected = MessagingException.class)
|
||||
@@ -94,7 +93,7 @@ public class SingleChannelRouterTests {
|
||||
RouterEndpoint endpoint = new RouterEndpoint(channelNameResolver);
|
||||
endpoint.setChannelRegistry(channelRegistry);
|
||||
Message<String> message = new StringMessage("test");
|
||||
endpoint.send(message);
|
||||
endpoint.onMessage(message);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user