Created
December 19, 2014 09:51
-
-
Save ilayaperumalg/c2de7a987cd9f39c46e4 to your computer and use it in GitHub Desktop.
SynchronousDispatcherMessageHandlerTests fix (after changing the processor implmentation to send pojopong or stringpong
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<?xml version="1.0" encoding="UTF-8"?> | |
<beans xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" | |
xmlns:int="http://www.springframework.org/schema/integration" | |
xmlns="http://www.springframework.org/schema/beans" | |
xsi:schemaLocation="http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd | |
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd"> | |
<int:channel id="outputChannel1"> | |
<int:queue capacity="20"/> | |
</int:channel> | |
<int:channel id="outputChannel2"> | |
<int:queue capacity="20"/> | |
</int:channel> | |
<int:channel id="toMessageHandlerChannel"/> | |
<int:channel id="toStringHandlerChannel"/> | |
<bean id="messageProcessor" class="org.springframework.xd.reactor.PongMessageProcessor"/> | |
<bean name="reactorMessageHandler" class="org.springframework.xd.reactor.SynchronousDispatcherMessageHandler"> | |
<constructor-arg ref="messageProcessor"/> | |
</bean> | |
<int:service-activator input-channel="toMessageHandlerChannel" ref="reactorMessageHandler" | |
output-channel="outputChannel1"/> | |
<bean id="stringProcessor" class="org.springframework.xd.reactor.PongStringProcessor"/> | |
<bean name="reactorStringHandler" class="org.springframework.xd.reactor.SynchronousDispatcherMessageHandler"> | |
<constructor-arg ref="stringProcessor"/> | |
</bean> | |
<int:service-activator input-channel="toStringHandlerChannel" ref="reactorStringHandler" | |
output-channel="outputChannel2"/> | |
</beans> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* | |
* Copyright 2014 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.xd.reactor; | |
import static org.junit.Assert.*; | |
import java.io.IOException; | |
import javax.annotation.Resource; | |
import org.junit.Test; | |
import org.junit.runner.RunWith; | |
import org.springframework.beans.factory.annotation.Autowired; | |
import org.springframework.beans.factory.annotation.Qualifier; | |
import org.springframework.messaging.Message; | |
import org.springframework.messaging.MessageChannel; | |
import org.springframework.messaging.PollableChannel; | |
import org.springframework.messaging.support.GenericMessage; | |
import org.springframework.test.annotation.DirtiesContext; | |
import org.springframework.test.context.ContextConfiguration; | |
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner; | |
/** | |
* Test the {@link org.springframework.xd.reactor.SynchronousDispatcherMessageHandler} by using two types of | |
* {@link org.springframework.xd.reactor.Processor}. The first is parameterized by | |
* {@link org.springframework.messaging.Message} and the second by String to test extracting payload types and | |
* wrapping return types in a Message. | |
* | |
* @author Mark Pollack | |
*/ | |
@RunWith(SpringJUnit4ClassRunner.class) | |
@ContextConfiguration("/reactor.xml") | |
@DirtiesContext | |
public class SynchronousDispatcherMessageHandlerTests { | |
private final int numMessages = 10; | |
@Autowired | |
@Qualifier("outputChannel1") | |
PollableChannel outputChannel1; | |
@Autowired | |
@Qualifier("outputChannel2") | |
PollableChannel outputChannel2; | |
@Autowired | |
@Qualifier("toMessageHandlerChannel") | |
MessageChannel toMessageHandlerChannel; | |
@Autowired | |
@Qualifier("toStringHandlerChannel") | |
MessageChannel toStringHandlerChannel; | |
@Test | |
public void pojoBasedProcessor() throws IOException { | |
sendPojoMessages(); | |
for (int i = 0; i < numMessages; i++) { | |
Message<?> outputMessage = outputChannel1.receive(500); | |
assertEquals("ping-pojopong", outputMessage.getPayload()); | |
} | |
} | |
@Test | |
public void stringBasedProcessor() throws IOException { | |
sendStringMessages(); | |
for (int i = 0; i < numMessages; i++) { | |
Message<?> outputMessage = outputChannel2.receive(500); | |
assertEquals("ping-stringpong", outputMessage.getPayload()); | |
} | |
} | |
private void sendPojoMessages() { | |
Message<?> message = new GenericMessage<String>("ping"); | |
for (int i = 0; i < numMessages; i++) { | |
toMessageHandlerChannel.send(message); | |
} | |
} | |
private void sendStringMessages() { | |
Message<?> message = new GenericMessage<String>("ping"); | |
for (int i = 0; i < numMessages; i++) { | |
toStringHandlerChannel.send(message); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment