camel-issues mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Anders Rabo Thorbeck (JIRA)" <j...@apache.org>
Subject [jira] [Created] (CAMEL-7193) Assertions are applied an extra, unnecessary time after an assertion period
Date Tue, 11 Feb 2014 14:54:34 GMT
Anders Rabo Thorbeck created CAMEL-7193:
-------------------------------------------

             Summary: Assertions are applied an extra, unnecessary time after an assertion
period
                 Key: CAMEL-7193
                 URL: https://issues.apache.org/jira/browse/CAMEL-7193
             Project: Camel
          Issue Type: Bug
          Components: camel-core
            Reporter: Anders Rabo Thorbeck
            Priority: Minor


{{org.apache.camel.component.mock.MockEndpoint.expectedMessagesMatches(Predicate...)}} is
implemented in such a way that, if the test at hand is run with an assert period, then an
assertion will be run once before the assert period, but will then be run twice more (when
it only needs to run once more) after the assertion period is up. 

This is because the {{run()}} method of the {{org.apache.camel.component.mock.AssertionClause}}
created in {{expectedMessagesMatches(Predicate...)}} calls {{AssertionClause.addPredicate(Predicate)}},
which has not been implemented as an [idempotent|http://en.wiktionary.org/wiki/idempotence]
function.
Therefore, when the assertion is run before the assert period, the {{Predicate}} is added
to the {{AssertionClause}} once, and when the assertion is run again _after_ the assert period,
the same {{Predicate}} is added again to the same {{AssertionClause}}, and so it is executed
one more time than necessary.

This can be fixed by making the method {{AssertionClause.addPredicate(Predicate)}} idempotent.
Suggestions for doing so are:
*  to change the type of {{org.apache.camel.component.mock.AssertionClause.predicates}} from
{{List<Predicate>}} to {{Set<Predicate>}} ({{java.util.LinkedHashSet}} will preserve
insertion order), or
* to add a containment check in {{AssertionClause.addPredicate(Predicate)}}, before adding
the {{Predicate}} to the list.

I am not sure whether this will work with equality checking of anonymous Predicate classes
with themselves.



--
This message was sent by Atlassian JIRA
(v6.1.5#6160)

Mime
View raw message