allthingssecurity opened a new pull request, #28135: URL: https://github.com/apache/camel/pull/28135
# Description [CAMEL-25781](https://issues.apache.org/jira/browse/CAMEL-25781) `EventHubsConsumer.processCommit` started a new checkpoint window when the wall clock had passed the scheduled time of the current one (`EventHubsCheckpointUpdaterTask.isExpired()`, which compares with `>`), and the timer task took the count of the window without the consumer's lock. So an event could be counted in a window whose timer had already run: 1. it completed in the millisecond of the scheduled time, after the timer ran; 2. the timer ran between the `isExpired()` check and the count of the event; 3. a timer that had already started when a checkpoint by batch size cancelled it took the count of the next window. And when the timer ran late (after the scheduled time by the wall clock), the next event started a new window, the old timer took its count and checkpointed the previous event, and the new timer found nothing. The event was then checkpointed only with the next event of the partition. If the partition stayed quiet, it was delivered again after a restart or a rebalance (a duplicate, not a loss). Using `>=` alone would close case 1 but make the late-timer case wider. Change: - a new window starts when the timer of the current one has run (`isDone()`), not by the wall clock; - the timer takes the count and the event context under the consumer's lock and marks itself done, so an event is either counted before it (and checkpointed by it) or after it (and starts a new window); - a checkpoint by batch size marks the task done under the lock as well, so a timer that has already started takes nothing; - `isExpired()` stays for the `CHECKPOINT_UPDATED_BY` header. Tests: - New `EventHubsConsumerCheckpointWindowTest` (3 tests, in the style of the CAMEL-25683 tests: `processCommit` called directly, a mocked scheduler whose captured timer tasks the test runs): the timer runs before its scheduled time by the wall clock and then an event completes; the timer runs late; a timer that had started before a checkpoint by batch size. Without the change all three fail with `Wanted but not invoked: eventContext.updateCheckpointAsync()` for the last completed event. Case 2 cannot be shown without a hook between the check and the count; the same lock closes it. - With the change the camel-azure-eventhubs unit tests pass: 38 run, 0 failures, 0 errors, 0 skipped. - Found with the camel-test-dst world for Event Hubs (CAMEL-25738, not on `main` yet), seed 3042 of 5000. On that branch, with this commit picked, seed 3042 passes and 5000 of 5000 seeds pass. What was not run: the full root build, and the integration tests (they need an Azure Event Hubs namespace). # 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-25781](https://issues.apache.org/jira/browse/CAMEL-25781). # 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 camel-azure-eventhubs, 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 commits carry 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]
