CAMEL-24463: Improve KeyValueRepository infrastructure - #26086
Conversation
- Add KeyValueRepositoryHelper unit tests (22 tests covering serialize/deserialize roundtrips, ByteBuffer, offset/length, error cases, null handling) - Add CacheProcessor test for cacheNull=true path - Fix RedisKeyValueRepository.put() to use atomic getAndSet() instead of non-atomic get+set - Extract shared KeyValueTtlValue from duplicate TtlValue inner classes in Ehcache and JCache backends - Fix import ordering in Ehcache/JCache source and test files
|
🌟 Thank you for your contribution to the Apache Camel project! 🌟 🐫 Apache Camel Committers, please review the following items:
|
|
🧪 CI tested the following changed modules:
🔬 Scalpel shadow comparison — Scalpel: 563 tested, 26 compile-only — current: 562 all testedMaveniverse Scalpel detected 589 affected modules (current approach: 562).
|
…avadoc improvements - Add comprehensive KeyValueRepository backends documentation page (keyValueRepository.adoc) covering all 11 backends with configuration examples, atomicity guarantees, TTL behavior, and adapter usage for Idempotent Consumer / Aggregator patterns - Add atomic replace() and delete(key,expected) overrides to JdbcKeyValueRepository using SQL WHERE clause on ITEM_VALUE for server-side CAS - Add Javadoc about non-atomic put() in Cassandra, Ehcache, and JCache backends - Add Javadoc about TTL/topic growth and non-atomic CAS in KafkaKeyValueRepository
- Add 'Distributed Deployment' section to keyValueRepository.adoc with a table showing which backends are safe for clustered Camel deployments (shared state, distributed CAS, practical recommendations per pattern) - Fix atomicity table: JDBC and Cassandra now correctly marked as atomic CAS (✓) reflecting the CAS overrides added in this PR and existing LWT support
✅ Generated files are up to dateAn earlier CI run reported uncommitted generated changes; the latest run no longer does. |
Changes
Comprehensive improvements to the KeyValueRepository infrastructure based on a full review of the SPI, all 11 backends, adapters, Cache EIP, and documentation.
Documentation
keyValueRepository.adoc(1077 lines) — comprehensive backends documentation covering all 11 implementations with configuration examples (Java + YAML DSL), Maven dependencies, atomicity guarantees table, TTL behavior differences, and adapter usage for Idempotent Consumer / Aggregator patternsputIfAbsentput()(no nativegetAndSetequivalent)put()(no nativegetAndPutwith per-entry TTL wrapper)Test Coverage
KeyValueRepositoryHelperTest— 22 new tests covering serialize/deserialize roundtrips (String, Integer, complex objects), ByteBuffer variant, offset/length variant, error cases (non-Serializable → RuntimeCamelException), and null handling. This helper had zero test coverage despite being shared across all persistent backends.CacheProcessorTest— new test forcacheNull=truepath (the trickier code path usingcontains()+get()instead of justget())Atomicity Fixes
RedisKeyValueRepository.put()— replaced non-atomicget()+set()with Redisson's atomicgetAndSet()(both TTL and non-TTL variants). Previous implementation could return stale previous values under concurrent writes.JdbcKeyValueRepository— added atomicreplace()anddelete(key, expected)overrides using SQLWHERE ITEM_KEY = ? AND ITEM_VALUE = ?for server-side CAS. Includes customizable SQL strings and table-name substitution. Javadoc documents the serialized-bytes comparison semantics.Code Deduplication
KeyValueTtlValue— the identicalTtlValueinner class was duplicated in bothEhcacheKeyValueRepositoryandJCacheKeyValueRepository. Extracted to a shared class incamel-support. Updated source and test files in both modules.Build Verification
MemoryKeyValueRepositoryTest(27),KeyValueIdempotentRepositoryTest(14),KeyValueAggregationRepositoryTest(12),CacheProcessorTest(8 including new test)KeyValueRepositoryHelperTest— 22/22 ✅