allthingssecurity opened a new pull request, #29994: URL: https://github.com/apache/camel/pull/29994
# Description [CAMEL-26949](https://issues.apache.org/jira/browse/CAMEL-26949), part of CAMEL-26610. One difference from the JIRA text: the guide example is an expiring map of Camel core (`DefaultTimeoutMap`), not an expiring repository, as the harness module depends on Camel core only (details below). In a DST run the wall clock was the fixed epoch plus the virtual monotonic time (`Dst.EPOCH_MILLIS + now`), so it could only move forward, together with the monotonic clock. Real wall clocks jump: an NTP step, a VM resumed after a pause, someone setting the system time. Code that keeps wall clock times (expiring entries and caches, deadlines, schedules) then sees time go back or leap forward while the monotonic clock goes on. A world could not model that. Change (harness only, `Dst`): - `jumpWallClock(deltaMillis)` moves the wall clock at once, back when the value is negative. Loop thread only, like the other calls of a run. - `jumpWallClockBetween(fromMillis, toMillis, minDeltaMillis, maxDeltaMillis)` lets the seed choose: it draws when the jump happens and how big it is, and schedules it as a task of the run. Both values come from the seeded random source when it is called, so the same seed makes the same jump at the same time and a failing seed replays exactly. The trace says when the jump is scheduled (time and size) and when it happens; the returned task has the delta as its result. - `wallClockOffset()` tells how far the jumps have moved the wall clock. A jump moves it at most 100 years (`MAX_WALL_CLOCK_JUMP_MILLIS`) away from the monotonic clock, so nothing overflows. `currentTimeMillis()` adds the offset, and `DstClock` reads it, so the jump reaches the rewritten wall clock reads of the code under test (`System.currentTimeMillis()`, `new Date()`, `Instant.now()` and the other `java.time` reads) and Camel core through `TimeSource.currentTimeMillis()` and `TimeSource.instant()` (for example the expiry of `DefaultTimeoutMap`, the failure window of `ThrottlingExceptionRoutePolicy` and the created time of a `MonotonicClock`). Nothing monotonic moves: `System.nanoTime()`, `TimeSource.nanoTime()`, `StopWatch`, `MonotonicClock.elapsed()`, `dst.now()`, sleeps and waits, and the due times of the tasks (a task scheduled 10 seconds ahead still runs 10 seconds later). Each jump is a line of the trace, and each run starts without a jump. Without a call to the new methods nothing changes. Docs: a new section "Wall clock jumps" in test-dst.adoc (and its catalog copy), with one example. The JIRA asks for an expiring repository; the harness module only has Camel core at hand, so the example uses the expiring map of core, `DefaultTimeoutMap` (the map behind request-reply timeouts): an entry with a 30 second timeout, under a backward jump of an hour 10 seconds after the put, is still there 70 seconds after the put and is evicted an hour late; after a forward jump it is evicted by the next purge after the jump. The section notes that `get()` refreshes the expiry from the jumped wall clock. The section also says that `dst.currentTimeMillis()` follows the jumps while `Dst.EPOCH_MILLIS + dst.now()` does not, so a fake can keep the clock of the external system apart from the clock of the Camel host. The rows of "What the harness controls", the "Timestamps at 0" pitfall and the table of classes mention it. Tests: new `DstWallClockJumpTest` (8 tests): - a backward jump moves `TimeSource.currentTimeMillis()`, `TimeSource.instant()` and the created time of a `MonotonicClock` at once, while `TimeSource.nanoTime()`, `StopWatch`, `MonotonicClock.elapsed()` and the due time of the next task do not move; - the rewritten `java.time` and `System` reads of the sample code see a forward jump; - the example of the guide, with a real `DefaultTimeoutMap` on an executor of the run: after the backward jump the entry is still there at 70 seconds and when its expiry is reached an hour late, and is evicted by the next purge; after a forward jump (in a fresh run) it is there at 10.999 seconds and evicted by the purge at 11 seconds; - seeded jumps: the same seed gives the same trace hash, time and size of the jump; 20 consecutive seeds give at least 16 different traces, all jumps within the bounds; a drawn delta of 0 makes no jump, and a one-value range gives exactly that value; - a new run starts without a jump, and the system clock is back after it; - a jump from a thread outside the harness is refused, and bad bounds (including values that would overflow) are rejected. The camel-test-dst tests pass (69 tests, including the 8 new ones, about 2 seconds). This is the harness only; worlds that use it come later under CAMEL-26610. I built and tested offline with the versions cached on my machine: commons-lang3 3.21.0 and Guava 33.7.2 (main has 3.22.0 and 33.8.0-jre). # 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-26949](https://issues.apache.org/jira/browse/CAMEL-26949). # 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 camel-test-dst and the core modules with the formatter and import-sort plugins and ran the camel-test-dst tests. The catalog copy of test-dst.adoc is the same file. 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]
