You are viewing a plain text version of this content. The canonical link for it is here.
Posted to dev@camel.apache.org by "Claus Ibsen (JIRA)" <ji...@apache.org> on 2008/03/24 10:22:32 UTC

[jira] Created: (CAMEL-395) MinaProducer waits for MINA worker thread to timeout when stopping JVM from standalone client

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.


[jira] Work started: (CAMEL-395) MinaProducer waits for MINA worker thread to timeout when stopping JVM from standalone client

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-395?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Work on CAMEL-395 started by Claus Ibsen.

> 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
>            Assignee: Claus Ibsen
>             Fix For: 1.3.0
>
>         Attachments: camel-mina_patch_394_395.patch
>
>
> 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.


[jira] Closed: (CAMEL-395) MinaProducer waits for MINA worker thread to timeout when stopping JVM from standalone client

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-395?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen closed CAMEL-395.
-----------------------------

    Resolution: Fixed

Fixed in trunk

> 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
>            Assignee: Claus Ibsen
>             Fix For: 1.3.0
>
>         Attachments: camel-mina_patch_394_395.patch
>
>
> 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.


[jira] Updated: (CAMEL-395) MinaProducer waits for MINA worker thread to timeout when stopping JVM from standalone client

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-395?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen updated CAMEL-395:
------------------------------

    Attachment: camel-mina_patch_394_395.patch

This is a combined patch for CAMEL-394 and CAMEL-395 plus:
- refactored camel-mina 
- writing data using mina session.write will now wait for the operation to complete and check if the operation is a success. This is important to handle as we want the operation to complete before continuing our code.
- improved and polished some unit tests
- polished pom to use readable ident
- mvn exec:java to see the CAMEL-395 in action from java main
- better error reporting for mistyped uri configuration
- and whatnot I have done the last 7 or so days

> 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
>
>         Attachments: camel-mina_patch_394_395.patch
>
>
> 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.


[jira] Commented: (CAMEL-395) MinaProducer waits for MINA worker thread to timeout when stopping JVM from standalone client

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
    [ https://issues.apache.org/activemq/browse/CAMEL-395?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=41805#action_41805 ] 

Claus Ibsen commented on CAMEL-395:
-----------------------------------

Running mvn:exec java from this component will run a java main app that demonstrates that Camel is now able to shutdown MINA resources faster.

See the code in MinaProducer doStop that does the trick.

> 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
>            Assignee: Claus Ibsen
>             Fix For: 1.3.0
>
>         Attachments: camel-mina_patch_394_395.patch
>
>
> 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.


[jira] Assigned: (CAMEL-395) MinaProducer waits for MINA worker thread to timeout when stopping JVM from standalone client

Posted by "Claus Ibsen (JIRA)" <ji...@apache.org>.
     [ https://issues.apache.org/activemq/browse/CAMEL-395?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel ]

Claus Ibsen reassigned CAMEL-395:
---------------------------------

    Assignee: Claus Ibsen

> 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
>            Assignee: Claus Ibsen
>             Fix For: 1.3.0
>
>         Attachments: camel-mina_patch_394_395.patch
>
>
> 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.