Skip to content

Port TraceMapperV1 payload test from Spock to JUnit 5 - #12124

Open
AlexeyKuznetsov-DD wants to merge 3 commits into
masterfrom
alexeyk/migrate-trace-mapper-v1-payload-test
Open

Port TraceMapperV1 payload test from Spock to JUnit 5#12124
AlexeyKuznetsov-DD wants to merge 3 commits into
masterfrom
alexeyk/migrate-trace-mapper-v1-payload-test

Conversation

@AlexeyKuznetsov-DD

Copy link
Copy Markdown
Contributor

What Does This Do

Replaces TraceMapperV1PayloadTest.groovy with a JUnit 5 / Java equivalent. All 25 Spock test instances are preserved; the count goes to 31 because test span kind value conversion (one expect block with 7 assertions) became a 7-row @TableTest.

While porting, duplicated helpers were dropped in favour of the existing shared ones:

  • traceIdBytes, newStringTable and the readFirstSpan(byte[]) / readFirstChunk(byte[]) overloads now come from V1PayloadReader, collapsing the hand-rolled unpacker walks in most tests to a single line.
  • PayloadVerifiers.CapturingChannel and PayloadVerifiers.assertEqualsWithNullAsEmpty replace the test's own ByteArrayChannel and null-as-empty helper.
  • Magic msgpack field ids are now V1PayloadReader.PayloadField / ChunkField / SpanField. This required dropping private from those three nested constant classes (test-only file, same package).
  • The ten repeated 16-arg PojoSpan constructions are behind small named factories (span, spanWithBaggage, spanWithIds, spanWithLinks).

Two behaviour-visible tightenings:

  • spanKindValueConversion asserts the literal wire values 05 instead of comparing TraceMapperV1.SPAN_KIND_* to itself, so a protocol-value change now fails the test.
  • Added attributes.size() assertions to the attribute tests, pinning that the encoder emits nothing beyond the tags under test plus thread.id / thread.name.

Motivation

The equivalent V0.4 and V0.5 payload tests were already migrated in #11871, and V1PayloadReader was written with this port in mind. This brings V1 in line with its siblings and lets the three tests share the same decode helpers.

Additional Notes

SpanLink's constructor is protected, which Groovy could call across packages but Java cannot, hence the small TestSpanLink subclass. Config isolation moves from DDSpecification to @ExtendWith(WithConfigExtension.class) plus a ProcessTags.reset(Config.get()) @BeforeEach, matching the V0.4/V0.5 tests.

No production code is touched.

🤖 Generated with Claude Code

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
@AlexeyKuznetsov-DD AlexeyKuznetsov-DD added tag: ai generated Largely based on code generated by an AI or LLM tag: no release notes Changes to exclude from release notes comp: core Tracer core type: refactoring labels Jul 31, 2026
@datadog-prod-us1-6

This comment has been minimized.

@dd-octo-sts

dd-octo-sts Bot commented Jul 31, 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.03 s 14.00 s [-0.6%; +1.0%] (no difference)
startup:insecure-bank:tracing:Agent 12.97 s 12.95 s [-0.5%; +0.9%] (no difference)
startup:petclinic:appsec:Agent 16.86 s 16.77 s [-0.6%; +1.6%] (no difference)
startup:petclinic:iast:Agent 16.35 s 16.98 s [-8.0%; +0.6%] (no difference)
startup:petclinic:profiling:Agent 16.60 s 16.80 s [-2.3%; -0.1%] (maybe better)
startup:petclinic:sca:Agent 16.82 s 16.52 s [+0.6%; +3.0%] (maybe worse)
startup:petclinic:tracing:Agent 16.07 s 16.05 s [-0.8%; +1.0%] (no difference)

Commit: d6bf61ba · 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.

@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD marked this pull request as ready for review July 31, 2026 19:01
@AlexeyKuznetsov-DD
AlexeyKuznetsov-DD requested a review from a team as a code owner July 31, 2026 19:01
@AlexeyKuznetsov-DD AlexeyKuznetsov-DD self-assigned this Jul 31, 2026

@datadog-prod-us1-6 datadog-prod-us1-6 Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

Datadog Autotest: PASS

More details

The Java migration preserves all original Spock scenarios and the shared reader changes only package visibility for test constants; no diff-only behavioral regression was identified. The targeted test could not execute because the checkout requires a Java 25 toolchain, while this sandbox provides JDK 8/11/17/21.

Was this helpful? React 👍 or 👎

Open Bits AI session

🤖 Datadog Autotest · Commit 6074405 · What is Autotest? · @DataDog review to ask questions · Any feedback? Reach out in #autotest

@chatgpt-codex-connector chatgpt-codex-connector Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

💡 Codex Review

Here are some automated review suggestions for this pull request.

Reviewed commit: 607440569b

ℹ️ About Codex in GitHub

Your team has set up Codex to review pull requests in this repo. Reviews are triggered when you

  • Open a pull request for review
  • Mark a draft as ready
  • Comment "@codex review".

If Codex has suggestions, it will comment; otherwise it will react with 👍.

Codex can also answer questions or update the PR. Try commenting "@codex address that feedback".

Comment on lines +653 to +657
long spanId = 0;
long parentId = 0;
long start = 0;
long duration = 0;
boolean error = false;

Copy link
Copy Markdown

Choose a reason for hiding this comment

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

P2 Badge Preserve presence checks for zero-valued span fields

Initializing parentId to 0 and error to false weakens the wire-format verification because both are valid expected values. If encoding the zero-parent or non-error case writes the wrong field ID, these values can remain unchanged and the assertions still pass; the map-size assertion does not establish that every field ID is unique. The Spock test used nullable boxed values, so retain that behavior or track explicit seenParentId and seenError flags.

Useful? React with 👍 / 👎.

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, and it was worse than described for parentId: TraceGenerator.randomSpan passes DDSpanId.ZERO, so the expected parent id is 0 for every span in the data-driven test, which made that assertion inert rather than merely weakened.

Confirmed by mutating TraceMapperV1 to write field id 6 twice and omit field 5 (16 entries preserved, start written twice with its correct value). Before the fix only spanIdsAreEncodedAsUnsignedValues failed — the one place that kept a boxed Long. Every test going through verifySpan passed with the parent-id field entirely unwritten.

Fixed in d6bf61b by pinning the decoded field-id set, rather than restoring boxed values or adding per-field flags:

assertEquals(EXPECTED_SPAN_FIELD_IDS, spanFieldsSeen);

Together with the existing 16-entry count assertion, set equality guarantees each id appears exactly once, so this covers all 16 fields instead of just parentId and error, and the failure message names the missing id. It also matches the EXPECTED_PAYLOAD_FIELD_IDS pattern already used for the payload header. The same mutation now fails 4 tests instead of 1.

verifyChunk was already safe — it keeps boxed values with assertNotNull on all five fields plus a seenSpans flag.

verifySpan asserted a 16-entry span map but not that each field id appeared
exactly once, so a repeated id plus an omitted one left the omitted field's
decoded value at its initialiser. For parentId (0) and error (false) those
sentinels equal the expected values, and TraceGenerator always uses
DDSpanId.ZERO as the parent id, so the parent-id check was inert.

Assert the decoded field-id set instead, which covers all 16 fields and names
the missing id on failure.

Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp: core Tracer core 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