test(commons): add golden fixture corpus for LongEncoding - #3146
Open
dpol1 wants to merge 1 commit into
Open
Conversation
Lock down the current encode/decode behavior of LongEncoding as a compatibility contract: exact outputs across the full value range including the wrapping arithmetic around Long.MIN_VALUE, accepted non-canonical inputs, and the exception class for each rejected input. Exception messages are deliberately not part of the contract. The corpus is generated by running the current implementation (LongEncodingGoldenGenerator, deterministic seed) and verified two ways: LongEncodingGoldenTest replays every line against the current implementation, and regenerates the corpus in memory to check the committed file matches the generator, so the two cannot drift apart. Both tests are registered in UnitTestSuite so commons CI runs them.
3 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Purpose of the PR
LongEncodingencodes ids and sortable keys, so its exact behavior is a compatibility contract, including the intentional overflow wrapping aroundLong.MIN_VALUEand inputs the decoder accepts but the encoder never produces. Today that contract exists only implicitly in the implementation. This PR pins it in a committed, implementation-independent corpus that any port or refactor can be checked against line by line.Main Changes
LongEncodingGoldenGenerator(test scope): produces the corpus by running the current implementation and recording, for each input, the exact output or the exception class. Deterministic: fixed value sets plus a fixed random seed, duplicate lines dropped.longencoding-golden.txt(test resource): 3940 cases, plain ASCII, tab separated with\uXXXXescapes. Covers full-range round trips includingLong.MIN_VALUE/MAX_VALUE, non-canonical decode inputs (00decodes to MIN while encode produces010), arbitrary UTF-16 decode input including surrogates, the error taxonomy (IllegalArgumentExceptionvsNumberFormatExceptionvs NPE), and length limits.LongEncodingGoldenTest: two checks. It replays every corpus line against the implementation, and it regenerates the corpus in memory to assert the committed file matches the generator output exactly, so generator and resource cannot drift apart.UnitTestSuiteso commons CI executes them.Review guide: the review surface is the generator (case selection, ~370 lines), the corpus format documented in the file header, and the two-way check mechanics. The corpus file is generated output verified by
testCorpusMatchesGeneratorand does not need line-by-line review.Contract boundaries: six operations (
encodeSortable/decodeSortable,encodeB64/decodeB64,encodeSignedB64/decodeSignedB64). Exact output strings and decoded values are contract; the exception class is contract, the exception message deliberately is not. No production code changes.Verifying these changes
mvn test -pl hugegraph-commons/hugegraph-common -Dtest=UnitTestSuite -DskipCommonsTests=falseon JDK 11 (the commons CI toolchain): 345 tests, the only errors are 2 environment NPEs inMachineInfoTestthat reproduce identically on a clean master checkout in the same environment.apache-rat:check,checkstyle:checkandgit diff --checkare clean.Does this PR potentially affect the following parts?
Documentation Status
Doc - No Need(user docs unaffected; the technical contract is documented in [Proposal] Java compatibility fixtures and PoC selection matrix for the Rust modernization groundwork #3145, the corpus file header, and this PR)