Skip to content

Migrate SQLCommenterTest from Groovy/Spock to JUnit 5 Java#11735

Open
dougqh wants to merge 3 commits into
masterfrom
dougqh/migrate-sqlcommenter-test
Open

Migrate SQLCommenterTest from Groovy/Spock to JUnit 5 Java#11735
dougqh wants to merge 3 commits into
masterfrom
dougqh/migrate-sqlcommenter-test

Conversation

@dougqh

@dougqh dougqh commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

What Does This Do

Migrates dd-java-agent/instrumentation/jdbc/src/test/groovy/SQLCommenterTest.groovy to JUnit 5 Java (SQLCommenterTest.java), per the project's "no new Groovy/Spock tests; migrate existing ones" convention.

Faithful 1:1 migration — all 91 cases preserved (8 getFirstWord + 68 inject + 12 base-hash + 3 peer-service), all passing.

Motivation

Moving away from Groovy to JUnit - in advance of some SQL integration optimizations

Notes

  • Spock where: tables → @ParameterizedTest + @MethodSource. @TableTest isn't viable here: the inject data carries embedded single-quotes, commas, slashes, whitespace-significant cells, empty strings, and nulls that the pipe-delimited/trimmed format can't represent. Each row leads with a human-readable scenario string for the test display name.
  • InstrumentationSpecificationAbstractInstrumentationTest; imperative WithConfigExtension.injectSysConfig (values are parameterized, so not @WithConfig); runUnderTrace lambda for the peer-service case.
  • Two behavior-preserving adaptations for the Java package's visibility: ProcessTags.reset(Config.get()) (the no-arg overload is package-private and just delegates), and throws Exception on the runUnderTrace test (its Callable declares it).

Validated with /review-groovy-migration (no findings) and /techdebt (clean).

🤖 Generated with Claude Code

Faithful 1:1 migration of the jdbc SQLCommenterTest: all 91 cases preserved
(8 getFirstWord + 68 inject + 12 base-hash + 3 peer-service). Spock `where:`
tables become @ParameterizedTest + @MethodSource (the data carries embedded
quotes, whitespace-significant, and null cells that @TableTest can't represent),
each row led by a human-readable scenario for the display name. Config injection
uses the imperative WithConfigExtension.injectSysConfig (values are parameterized).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dougqh dougqh added tag: no release notes Changes to exclude from release notes type: refactoring inst: jdbc JDBC instrumentation tag: ai generated Largely based on code generated by an AI or LLM labels Jun 24, 2026
@dougqh dougqh marked this pull request as ready for review June 24, 2026 21:35
@dougqh dougqh requested a review from a team as a code owner June 24, 2026 21:35
@dougqh dougqh requested review from ValentinZakharov and removed request for a team June 24, 2026 21:35
@dd-octo-sts

dd-octo-sts Bot commented Jun 24, 2026

Copy link
Copy Markdown
Contributor

🟢 Java Benchmark SLOs — All performance SLOs passed

Suite Status
Startup 🟢 pass

SLO thresholds are defined here based on automatically generated metrics. A warning is raised when results are within 5% of the threshold.

PR vs. master results
Scenario Candidate master Δ (95% CI of mean)
startup:insecure-bank:iast:Agent 14.07 s 13.97 s [-0.1%; +1.5%] (no difference)
startup:insecure-bank:tracing:Agent 12.93 s 13.04 s [-1.7%; +0.0%] (no difference)
startup:petclinic:appsec:Agent 16.85 s 16.57 s [+0.7%; +2.6%] (maybe worse)
startup:petclinic:iast:Agent 16.87 s 16.37 s [-1.4%; +7.5%] (no difference)
startup:petclinic:profiling:Agent 16.83 s 16.89 s [-1.2%; +0.5%] (no difference)
startup:petclinic:sca:Agent 16.87 s 16.57 s [+0.9%; +2.7%] (maybe worse)
startup:petclinic:tracing:Agent 15.95 s 16.16 s [-2.0%; -0.5%] (maybe better)

Commit: f0ba4cca · CI Pipeline · Benchmarking Platform UI


Load and DaCapo benchmarks can be triggered manually in the GitLab pipeline. Results will appear in the Benchmarking Platform UI after completion.

@ValentinZakharov ValentinZakharov left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please check the comment; there may be a problem
Otherwise, everything looks good

Comment on lines +887 to +899
arguments(
"append postgres optimizer hint leading duplicate",
"/*+ SeqScan(foo) */ SELECT * FROM foo",
"SqlCommenter",
"Test",
"my-service",
"postgres",
"h",
"n",
"TestVersion",
true,
TRACE_PARENT,
"/*+ SeqScan(foo) */ SELECT * FROM foo /*ddps='SqlCommenter',dde='Test',ddpv='TestVersion',dddbs='my-service',ddh='h',dddb='n',traceparent='00-00000000000000007fffffffffffffff-000000024cb016ea-00'*/"),

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is identical to the previous one. I think the idea was to check that applying the comment a second time is safe, but for that the input SQL needs to already contain the DD comment

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Okay, I just let Claude do the conversion, but I'll double check.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch. That duplicate row came over verbatim from the Groovy data table (it had two identical leading-hint append cases), so the migration copied it faithfully — but it was dead weight. I've repurposed it to test the intended behavior: re-injecting already-commented SQL is a no-op (the input now carries the DD comment, expected unchanged). Passes, and it confirms hasDDComment skips already-commented SQL.

(This reply and fix are from Claude.)

The migration faithfully copied a duplicate row that already existed in the Groovy
(two identical leading-hint append cases). Per review, repurpose it to verify the
intended behavior: re-injecting already-commented SQL is a no-op (hasDDComment skips it).

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
@dougqh dougqh enabled auto-merge June 25, 2026 19:41
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

inst: jdbc JDBC instrumentation tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes type: refactoring

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants