Skip to content

Add negative int32 test coverage for Avro wire format and type widening#602

Merged
leiykpt merged 1 commit intolinkedin:masterfrom
leiykpt:master
Mar 27, 2026
Merged

Add negative int32 test coverage for Avro wire format and type widening#602
leiykpt merged 1 commit intolinkedin:masterfrom
leiykpt:master

Conversation

@leiykpt
Copy link
Copy Markdown
Collaborator

@leiykpt leiykpt commented Mar 26, 2026

Summary

This PR adds explicit test coverage proving that negative int32 values are correctly handled at the Avro serialization layer — both binary and JSON wire formats — and that int-to-long type widening preserves sign.

Negative int32 values and very large positive values share overlapping bit representations in two's complement. These tests build confidence that the serialization, deserialization, and schema evolution paths behave correctly for the full signed int32 range.

What's Changed

Added 3 tests to AvroWireFormatCompatibilityTest.java, each exercising three negative values (-1, -100, Integer.MIN_VALUE):

Test Description
testNegativeInt32BinaryRoundtrip Serialize negative int to Avro binary, deserialize, verify value preserved
testNegativeInt32JsonRoundtrip Serialize negative int to Avro JSON, deserialize via compatible decoder, verify value preserved
testNegativeInt32TypeWideningToLong Write with union[null, int] schema, read with union[null, long] schema, verify sign preserved

Total: 9 new test cases (3 tests x 3 values)

These tests run across all supported Avro versions (1.4 through 1.11) via the existing multi-version test harness. No new schemas or dependencies — tests reuse existing RecordWithNumericFields.avsc and WidenIntToLongInUnionField_{writer,reader}.avsc.

Test Plan

  • All 9 new test cases pass locally
  • Existing tests in AvroWireFormatCompatibilityTest.java remain green
  • CI passes

…rectly handled through Avro serialization and schema evolution paths.
@leiykpt leiykpt marked this pull request as ready for review March 26, 2026 18:33
@dg-builder
Copy link
Copy Markdown
Collaborator

nit but int32 is protobuf/c terminology. We probably want to say int (Avro) or Java integer (Java).

@leiykpt leiykpt merged commit 27c74fa into linkedin:master Mar 27, 2026
2 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants