allthingssecurity opened a new pull request, #30360: URL: https://github.com/apache/camel/pull/30360
# Description [CAMEL-27169](https://issues.apache.org/jira/browse/CAMEL-27169) The `onConsumeBatchComplete` query is documented to run "after processing the entire batch", for example `delete from projects` (as in `SqlConsumerDeleteBatchCompleteTest`) or an update that marks the rows as processed. When the consumer was stopped while it routed a batch (a route stop, a context shutdown or a reload: by default the graceful shutdown completes only the current exchange, so `isBatchAllowed()` turns false), `SqlConsumer.processBatch` left the loop and still ran the query. The rows of the batch that were not routed were deleted or marked as processed, and never consumed, with no error. Fix, in `SqlConsumer.processBatch`: when the loop routed only part of the batch, the `onConsumeBatchComplete` query is not run (logged at INFO, once per stop that cuts a batch short), and the exchanges of the rows that were not routed are released to the exchange factory (they were left in the queue). A batch that is routed to its end, including one with failed rows, runs the query as before. The rows routed before the stop are not affected by the skipped query when `onConsume` handles each row (deleted or marked as each one is routed, as in the test). A route that relies on `onConsumeBatchComplete` alone (no `onConsume`) to delete or mark the rows now leaves the routed rows of that batch as they are too, and the next poll routes them again (where before the rows that were not routed were lost). Tests: `SqlConsumerBatchCompleteStopTest` (embedded H2, the three rows of `createAndPopulateDatabase.sql`, `onConsume=delete from projects where id = :#id` and `onConsumeBatchComplete=delete from projects`): the route is stopped while it routes the first row. The routed row must be deleted by `onConsume`, and the two rows that were not routed must stay. Runs (offline, with the versions cached on my machine): the new test fails on main (the two rows that were not routed are deleted: expected `[2, 3]` but was `[]`) and passes with the fix; camel-sql module tests 236 run, 0 failures, 2 errors, both in `SqlFunctionDataSourceTest`, whose embedded MariaDB (mariadb4j) cannot be installed on my machine (the same two errors in earlier camel-sql runs of other branches; not related to this change); the new test 20 times in one JVM: 20 of 20. # 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): [CAMEL-27169](https://issues.apache.org/jira/browse/CAMEL-27169). # 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 the core modules and camel-sql with the formatter and import-sort plugins; no option, metadata or doc file changed. 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]
