git.net

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Unit Test Polling Consumer


You could setup another HTTP route in your test that returns what you’re after to exercise your test conditions - I’ve done that quite a bit in the past.

> On Mar 2, 2018, at 10:45 AM, Karel Bernolet <karel.bernolet@xxxxxxxxx> wrote:
> 
> Hello,
> 
> --short version --
> 
> I am trying to unit test a route calling a polling consumer (currently a
> http endpoint)
> Unfortunately, mock endpoints do not support consumers. Is there an
> equivalent to mock endpoints to be used in case of a polling consumer?
> 
> I currently replace the endpoint with a seda endpoint where I send the
> exchange to be polled to before running the test, but this does not provide
> a way to assert if the endpoint has been consumed. Preferably, the test
> endpoint also supports a timeout equivalent to the mock endpoint.
> 
> --longer version --
> I have a requirement where I need to poll an endpoint every x seconds. All
> the available messages need to be processed as fast as possible. In case of
> an error or no messages found, it should delay the next poll to avoid
> having too many error logs.
> As this completely describes a scheduled poll consumer with his
> backoffTresholds, I decided to use this endpoint. The
> DefaultScheduledPollConsumer however does not propagate exceptions while
> polling the endpoint, hence the backoffThresholds are never triggered.
> To avoid this, I overrided the poll method to rethrow the exception:
> 
>> @Override
>> protected int poll() throws Exception {
>>    Exchange exchange = consumer.receive();
>>    getProcessor().process(exchange);
>>    if (exchange.getException() != null) {
>>      throw exchange.getException();
>>    } else {
>>      return exchange.getIn().getHeader(exchange.SCHEDULER_POLLED_MESSAGES, true, Boolean.class) ? 1 : 0;
>>    }
>> 
>> }
>> 
>> While trying to unit test this, I need a polling consumer in which I can
> inject messages to be polled.  As described above, I currently replace the
> endpoint by a seda endpoint where I can send exchanges to be consumed to.
> What I would now like to verify in the test is how many polls on that
> endpoint have been done (to make sure the backoffTresholds work as
> expected).
> 
> 
> I hope someone can direct me to either the good component or an alternative
> way to solve this requirement.
> 
> mvg
> Karel




( ! ) Warning: include(msgfooter.php): failed to open stream: No such file or directory in /var/www/git/apache-camel-users/msg03109.html on line 124
Call Stack
#TimeMemoryFunctionLocation
10.0008358376{main}( ).../msg03109.html:0

( ! ) Warning: include(): Failed opening 'msgfooter.php' for inclusion (include_path='.:/var/www/git') in /var/www/git/apache-camel-users/msg03109.html on line 124
Call Stack
#TimeMemoryFunctionLocation
10.0008358376{main}( ).../msg03109.html:0