You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Charles Moulliard <ch...@gmail.com> on 2012/08/29 18:25:26 UTC

Issue using camel + cxf in an unit test

Hi,

I have a unit test issue with camel (2.7.1) and cxf. One camel test class
(extending CamelSpringTestSupport) contain 2 unit tests where we call a web
service exposed by a camel route using a CamelProducerTemplate. Tests
executed individually pass well but If I would like to execute both tests,
I get an exception that the jetty server of CXF cannot respond on the
socket. I have tried to add @DirtiesContext for each individual unit test
(to force Spring to create a new CamelContext) but that does not help. It
seems that when the second test is executed by Junit/Spring, it tries to
call the Jetty server created during execution of the first test.

Any idea is welcome ?

Regards,
-- 
Charles Moulliard
Apache Committer / Sr. Pr. Consultant at FuseSource.com
Twitter : @cmoulliard
Blog : http://cmoulliard.blogspot.com

Re: Issue using camel + cxf in an unit test

Posted by Charles Moulliard <ch...@gmail.com>.
Hi Daniel,

Many thanks for the feedback. I will make some tests with what you suggest.
Is there a ticket created to improve in the feature this issue ? Is it
related this one (https://issues.apache.org/jira/browse/CXF-2775) ?

Regards,

Charles

On Wed, Aug 29, 2012 at 10:01 PM, Daniel Kulp <dk...@apache.org> wrote:

>
> It's a semi-Jetty issue.   If you use Keep-Alive connections (the
> default), Jetty has issues shutting down the port for some reason.   It
> holds the port in some sort of strange semi-open state that accepts
> connections but doesn't properly process things.   Never really had time to
> investigate any potential workarounds or fixes.
>
> Couple of solutions:
> 1) Turn off the keep-alives in the connections
>
> 2)  Put  a "Thread.sleep(60000)" between the tests.  (might just be 10000)
> to wait for the keep-alive to timeout.   Yea, not recommended, but thought
> I'd mention it.  :-)
>
> 3) Set the System property:
> "org.apache.cxf.transports.http_jetty.DontClosePort." + port
> (port is the port number you are using) to true.
>
> which tells CXF to just keep the port open and not make any attempt to
> close it.   Thus, when the second server starts up, it just registers on
> the already running instance.   This is what we do for all the Camel and
> CXF unit/system tests.
>
>
> Dan
>
>
>
>
> On Aug 29, 2012, at 12:25 PM, Charles Moulliard <ch...@gmail.com> wrote:
>
> > Hi,
> >
> > I have a unit test issue with camel (2.7.1) and cxf. One camel test class
> > (extending CamelSpringTestSupport) contain 2 unit tests where we call a
> web
> > service exposed by a camel route using a CamelProducerTemplate. Tests
> > executed individually pass well but If I would like to execute both
> tests,
> > I get an exception that the jetty server of CXF cannot respond on the
> > socket. I have tried to add @DirtiesContext for each individual unit test
> > (to force Spring to create a new CamelContext) but that does not help. It
> > seems that when the second test is executed by Junit/Spring, it tries to
> > call the Jetty server created during execution of the first test.
> >
> > Any idea is welcome ?
> >
> > Regards,
> > --
> > Charles Moulliard
> > Apache Committer / Sr. Pr. Consultant at FuseSource.com
> > Twitter : @cmoulliard
> > Blog : http://cmoulliard.blogspot.com
>
> --
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
>


-- 
Charles Moulliard
Apache Committer / Sr. Pr. Consultant at FuseSource.com
Twitter : @cmoulliard
Blog : http://cmoulliard.blogspot.com

Re: Issue using camel + cxf in an unit test

Posted by "Preben.Asmussen" <pr...@dr.dk>.
Would be helpfull as a hint on the camel-cxf wiki regarding testing.



--
View this message in context: http://camel.465427.n5.nabble.com/Issue-using-camel-cxf-in-an-unit-test-tp5718310p5718475.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issue using camel + cxf in an unit test

Posted by Charles Moulliard <ch...@gmail.com>.
Option 3) works fine.

On Wed, Aug 29, 2012 at 10:01 PM, Daniel Kulp <dk...@apache.org> wrote:

>
> It's a semi-Jetty issue.   If you use Keep-Alive connections (the
> default), Jetty has issues shutting down the port for some reason.   It
> holds the port in some sort of strange semi-open state that accepts
> connections but doesn't properly process things.   Never really had time to
> investigate any potential workarounds or fixes.
>
> Couple of solutions:
> 1) Turn off the keep-alives in the connections
>
> 2)  Put  a "Thread.sleep(60000)" between the tests.  (might just be 10000)
> to wait for the keep-alive to timeout.   Yea, not recommended, but thought
> I'd mention it.  :-)
>
> 3) Set the System property:
> "org.apache.cxf.transports.http_jetty.DontClosePort." + port
> (port is the port number you are using) to true.
>
> which tells CXF to just keep the port open and not make any attempt to
> close it.   Thus, when the second server starts up, it just registers on
> the already running instance.   This is what we do for all the Camel and
> CXF unit/system tests.
>
>
> Dan
>
>
>
>
> On Aug 29, 2012, at 12:25 PM, Charles Moulliard <ch...@gmail.com> wrote:
>
> > Hi,
> >
> > I have a unit test issue with camel (2.7.1) and cxf. One camel test class
> > (extending CamelSpringTestSupport) contain 2 unit tests where we call a
> web
> > service exposed by a camel route using a CamelProducerTemplate. Tests
> > executed individually pass well but If I would like to execute both
> tests,
> > I get an exception that the jetty server of CXF cannot respond on the
> > socket. I have tried to add @DirtiesContext for each individual unit test
> > (to force Spring to create a new CamelContext) but that does not help. It
> > seems that when the second test is executed by Junit/Spring, it tries to
> > call the Jetty server created during execution of the first test.
> >
> > Any idea is welcome ?
> >
> > Regards,
> > --
> > Charles Moulliard
> > Apache Committer / Sr. Pr. Consultant at FuseSource.com
> > Twitter : @cmoulliard
> > Blog : http://cmoulliard.blogspot.com
>
> --
> Daniel Kulp
> dkulp@apache.org - http://dankulp.com/blog
> Talend Community Coder - http://coders.talend.com
>
>


-- 
Charles Moulliard
Apache Committer / Sr. Pr. Consultant at FuseSource.com
Twitter : @cmoulliard
Blog : http://cmoulliard.blogspot.com

Re: Issue using camel + cxf in an unit test

Posted by Daniel Kulp <dk...@apache.org>.
It's a semi-Jetty issue.   If you use Keep-Alive connections (the default), Jetty has issues shutting down the port for some reason.   It holds the port in some sort of strange semi-open state that accepts connections but doesn't properly process things.   Never really had time to investigate any potential workarounds or fixes.

Couple of solutions:
1) Turn off the keep-alives in the connections

2)  Put  a "Thread.sleep(60000)" between the tests.  (might just be 10000) to wait for the keep-alive to timeout.   Yea, not recommended, but thought I'd mention it.  :-)

3) Set the System property:
"org.apache.cxf.transports.http_jetty.DontClosePort." + port   
(port is the port number you are using) to true.

which tells CXF to just keep the port open and not make any attempt to close it.   Thus, when the second server starts up, it just registers on the already running instance.   This is what we do for all the Camel and CXF unit/system tests.


Dan




On Aug 29, 2012, at 12:25 PM, Charles Moulliard <ch...@gmail.com> wrote:

> Hi,
> 
> I have a unit test issue with camel (2.7.1) and cxf. One camel test class
> (extending CamelSpringTestSupport) contain 2 unit tests where we call a web
> service exposed by a camel route using a CamelProducerTemplate. Tests
> executed individually pass well but If I would like to execute both tests,
> I get an exception that the jetty server of CXF cannot respond on the
> socket. I have tried to add @DirtiesContext for each individual unit test
> (to force Spring to create a new CamelContext) but that does not help. It
> seems that when the second test is executed by Junit/Spring, it tries to
> call the Jetty server created during execution of the first test.
> 
> Any idea is welcome ?
> 
> Regards,
> -- 
> Charles Moulliard
> Apache Committer / Sr. Pr. Consultant at FuseSource.com
> Twitter : @cmoulliard
> Blog : http://cmoulliard.blogspot.com

-- 
Daniel Kulp
dkulp@apache.org - http://dankulp.com/blog
Talend Community Coder - http://coders.talend.com


Re: Issue using camel + cxf in an unit test

Posted by "Preben.Asmussen" <pr...@dr.dk>.
Have tried that. Doesn't fix it if I remember right.



--
View this message in context: http://camel.465427.n5.nabble.com/Issue-using-camel-cxf-in-an-unit-test-tp5718310p5718324.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Issue using camel + cxf in an unit test

Posted by Charles Moulliard <ch...@gmail.com>.
Maybe @*DirtiesContext*(classMode = ClassMode.AFTER_EACH_TEST_METHOD) at
the level of the class can help ?

On Wed, Aug 29, 2012 at 9:16 PM, Preben.Asmussen <pr...@dr.dk> wrote:

> I can confirm this behavior also exists on Camel 2.10
>
> /Preben
>
>
>
> --
> View this message in context:
> http://camel.465427.n5.nabble.com/Issue-using-camel-cxf-in-an-unit-test-tp5718310p5718322.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>



-- 
Charles Moulliard
Apache Committer / Sr. Pr. Consultant at FuseSource.com
Twitter : @cmoulliard
Blog : http://cmoulliard.blogspot.com

Re: Issue using camel + cxf in an unit test

Posted by "Preben.Asmussen" <pr...@dr.dk>.
I can confirm this behavior also exists on Camel 2.10

/Preben 



--
View this message in context: http://camel.465427.n5.nabble.com/Issue-using-camel-cxf-in-an-unit-test-tp5718310p5718322.html
Sent from the Camel - Users mailing list archive at Nabble.com.