You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Filippo Balicchia <fb...@gmail.com> on 2012/01/27 09:03:31 UTC

camel test kit

Hi,

When use camelTestSuport is possible to avoid the use of Thread.sleep
for gives Camel to React and and route ?
Suppose that  test is running on CI where cpu  it is particularly
busy, with thread.sleep
there is a risk that the test should not fail even if


Cheers

--Filippo

Re: camel test kit

Posted by Filippo Balicchia <fb...@gmail.com>.
Ok Thanks,
maybe I explained bad

for example this test sometimes fails and sometimes not when I make a
thread sleep 3000

When i put 4000 on my console never failed.
What I wanted to say and if you can using them, a different switching technique

Thanks


public class DispatchToxdmRouteTest extends CamelTestSupport
{

    @Override
    protected CamelContext createCamelContext() throws Exception
    {
        CamelContext camelContext = super.createCamelContext();
        String url = "vm://test-broker-" + "42" +
"?broker.persistent=true&broker.useJmx=false";
        ActiveMQConnectionFactory connectionFactory = new
ActiveMQConnectionFactory(url);

        connectionFactory.setCopyMessageOnSend(false);
        connectionFactory.setOptimizeAcknowledge(true);
        connectionFactory.setOptimizedMessageDispatch(true);

        connectionFactory.setUseAsyncSend(false);

        connectionFactory.setAlwaysSessionAsync(false);
        // use a pooled connection factory
        PooledConnectionFactory pooled = new
PooledConnectionFactory(connectionFactory);
        pooled.setMaxConnections(8);
        camelContext.addComponent("activemq",
jmsComponentAutoAcknowledge(connectionFactory));
        return camelContext;
    }

    @Test
    public void testSendAndReceiveMailOneAttach() throws Exception
    {
        Mailbox.clearAll();
        Endpoint endpoint =
context.getEndpoint("smtp://smx@testmail?password=secret");

        Exchange exchange = endpoint.createExchange();
        Message in = exchange.getIn();
        in.setBody("Test Mail");

        String sourceFileName = "26X00000002181_1.xml";

        in.addAttachment(sourceFileName, new DataHandler(new
FileDataSource("src/test/resources/" + sourceFileName)));

        Producer producer = endpoint.createProducer();
        producer.start();
        producer.process(exchange);
        Thread.sleep(3000);
        MockEndpoint mock = getMockEndpoint("mock:result");
        mock.expectedMessageCount(1);
        Exchange out = mock.assertExchangeReceived(0);
        String fileNameStr = (String) out.getIn().getHeader("fileName");
        Assert.assertEquals(fileNameStr, sourceFileName + "_");

        mock.assertIsSatisfied();

        producer.stop();

    }

    @Override
    protected RouteBuilder createRouteBuilder() throws Exception
    {

        return new RouteBuilder()
        {

            @Override
            public void configure() throws Exception
            {

from("pop3://smx@testmail?password=secret&consumer.delay=1000").process(
                    new AttachMailProcessor()).to("activemq:myqueue");

                from("activemq:myqueue").to("mock:result");

            }
        };
    }

}




Il 27 gennaio 2012 09:42, Tarjei Huse <ta...@scanmine.com> ha scritto:
> On 01/27/2012 09:25 AM, Claus Ibsen wrote:
>> Hi
>>
>> Can you be more specific how this is related to C
>> This is not really Camel specific, but about timing issues from unit
>> tests running on CI servers.
>>
>>
>> On Fri, Jan 27, 2012 at 9:03 AM, Filippo Balicchia <fb...@gmail.com> wrote:
>>> Hi,
>>>
>>> When use camelTestSuport is possible to avoid the use of Thread.sleep
>>> for gives Camel to React and and route ?
>>> Suppose that  test is running on CI where cpu  it is particularly
>>> busy, with thread.sleep
>>> there is a risk that the test should not fail even if
>
> This is what you use the MockEndpoint.assertSatisfied() methods for. You
> await a reaction at the end of the route. If it is not possible to await
> the end of the route because it ends in a dead end (f.x. a db value is
> updated) then inject an extra listener that you can wait for.
>
> Tip if you got multiple tests running in the same jvm then it is often a
> good idea to call
> MockEndpoint.resetMocks(this.context());
>
> As spring has a tendency to reuse too much of the context.
>
> A bit sample code to get you started:
>
> RouteDefinition rdef = context().getRouteDefinition(routeName);
> rdef.adviceWith(context(), new AdviceWithRouteBuilder() {
>            @Override
>            public void configure() throws Exception {
>                weaveByType(RecipientListDefinition.class)
>                //weaveByToString(".*RecipientList.*")
>                .before().log(("[MOCK] message for ${header.dest}
> sending to mock")).to("mock:myMock");
>            }
>        });
>
> T
>>>
>>>
>>> Cheers
>>>
>>> --Filippo
>>
>>
>
>
> --
> Regards / Med vennlig hilsen
> Tarjei Huse
> Mobil: 920 63 413
>

Re: camel test kit

Posted by Tarjei Huse <ta...@scanmine.com>.
On 01/27/2012 09:25 AM, Claus Ibsen wrote:
> Hi
>
> Can you be more specific how this is related to C
> This is not really Camel specific, but about timing issues from unit
> tests running on CI servers.
>
>
> On Fri, Jan 27, 2012 at 9:03 AM, Filippo Balicchia <fb...@gmail.com> wrote:
>> Hi,
>>
>> When use camelTestSuport is possible to avoid the use of Thread.sleep
>> for gives Camel to React and and route ?
>> Suppose that  test is running on CI where cpu  it is particularly
>> busy, with thread.sleep
>> there is a risk that the test should not fail even if

This is what you use the MockEndpoint.assertSatisfied() methods for. You
await a reaction at the end of the route. If it is not possible to await
the end of the route because it ends in a dead end (f.x. a db value is
updated) then inject an extra listener that you can wait for.

Tip if you got multiple tests running in the same jvm then it is often a
good idea to call
MockEndpoint.resetMocks(this.context());

As spring has a tendency to reuse too much of the context.

A bit sample code to get you started:

RouteDefinition rdef = context().getRouteDefinition(routeName);
rdef.adviceWith(context(), new AdviceWithRouteBuilder() {
            @Override
            public void configure() throws Exception {
                weaveByType(RecipientListDefinition.class)
                //weaveByToString(".*RecipientList.*")
                .before().log(("[MOCK] message for ${header.dest}
sending to mock")).to("mock:myMock");
            }
        });

T
>>
>>
>> Cheers
>>
>> --Filippo
>
>


-- 
Regards / Med vennlig hilsen
Tarjei Huse
Mobil: 920 63 413


Re: camel test kit

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Can you be more specific how this is related to C
This is not really Camel specific, but about timing issues from unit
tests running on CI servers.


On Fri, Jan 27, 2012 at 9:03 AM, Filippo Balicchia <fb...@gmail.com> wrote:
> Hi,
>
> When use camelTestSuport is possible to avoid the use of Thread.sleep
> for gives Camel to React and and route ?
> Suppose that  test is running on CI where cpu  it is particularly
> busy, with thread.sleep
> there is a risk that the test should not fail even if
>
>
> Cheers
>
> --Filippo



-- 
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.blogspot.com/
Author of Camel in Action: http://www.manning.com/ibsen/