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

   # Description
   
   [CAMEL-26103](https://issues.apache.org/jira/browse/CAMEL-26103)
   
   camel-test-dst rewrites the time calls of the code under test with a byte 
code agent. It attached the Byte Buddy agent to the running JVM 
(`ByteBuddyAgent.install()`, as Mockito's inline mock maker does). The JDK 
prints a warning for an agent loaded that way (the parent pom hides it with 
`-XX:+EnableDynamicAgentLoading`) and is to disallow it by default (JEP 451): 
with `-XX:-EnableDynamicAgentLoading` every DST test on main fails with `Could 
not self-attach to current VM using external process`. As proposed in 
CAMEL-25911 and on dev@ ("[DISCUSS] An internal time source in camel-util"), 
the agent is now loaded with `-javaagent` in the surefire `argLine` of the 
modules that have DST tests.
   
   Changes:
   - `DstInstrumentation` takes the instrumentation of the agent loaded at JVM 
start (`ByteBuddyAgent.getInstrumentation()`) instead of attaching one. When 
the agent is missing, the first `@DstInstrument` test fails with "The byte code 
agent of camel-test-dst is not loaded: start the JVM of the tests with 
-javaagent:<path of byte-buddy-agent.jar> ...". There is no fallback to a 
runtime attach (the JIRA asks for the `-javaagent` instead of the attach).
   - The modules with DST tests resolve the path of the agent jar from their 
dependencies with the `properties` goal of the `maven-dependency-plugin` (it 
sets the property `net.bytebuddy:byte-buddy-agent:jar`, the jar of the 
`byte-buddy-agent` version managed by the parent), and add 
`-javaagent:${net.bytebuddy:byte-buddy-agent:jar}` to the JVM of surefire:
     - camel-aws2-sqs, camel-azure-eventhubs, camel-kafka-share, camel-slack: 
`camel.surefire.fork.additional-vmargs`, which the `argLine` of the parent 
includes;
     - camel-pulsar: appended to its existing 
`camel.surefire.fork.additional-vmargs` (the `--add-opens` options);
     - camel-test-dst: its own `argLine`, for its self-tests.
   - Only these modules get the `-javaagent`: they all have `byte-buddy-agent` 
on their test classpath (through camel-test-dst), so the property is always 
set. A global `-javaagent` in the parent (as tried for Mockito in #24094) fails 
in the modules without that dependency, where the property stays unresolved and 
the forked JVM does not start.
   - The other tests of these modules run with the agent loaded too. It only 
registers the instrumentation; Mockito's inline mock maker (`mockStatic` in the 
Slack and Event Hubs worlds) finds it and does not attach its own either (the 
camel-slack tests pass with `-XX:-EnableDynamicAgentLoading`, see below).
   - test-dst.adoc (and its catalog copy): a new "Setup" section (the existing 
dependency snippet and, after it, how to set up the agent for a module with DST 
tests: the XML, the error without it, and that a run from an IDE needs the 
`-javaagent` option in the run configuration). The error message points to that 
section.
   - `DstInstrumentationTest.theAgentIsLoadedWhenTheJvmStarts` checks that the 
JVM was started with the `-javaagent` of `byte-buddy-agent` and that the 
agent's instrumentation is there. It fails on main.
   
   Tests (offline build, the core modules in the same reactor):
   - camel-test-dst 58/0. The worlds with their default seeds 
(`SqsVisibilityDstTest` 1 000, `SqsRedeliveryDstTest` 500, 
`EventHubsCheckpointDstTest` 1 002, `PulsarConsumerDstTest` 1 001, 
`SlackSuspendDstTest` 1 000), together with all unit tests of their modules 
(`-DskipITs`): camel-aws2-sqs 1 599/0 (16 skipped), camel-azure-eventhubs 1 
049/0 (8 skipped), camel-pulsar 1 075/0 (37 skipped), camel-slack 1 027/0 (1 
skipped). Each `dependency:properties` execution ran offline.
   - After rebasing on main with #28434: camel-test-dst 58/0, 
`KafkaShareConsumerDstTest` 1 000/0 and all unit tests of camel-kafka-share 
(29/0), `SlackSuspendDstTest`, `PulsarConsumerDstTest`, `SqsVisibilityDstTest` 
and `EventHubsCheckpointDstTest` with their default seeds. Without the 
camel-kafka-share pom additions, `KafkaShareConsumerDstTest` fails with the 
"not loaded" message.
   - With `-XX:-EnableDynamicAgentLoading` added to the JVM: on this branch 
camel-test-dst, the two SQS worlds and all camel-slack tests pass (58, 1 500 
and 1 027 tests). On main the same run fails in every DST test class 
(`DstAlsoRewriteTest`, `SqsRedeliveryDstTest`, `SqsVisibilityDstTest`, 
`SlackSuspendDstTest`, ...) with the self-attach error above.
   - The formatter and import-sort plugins ran and changed nothing.
   
   camel-kafka-share: its DST world (`KafkaShareConsumerDstTest`, CAMEL-25910, 
#28434) was merged after this change was first prepared; this PR adds the same 
two pom additions there (the `dst-agent-path` execution and the `-javaagent` in 
`camel.surefire.fork.additional-vmargs`).
   
   Backport: camel-test-dst is new in 4.24 (preview), so main only.
   
   # 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-26103) 
filed for the change (usually before you start working on it): 
[CAMEL-26103](https://issues.apache.org/jira/browse/CAMEL-26103).
   
   # 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 the core modules, camel-test-dst and the four world modules and 
ran the tests above, including the formatter and import-sort plugins. The 
test-dst.adoc change is copied to its catalog copy. 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]

Reply via email to