Skip to content

Commit

Permalink
Fixed the controller module test case to not append line-feed ("\n") …
Browse files Browse the repository at this point in the history
…at the end of the payload as having textline enabled that would cause 2 payloads going through the wire, in this case "<data><stuff/></data>" and the empty string "" afterwards. One can see the stack trace of the problem this causes while running this test on OS-X. See http://camel.apache.org/mina for more details about the "textline" and "textlineDelimiter" options. Also polished some more other stuff here & there.
  • Loading branch information
bvahdat committed May 21, 2013
1 parent 3df26d7 commit c7f06f9
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 6 deletions.
Expand Up @@ -31,7 +31,7 @@
<simple>&lt;data&gt;&lt;messageNumber&gt;${property.CamelTimerCounter}&lt;/messageNumber&gt;&lt;timestamp&gt;${date:now:kk:mm:ss.SS}&lt;/timestamp&gt;&lt;/data&gt;</simple>
</setBody>
<log message="Sending message ${property.CamelTimerCounter} with data: ${body}"/>
<to uri="mina:tcp://localhost:9000?textline=true&amp;sync=true"/>
<to uri="mina:tcp://0.0.0.0:9000?textline=true&amp;sync=true"/>
<log message="Received ${property.CamelTimerCounter} message: ${body}"/>
</route>
</camelContext>
Expand Down
Expand Up @@ -30,9 +30,9 @@ public class CamelContextXmlTest extends CamelSpringTestSupport {

@Test
public void testCamelRoute() throws Exception {
String body = "<data><stuff/></data>\n";
String body = "<data><stuff/></data>";

String response = inputEndpoint.requestBody("mina:tcp://localhost:9001?textline=true&sync=true", body, java.lang.String.class);
Object response = inputEndpoint.requestBody("mina:tcp://localhost:9001?textline=true&sync=true", body);

assertEquals("Incorrect Response", "<data><stuff/><controller>Controller 1</controller></data>", response);
}
Expand Down
Expand Up @@ -32,7 +32,7 @@ public class CamelContextXmlTest extends CamelSpringTestSupport {

@Test
public void testCamelRoute() throws Exception {
// Create routes from the output endpoints to our mock endpoints so we can assert expectations
// Create 2 routes consuming from the tcp ports the route "route1" (inside camel-context.xml) writes into
context.addRoutes(new RouteBuilder() {
@Override
public void configure() throws Exception {
Expand All @@ -54,13 +54,22 @@ public void configure() throws Exception {
final String expectedResponse1 = "<data><stuff/><controller>Controller 1</controller></data>";
final String expectedResponse2 = "<data><stuff/><controller>Controller 2</controller></data>";

String response = inputEndpoint.requestBody("mina:tcp://localhost:9000?textline=true&sync=true", request, String.class);
Object response = inputEndpoint.requestBody("mina:tcp://0.0.0.0:9000?textline=true&sync=true", request);

assertEquals("Incorrect response from controller 1", expectedResponse1, response);

context().stopRoute("controller1");

response = inputEndpoint.requestBody("mina:tcp://localhost:9000?textline=true&sync=true", request, String.class);
// in addition to stopping the route "controller1" let's remove it as well so that Camel graceful shutdown
// (when test is tearing down) doesn't try to unbind the port 9001 again which is actually not bound anymore
// (has already happened after the route stop). this could be confusing for the users:
// (java.lang.IllegalArgumentException: Address not bound: /0.0.0.0:9001)
context().removeRoute("controller1");

// after the execution of the following line we see a stacktrace of MinaProducer failing to get the Mina IoSession
// as the MinaConsumer of the route "controller1" is already gone. however as we've got a failover load balancer
// (inside camel-context.xml) the MinaConsumer of other route "controller2" will kick in
response = inputEndpoint.requestBody("mina:tcp://localhost:9000?textline=true&sync=true", request);

assertEquals("Incorrect response from controller 2", expectedResponse2, response);
}
Expand Down

0 comments on commit c7f06f9

Please sign in to comment.