allthingssecurity opened a new pull request, #27243: URL: https://github.com/apache/camel/pull/27243
# Description [CAMEL-25246](https://issues.apache.org/jira/browse/CAMEL-25246) CAMEL-15899 made the Hazelcast consumers register their listener in `doStart` and remove it in `doStop`, but `HazelcastQueueConsumer` and `HazelcastInstanceConsumer` were not changed: - **Queue consumer, listen mode (default).** The item listener was added from a task on the consumer's executor and never removed. After a stop the stopped route kept getting the queue events; after a restart (route controller, `master:`/clustered route policy failover, suspend/resume) a second listener was added and every event was processed twice, one more time per restart. - **Instance consumer.** The membership listener was added in the constructor and never removed. - **Queue consumer, poll mode.** Only `InterruptedException` was caught around `queue.poll`. Any other exception (a client disconnected from the cluster, an operation timeout) ended the single polling thread without a log: the route stayed started and never consumed again. This change: - `HazelcastQueueConsumer` gets the queue in `doStart`; in listen mode it adds the listener there and removes it in `doStop` (the executor is only created for poll mode); in poll mode a failed poll goes to the consumer's exception handler and the consumer polls again after `pollingTimeout`. - `HazelcastInstanceConsumer` adds the membership listener in `doStart` and removes it in `doStop`. Tests: - `HazelcastQueueConsumerRestartTest` (new): one listener left after stop, one event received twice after a restart. - `HazelcastQueueConsumerPollErrorTest` (new): the first poll throws, the next item must still be received. - `HazelcastInstanceConsumerTest.testStopRemovesListener` (new). - `HazelcastQueueConsumerTest` now captures the registered listener again. CAMEL-17952 had replaced the captor with a mock that waits inside `addItemListener` for the test method, because the listener was registered from another thread (a race); the registration is now synchronous in `doStart`, so the race is gone. - Without the change all new tests fail (`Expected: <1> but was: <2>`, `expected: <0> but was: <1>`, `Expected: <1> but was: <0>`, `Wanted but not invoked: removeMembershipListener`). - With the change the camel-hazelcast suite passes: 237 tests, 1 flake (`HazelcastAggregationRepositoryRoutesTest.checkAggregationFromTwoRoutes`, which also fails on main and passes on rerun). # Target - [x] I checked that the commit is targeting the correct branch (Camel 4 uses the `main` branch) # Tracking - [x] If this is a large change, bug fix, or code improvement, I checked there is a [JIRA issue](https://issues.apache.org/jira/browse/CAMEL) filed for the change (usually before you start working on it). # Apache Camel coding standards and style - [x] I checked that each commit in the pull request has a meaningful subject line and body. - [ ] I have run `mvn clean install -DskipTests` locally from root folder and I have committed all auto-generated changes. (I built and tested the affected module, including the formatter and import-sort plugins. I did not run the full root build.) # AI-assisted contributions - [x] If this PR includes AI-generated code, commits have proper co-authorship attribution (e.g., `Co-authored-by` trailers) and the PR description identifies the AI tool used. This PR was prepared with Claude Code (Claude Opus 5.5). The commit carries a `Co-Authored-By` trailer. _Claude Code on behalf of allthingssecurity_ 🤖 Generated with [Claude Code](https://claude.com/claude-code) -- This is an automated message from the Apache Git Service. To respond to the message, please log on to GitHub and use the URL above to go to the specific comment. To unsubscribe, e-mail: [email protected] For queries about this service, please contact Infrastructure at: [email protected]
