gnodet opened a new pull request, #28521:
URL: https://github.com/apache/camel/pull/28521

   ## Summary
   
   Fixes two bugs in `TransientResumeStrategy.createSimpleCache().forEach()` 
and one bug in `KafkaResumeAdapter.resume()`.
   
   Closes https://issues.apache.org/jira/browse/CAMEL-26315
   
   ## Bug 1 — Inverted boolean in `createSimpleCache().forEach()`
   
   The `ResumeCache.forEach(BiFunction<K, V, Boolean> action)` contract (as 
documented and correctly implemented by `CaffeineCache`) is:
   - `true` returned by the action → **invalidate/remove** the entry
   - `false` → **keep** the entry
   
   The simple cache created by `TransientResumeStrategy.createSimpleCache()` 
had the sense inverted: it removed the entry when the action returned `false` 
and kept it when `true`. This caused `KinesisResumeAction.evalEntry()` (which 
always returns `false` to keep its shard entries) to have all entries silently 
dropped on every resume.
   
   **Fix:** Remove the `!` negation so the entry is removed only when the 
action returns `true`.
   
   ## Bug 2 — `ConcurrentModificationException` with 2+ entries
   
   The same `forEach()` loop called `cache.remove(key)` on the underlying 
`HashMap` while iterating over `cache.entrySet()`. With a single entry this 
goes undetected; with 2+ entries it throws `ConcurrentModificationException`.
   
   **Fix:** Replace the `for`-each loop with an explicit `Iterator` and call 
`it.remove()` instead of `cache.remove()`.
   
   ## Bug 3 — `KafkaResumeAdapter.resume()` returns `true` (wrong)
   
   `KafkaResumeAdapter.resume(TopicPartition, Object)` calls `consumer.seek()` 
and then returns `true`. Because `CaffeineCache.forEach()` correctly implements 
the contract (removes on `true`), this causes all Kafka partition offsets to be 
evicted from the cache immediately after the first resume call.
   
   The seek has already been applied; the entry should be retained for 
subsequent calls, so the method must return `false`.
   
   **Fix:** Change `return true` to `return false`.
   
   ## Changes
   
   | File | Change |
   |------|--------|
   | `core/camel-core-processor/src/main/java/.../TransientResumeStrategy.java` 
| Invert boolean + use Iterator to fix CME |
   | `core/camel-core-processor/pom.xml` | Add `junit-jupiter` test dependency 
(first test in this module) |
   | 
`core/camel-core-processor/src/test/.../TransientResumeStrategyCacheTest.java` 
| 5 new unit tests for `createSimpleCache().forEach()` |
   | `components/camel-kafka/src/main/java/.../KafkaResumeAdapter.java` | 
Return `false` from `resume()` |
   | `components/camel-kafka/src/test/.../KafkaResumeAdapterTest.java` | Fix 
`TestResumeCache.forEach()` stub + add 
`testResumeReturnsFalseToKeepCacheEntries` test |
   
   > _Hermes Agent (forgebot) on behalf of gnodet_


-- 
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]

Reply via email to