You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Kevin Jackson <fo...@gmail.com> on 2010/02/06 17:09:14 UTC

Integration testing a route before production

Hi,

I have a route configured in Spring and I would like to integration
test (from file endpoint with production data to persistence in test
db)

For example:

<camel:route id="integration-test">
  <camel:from ref="file-consumer"/>
  <camel:split streaming="true">
    <camel:tokenize token="\n"/>
    <camel:bean ref="Unmarshaller" method="unmarshall"/>
    <camel:bean ref="Transformer" method="transform"/>
    <camel:to uri="mock:result"/>
  </camel:split>
</camel:route>

Now I want to run this route with production data and ensure that the
sample of data I used in my unit tests is representative and that the
production data doesn't cause my pojos to break in any weird ways.
I'm also interested in seeing how much ram this single route will
consume with realistic data before I add it to the live routes.

# How do I trigger this route to run (in the context of an @Test
decorated method)?
# How do I make any meaningful assertions against the mock:result?

Essentially I want to 'assertNoExceptions' and assertTrue(memoryUsed <
80Mb) (or any other arbitrary value.  If I wire up the db layer I can
assert against the data in the tables, but that's a data centric
approach and I think what I'm after is not easily defined by data.

For example I can prove by induction that if the code works for 1
valid input dataset then it will work for n valid input datasets, so
I'm leaning more towards testing intangibles (performance
[time|space], robustness of handling real workloads/data etc).

Sorry I can't really explain why I feel I need to do this, just that I
think it's necessary in this one particular case - does anyone have
any suggestions for how to at least start up the route in a testing
context?

Thanks,
Kev

Re: Integration testing a route before production

Posted by Stephen Gargan <st...@gmail.com>.
Kevin,

You are almost there, If you split your integration route into two
routes then everything should works as you expect. The first is your
route under test, the production route as it will appear in the
released code. The second is the integration route to drive it. In
this case, you will use the integration route to write your test data
to the file being monitored and then your production route will then
pick it up e.g.

<camel:route id="integration-test">
 <camel:from uri="direct:file"/>
 <camel:to uri="file:file-that-file-component-is-watching"/>
</camel:route>

your production route (decouple it from the mock with a direct endpoint)

<camel:route id="production-route">
 <camel:from ref="file-consumer"/>
 <camel:split streaming="true">
   <camel:tokenize token="\n"/>
   <camel:bean ref="Unmarshaller" method="unmarshall"/>
   <camel:bean ref="Transformer" method="transform"/>
   <camel:to uri="direct:route-out"/>
 </camel:split>
</camel:route>

Add another test route in your test context to grab the output of the
production route

<camel:route id="integration-test-result">
 <camel:from uri="direct:route-out"/>
 <camel:to uri="mock:result" />
</camel:route>

If you notice, now 'production-route' contains no test artifacts, it
appears as it would in your final product.The other test routes exist
in a test context that can import your actual production routes and
drive them any which way you need to test them. Direct endpoints are
your friend as they make it very easy to decouple routes and give you
simple known in and out points to hook into for testing.

Give this a try, shout back if you've any questions.

rgds,

ste

On Mon, Feb 8, 2010 at 12:51 AM, Claus Ibsen <cl...@gmail.com> wrote:
> On Mon, Feb 8, 2010 at 9:37 AM, Kevin Jackson <fo...@gmail.com> wrote:
>> Hi,
>>
>> Thanks for the responses.
>>
>>> [1] http://camel.apache.org/spring-testing.html
>>
>> I have read this and it doesn't really answer my question.
>>
>> I already do integration testing using fluent dsl for :
>> direct-> processor/bean -> mock
>>
>> I have integration tests in Camel using Camel test framework for these
>> simple integrations.  The problem is that I want to test the spring
>> config and also test the memory consumption of a single route before
>> integrating the route into my main context (which is also Spring).
>>
>
> Monitoring memory usage is not a Camel specific thing. Use google to
> find solutions for that.
>
>
>> So for each part of the route I have classic JUnit tests and also
>> Camel Tests, now I want an end-to-end test :
>>
>> from fileconsumer via processing pojos to persistence
>>
>>>> Then the next thing is to feed the data into the route.
>>>> If you want to keep your file endpoint you could copy files into the
>>>> directory it listens to.
>>
>> This needs to be repeatable, so manually copying a file into a directory is out.
>>
>
> You can use Camel to create or move files for your testing as well.
>
>>>> I normally use a producer (see
>>>> http://camel.apache.org/pojo-producing.html). For this aproach you need to
>>>> start the route with a direct endpoint.
>>
>> This is the part I don't get - I have already configured the from
>> endpoint in Spring, I need to kickstart the route from within the
>> context of JUnit's TestRunner.  This works fine with direct:start
>>
>> So I can get this route to work :
>> <camel:route id="mock-integration-test">
>>  <camel:from uri="direct:start"/>
>>  <camel:bean ref="Unmarshaller" method="unmarshall"/>
>>  <camel:bean ref="Transformer" method="transform"/>
>>  <camel:to uri="mock:result"/>
>> </camel:route>
>>
>> by using:
>> @Produce(uri = "direct:start")
>> private ProducerTemplate template;
>>
>> @Test
>> @DirtiesContext
>> public void testIntegrated() throws Exception {
>>  resultEndpoint.expectedBodiesReceived(result);
>>  template.sendBody(test);
>>  resultEndpoint.assertIsSatisfied();
>> }
>>
>> but this only has a subset of test data (hardcoded in the Test class),
>>
>> So I need to be able to consume a representative sample of test data:
>> <camel:route id="integration-test">
>>  <camel:from uri="direct:file"/>
>>  <camel:to ref="file-consumer"/>
>>  <camel:split streaming="true">
>>    <camel:tokenize token="\n"/>
>>    <camel:bean ref="Unmarshaller" method="unmarshall"/>
>>    <camel:bean ref="Transformer" method="transform"/>
>>    <camel:to uri="mock:result"/>
>>  </camel:split>
>> </camel:route>
>>
>> How can I trigger this?
>>
>> Thanks,
>> Kev
>>
>
>
>
> --
> Claus Ibsen
> Apache Camel Committer
>
> Author of Camel in Action: http://www.manning.com/ibsen/
> Open Source Integration: http://fusesource.com
> Blog: http://davsclaus.blogspot.com/
> Twitter: http://twitter.com/davsclaus
>

Re: Integration testing a route before production

Posted by Claus Ibsen <cl...@gmail.com>.
On Mon, Feb 8, 2010 at 9:37 AM, Kevin Jackson <fo...@gmail.com> wrote:
> Hi,
>
> Thanks for the responses.
>
>> [1] http://camel.apache.org/spring-testing.html
>
> I have read this and it doesn't really answer my question.
>
> I already do integration testing using fluent dsl for :
> direct-> processor/bean -> mock
>
> I have integration tests in Camel using Camel test framework for these
> simple integrations.  The problem is that I want to test the spring
> config and also test the memory consumption of a single route before
> integrating the route into my main context (which is also Spring).
>

Monitoring memory usage is not a Camel specific thing. Use google to
find solutions for that.


> So for each part of the route I have classic JUnit tests and also
> Camel Tests, now I want an end-to-end test :
>
> from fileconsumer via processing pojos to persistence
>
>>> Then the next thing is to feed the data into the route.
>>> If you want to keep your file endpoint you could copy files into the
>>> directory it listens to.
>
> This needs to be repeatable, so manually copying a file into a directory is out.
>

You can use Camel to create or move files for your testing as well.

>>> I normally use a producer (see
>>> http://camel.apache.org/pojo-producing.html). For this aproach you need to
>>> start the route with a direct endpoint.
>
> This is the part I don't get - I have already configured the from
> endpoint in Spring, I need to kickstart the route from within the
> context of JUnit's TestRunner.  This works fine with direct:start
>
> So I can get this route to work :
> <camel:route id="mock-integration-test">
>  <camel:from uri="direct:start"/>
>  <camel:bean ref="Unmarshaller" method="unmarshall"/>
>  <camel:bean ref="Transformer" method="transform"/>
>  <camel:to uri="mock:result"/>
> </camel:route>
>
> by using:
> @Produce(uri = "direct:start")
> private ProducerTemplate template;
>
> @Test
> @DirtiesContext
> public void testIntegrated() throws Exception {
>  resultEndpoint.expectedBodiesReceived(result);
>  template.sendBody(test);
>  resultEndpoint.assertIsSatisfied();
> }
>
> but this only has a subset of test data (hardcoded in the Test class),
>
> So I need to be able to consume a representative sample of test data:
> <camel:route id="integration-test">
>  <camel:from uri="direct:file"/>
>  <camel:to ref="file-consumer"/>
>  <camel:split streaming="true">
>    <camel:tokenize token="\n"/>
>    <camel:bean ref="Unmarshaller" method="unmarshall"/>
>    <camel:bean ref="Transformer" method="transform"/>
>    <camel:to uri="mock:result"/>
>  </camel:split>
> </camel:route>
>
> How can I trigger this?
>
> Thanks,
> Kev
>



-- 
Claus Ibsen
Apache Camel Committer

Author of Camel in Action: http://www.manning.com/ibsen/
Open Source Integration: http://fusesource.com
Blog: http://davsclaus.blogspot.com/
Twitter: http://twitter.com/davsclaus

Re: Integration testing a route before production

Posted by Kevin Jackson <fo...@gmail.com>.
Hi,

Thanks for the responses.

> [1] http://camel.apache.org/spring-testing.html

I have read this and it doesn't really answer my question.

I already do integration testing using fluent dsl for :
direct-> processor/bean -> mock

I have integration tests in Camel using Camel test framework for these
simple integrations.  The problem is that I want to test the spring
config and also test the memory consumption of a single route before
integrating the route into my main context (which is also Spring).

So for each part of the route I have classic JUnit tests and also
Camel Tests, now I want an end-to-end test :

from fileconsumer via processing pojos to persistence

>> Then the next thing is to feed the data into the route.
>> If you want to keep your file endpoint you could copy files into the
>> directory it listens to.

This needs to be repeatable, so manually copying a file into a directory is out.

>> I normally use a producer (see
>> http://camel.apache.org/pojo-producing.html). For this aproach you need to
>> start the route with a direct endpoint.

This is the part I don't get - I have already configured the from
endpoint in Spring, I need to kickstart the route from within the
context of JUnit's TestRunner.  This works fine with direct:start

So I can get this route to work :
<camel:route id="mock-integration-test">
  <camel:from uri="direct:start"/>
  <camel:bean ref="Unmarshaller" method="unmarshall"/>
  <camel:bean ref="Transformer" method="transform"/>
  <camel:to uri="mock:result"/>
</camel:route>

by using:
@Produce(uri = "direct:start")
private ProducerTemplate template;

@Test
@DirtiesContext
public void testIntegrated() throws Exception {
  resultEndpoint.expectedBodiesReceived(result);
  template.sendBody(test);
  resultEndpoint.assertIsSatisfied();
}

but this only has a subset of test data (hardcoded in the Test class),

So I need to be able to consume a representative sample of test data:
<camel:route id="integration-test">
  <camel:from uri="direct:file"/>
  <camel:to ref="file-consumer"/>
  <camel:split streaming="true">
    <camel:tokenize token="\n"/>
    <camel:bean ref="Unmarshaller" method="unmarshall"/>
    <camel:bean ref="Transformer" method="transform"/>
    <camel:to uri="mock:result"/>
  </camel:split>
</camel:route>

How can I trigger this?

Thanks,
Kev

Re: Integration testing a route before production

Posted by Willem Jiang <wi...@gmail.com>.
Here is the example to show how to start the camel context[1] with 
spring test support.

[1] http://camel.apache.org/spring-testing.html

Willem


Christian Schneider wrote:
> Hi Kevin,
> 
> basically you can use the spring integration test aproach.
> http://static.springsource.org/spring/docs/2.5.x/reference/testing.html#integration-testing 
> 
> So you use spring to start the context.
> 
> Another aproach is to use the camel testing support:
> http://camel.apache.org/testing.html
> 
> Then the next thing is to feed the data into the route.
> If you want to keep your file endpoint you could copy files into the 
> directory it listens to.
> 
> I normally use a producer (see 
> http://camel.apache.org/pojo-producing.html). For this aproach you need 
> to start the route with a direct endpoint.
> 
> In any case I would use the mock endpoint to wait for the number of 
> exchanges you expect to come. Additionally you can set a time limit. So 
> you can check the time part of your performance.
> I have no idea though how to test for memory consumption.
> 
> In any case it is a good idea to have a look into the tests of the camel 
> components they show nicely how to test camel routes.
> 
> Greetings
> 
> Christian
> 
> 
> Am 06.02.2010 17:09, schrieb Kevin Jackson:
>> Hi,
>>
>> I have a route configured in Spring and I would like to integration
>> test (from file endpoint with production data to persistence in test
>> db)
>>
>> For example:
>>
>> <camel:route id="integration-test">
>>    <camel:from ref="file-consumer"/>
>>    <camel:split streaming="true">
>>      <camel:tokenize token="\n"/>
>>      <camel:bean ref="Unmarshaller" method="unmarshall"/>
>>      <camel:bean ref="Transformer" method="transform"/>
>>      <camel:to uri="mock:result"/>
>>    </camel:split>
>> </camel:route>
>>
>> Now I want to run this route with production data and ensure that the
>> sample of data I used in my unit tests is representative and that the
>> production data doesn't cause my pojos to break in any weird ways.
>> I'm also interested in seeing how much ram this single route will
>> consume with realistic data before I add it to the live routes.
>>
>> # How do I trigger this route to run (in the context of an @Test
>> decorated method)?
>> # How do I make any meaningful assertions against the mock:result?
>>
>> Essentially I want to 'assertNoExceptions' and assertTrue(memoryUsed<
>> 80Mb) (or any other arbitrary value.  If I wire up the db layer I can
>> assert against the data in the tables, but that's a data centric
>> approach and I think what I'm after is not easily defined by data.
>>
>> For example I can prove by induction that if the code works for 1
>> valid input dataset then it will work for n valid input datasets, so
>> I'm leaning more towards testing intangibles (performance
>> [time|space], robustness of handling real workloads/data etc).
>>
>> Sorry I can't really explain why I feel I need to do this, just that I
>> think it's necessary in this one particular case - does anyone have
>> any suggestions for how to at least start up the route in a testing
>> context?
>>
>> Thanks,
>> Kev
>>
>>    
> 
> 


Re: Integration testing a route before production

Posted by Christian Schneider <ch...@die-schneider.net>.
Hi Kevin,

basically you can use the spring integration test aproach.
http://static.springsource.org/spring/docs/2.5.x/reference/testing.html#integration-testing
So you use spring to start the context.

Another aproach is to use the camel testing support:
http://camel.apache.org/testing.html

Then the next thing is to feed the data into the route.
If you want to keep your file endpoint you could copy files into the 
directory it listens to.

I normally use a producer (see 
http://camel.apache.org/pojo-producing.html). For this aproach you need 
to start the route with a direct endpoint.

In any case I would use the mock endpoint to wait for the number of 
exchanges you expect to come. Additionally you can set a time limit. So 
you can check the time part of your performance.
I have no idea though how to test for memory consumption.

In any case it is a good idea to have a look into the tests of the camel 
components they show nicely how to test camel routes.

Greetings

Christian


Am 06.02.2010 17:09, schrieb Kevin Jackson:
> Hi,
>
> I have a route configured in Spring and I would like to integration
> test (from file endpoint with production data to persistence in test
> db)
>
> For example:
>
> <camel:route id="integration-test">
>    <camel:from ref="file-consumer"/>
>    <camel:split streaming="true">
>      <camel:tokenize token="\n"/>
>      <camel:bean ref="Unmarshaller" method="unmarshall"/>
>      <camel:bean ref="Transformer" method="transform"/>
>      <camel:to uri="mock:result"/>
>    </camel:split>
> </camel:route>
>
> Now I want to run this route with production data and ensure that the
> sample of data I used in my unit tests is representative and that the
> production data doesn't cause my pojos to break in any weird ways.
> I'm also interested in seeing how much ram this single route will
> consume with realistic data before I add it to the live routes.
>
> # How do I trigger this route to run (in the context of an @Test
> decorated method)?
> # How do I make any meaningful assertions against the mock:result?
>
> Essentially I want to 'assertNoExceptions' and assertTrue(memoryUsed<
> 80Mb) (or any other arbitrary value.  If I wire up the db layer I can
> assert against the data in the tables, but that's a data centric
> approach and I think what I'm after is not easily defined by data.
>
> For example I can prove by induction that if the code works for 1
> valid input dataset then it will work for n valid input datasets, so
> I'm leaning more towards testing intangibles (performance
> [time|space], robustness of handling real workloads/data etc).
>
> Sorry I can't really explain why I feel I need to do this, just that I
> think it's necessary in this one particular case - does anyone have
> any suggestions for how to at least start up the route in a testing
> context?
>
> Thanks,
> Kev
>
>    


-- 

Christian Schneider
---
http://www.liquid-reality.de