MinaProducer waits for MINA worker thread to timeout when stopping JVM from
standalone client
---------------------------------------------------------------------------------------------
Key: CAMEL-395
URL: https://issues.apache.org/activemq/browse/CAMEL-395
Project: Apache Camel
Issue Type: Improvement
Components: camel-mina
Affects Versions: 1.3.0
Environment: Standalone client (not junit)
Reporter: Claus Ibsen
Fix For: 1.3.0
I was working on a camel-mina-example sample that starts a MinaProducer to send
data to a TCP server. When my sample terminates the JVM it waits 60 seconds
until the MINA worker threads times out (default 60 sec).
As a workaround using System.exit(0) will terminate my client JVM immediately.
And running my client as a JUnit tests will also in fact terminate the JVM
immediately.
The code below demonstrates this: Running as JUnit runs within a few seconds.
Run it as a standard java main app and it terminates after 60+ seconds
The code is a test I am working on for the patch to fix it. (I got it fixed but
I want a better unit test)
{code}
public class MinaProducerTest extends ContextTestSupport {
public static void main(String[] args) throws Exception {
MinaProducerTest test = new MinaProducerTest();
test.producerRunningFromMain();
}
private void producerRunningFromMain() throws Exception {
long start = System.currentTimeMillis();
System.out.println("+++ start +++");
context = new DefaultCamelContext();
context.addRoutes(createRouteBuilder());
context.start();
testProducer();
context.stop();
System.out.println("+++ stop +++");
long end = System.currentTimeMillis();
assertTrue("Should stop within 5 seconds", end - start < 5000);
// TODO: add shutdown hook to verify that its stopped before 5 seconds,
or mocks
}
private static final String uri = "mina:tcp://localhost:6321?textline=true";
protected RouteBuilder createRouteBuilder() {
return new RouteBuilder() {
public void configure() {
from(uri).to("mock:result");
}
};
}
public void testProducer() throws Exception {
MockEndpoint mock = getMockEndpoint("mock:result");
mock.expectedBodiesReceived("Hello World");
Endpoint endpoint = context.getEndpoint(uri);
Producer producer = endpoint.createProducer();
Exchange exchange = endpoint.createExchange();
exchange.getIn().setBody("Hello World");
producer.start();
producer.process(exchange);
producer.stop();
assertMockEndpointsSatisifed();
}
// TODO: Test using mocks requires many codelines to mock all the producer,
endpoints etc.
}
{code}
--
This message is automatically generated by JIRA.
-
You can reply to this email to add a comment to the issue online.