allthingssecurity opened a new pull request, #29995: URL: https://github.com/apache/camel/pull/29995
# Description [CAMEL-26957](https://issues.apache.org/jira/browse/CAMEL-26957), part of CAMEL-26610. Two differences from the JIRA text: the world drives the pull consumer only, as the push consumer and core NATS subjects deliver on threads of jnats that the harness does not run; and a server restart is modelled as the server deleting the ephemeral consumers while the connection stays up, not as a reconnect of the connection itself. A deterministic simulation test (camel-test-dst) of the camel-nats JetStream pull consumer, in the `dst` package of its tests, in the same form as the SQS world: `NatsConsumerDstTest` (1000 seeds), `NatsWorld` and `FakeJetStream`. Test only; no main code changes. What the world models: the real consumer (`NatsConsumer` and its consuming task) and Camel's routing run on the virtual-time loop; only the NATS server is faked, behind a jnats `Connection` given to the endpoint with the `connection` option (dynamic proxies of the jnats interfaces, Mockito mocks of the jnats value classes `ServerInfo`, `StreamInfo`, `ConsumerInfo` and `NatsJetStreamMetaData`). The fake is written from the NATS JetStream documentation and the jnats client, and cites them: a pull `fetch` waits up to its timeout for up to a batch and returns what it got, explicit `ack`, `nak` and `nakWithDelay`, redelivery after AckWait, MaxDeliver, ephemeral and durable consumers, a server restart modelled as the deletion of the ephemeral consumers while connected (a pull waiting at the deletion gets 409 Consumer Deleted; a later pull gets no message and `getConsumerInfo` answers null, so the consumer finds the consumer gone and subscribes again), a `flush` that times out, and acks that are lost (an ack is a publish without an answer). A new ephemeral consumer starts with no delivery state of its own; the fake keeps one state per message for all consumers, which is written down where it matters. The seed picks `pullBatchSize`, `pullFetchTimeout`, `ackWait`, `maxDeliver`, `nackWait`, a durable or an ephemeral consumer and the fault rates, and injects failed fetches, lost acks, flushes that time out during the stop, failed and slow processing (now and then longer than AckWait), route restarts (also while the consumer waits in a fetch) and server restarts. Invariants: the consumer passes its ack policy, AckWait and MaxDeliver to the server and uses the connection as documented (it never closes the shared connection); a message is acked only after its exchange completed, and nak'd only after it failed; a stopped consumer leaves no subscription active, checked when the route starts again and after the final stop; once the faults cleared every message is acked, or given up after MaxDeliver. One case is accepted: when an ack was lost and the server then deleted the ephemeral consumer, the consumer subscribes again after that message, as it counts it as acknowledged. Limits, written in the world's Javadoc: the operator stops the route only while no exchange is in it, so a stop between two messages of a fetched batch is not driven; the harness interrupts no thread, so the interrupt part of CAMEL-26884 is not checked (its flush and subscribe parts are); the route starts again 100 ms or more after a stop, so a start that comes while the stopped consumer task still subscribes is not driven. Not explored: push subscriptions and core NATS subjects (their dispatchers deliver on jnats threads), manualAck, AckAll and AckNone, a connection created by the consumer itself. Other changes: - `camel-test-dst` and `mockito-core` as test dependencies of camel-nats, and the byte code agent of camel-test-dst on the surefire command line, as for the other worlds. - The test log of camel-nats goes to a size-capped rolling file (50 MB, one backup), as a failing world can log a lot. - The `@DstWorld` annotation lists the world in the component JSON (and its catalog copy) and in the table of the camel-test-dst page (and its catalog copy, byte-identical). Tests: - On main: 5000 of 5000 seeds pass (about 9 ms a seed). Seeds 8 and 77 replayed in two JVMs give the same trace hashes. - Self-check against a fixed bug: on the code before CAMEL-26884 (6bc46f9cffc1 reverted) 346 of 2000 seeds fail, all on "a stopped consumer leaves no subscription active". CAMEL-26462 and CAMEL-25847 from the JIRA's list of candidates are fixes of the push consumer and its dispatcher, which this world does not drive, so they are not used. - The open PR for CAMEL-26915 (`camel-nats-consumer-run-token`) also changes `NatsConsumer`: this branch merges with it without a conflict, and no invariant of the world depends on it. Merged locally with that branch, the world passes 2000 of 2000 seeds. - camel-nats unit tests: 1044 run (44, plus 1000 seeds), 0 failures, 0 errors, 0 skipped. What was not run locally: the ITs (they need Docker) and the full root build. 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-26957](https://issues.apache.org/jira/browse/CAMEL-26957). # 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-test-dst and camel-nats, including the formatter and import-sort plugins. The generated files touched are the component JSON with its catalog copy, and the table of the camel-test-dst page with its catalog copy (byte-identical). 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]
