Skip to content

Implement reset methods for XXHash checksum algorithms#6762

Merged
zoewangg merged 2 commits intomasterfrom
zoewang/xxhashReset
Mar 6, 2026
Merged

Implement reset methods for XXHash checksum algorithms#6762
zoewangg merged 2 commits intomasterfrom
zoewang/xxhashReset

Conversation

@zoewangg
Copy link
Contributor

@zoewangg zoewangg commented Mar 5, 2026

Motivation and Context

XxHashChecksum.reset() previously threw UnsupportedOperationException, causing exception to be thrown from async streaming operations that use this checksum (no services use this today). This change implements reset() to properly close the old CRT resource and create a fresh instance. The root cause is that ChunkedEncodedPublisher resets all states including checksum in subscribe

public void subscribe(Subscriber<? super ByteBuffer> subscriber) {
resetState();

Additionally, HttpChecksumCalculationTest relied on Mockito mocks with manual ArgumentCaptor wiring. This refactors it to use MockSyncHttpClient/
MockAsyncHttpClient from service-test-utils, and adds full request body verification for streaming checksum trailer tests.

Modifications

  • XxHashChecksum: Implement reset() — closes the existing XXHash CRT resource and reinitializes
  • XxHashChecksumTest: Replace reset_throwsUnsupportedOperationException with reset_allowsReuseOfChecksum
  • HttpChecksumCalculationTest: Rewrite to use MockSyncHttpClient/MockAsyncHttpClient, add complete chunked body assertions for both sync and async streaming paths, add xxhash and sha256 test cases to checksumInHeaderRequiredParams
  • MockAsyncHttpClient: Always capture streaming payload via ByteArrayOutputStream, return CompletableFuture that completes after payload capture, remove
    unused setAsyncRequestBodyLength

Testing

  • Updated unit tests for XxHashChecksum.reset() behavior
  • HttpChecksumCalculationTest now verifies exact chunked body content including trailer checksum values for all algorithms (CRC32, CRC32C, SHA1, SHA256,
    XXHASH3, XXHASH64, XXHASH128)

Types of changes

  • Bug fix (non-breaking change which fixes an issue)
  • New feature (non-breaking change which adds functionality)

Checklist

  • I have read the CONTRIBUTING document
  • Local run of mvn clean install -pl :{module} succeeds for affected modules
  • My code follows the code style of this project
  • My change requires a change to the Javadoc documentation
  • I have updated the Javadoc documentation accordingly
  • I have added tests to cover my changes
  • All new and existing tests passed
  • I have added a changelog entry

License

  • I confirm that this pull request can be released under the Apache 2 license

@zoewangg zoewangg requested a review from a team as a code owner March 5, 2026 17:05
@@ -120,7 +120,6 @@ public void asyncNonStreamingOperation_payloadSizeLessThanCompressionThreshold_d
public void asyncStreamingOperation_compressionEnabled_compressesCorrectly() {
mockAsyncHttpClient.stubNextResponse(mockResponse(), Duration.ofMillis(500));

mockAsyncHttpClient.setAsyncRequestBodyLength(compressedBody.length());
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Removed this because MockAsyncHttpClient now always captures the streaming request payload, so pre-configuring the expected body length is no longer needed.

byte[] bytes = new byte[buffer.remaining()];
buffer.get(bytes);
byteBuffer.put(bytes);
invokeSafely(() -> baos.write(BinaryUtils.copyBytesFrom(buffer)));
Copy link
Contributor Author

Choose a reason for hiding this comment

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

We should technically call request.subscription(1) here, but it'd trigger a bug in InMemoryPublisher that causes the request to hang. I'll fix it later. This shouldn't cause any real issues though since InMemoryPublisher only invokes onNext once.

@zoewangg zoewangg added no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required and removed no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required labels Mar 5, 2026
@zoewangg
Copy link
Contributor Author

zoewangg commented Mar 5, 2026

Added no-api-surface-area-change because it's an internal API and it's not used by any service clients today

@zoewangg zoewangg enabled auto-merge March 5, 2026 21:40
@sonarqubecloud
Copy link

sonarqubecloud bot commented Mar 5, 2026

Quality Gate Failed Quality Gate failed

Failed conditions
28.6% Coverage on New Code (required ≥ 80%)

See analysis details on SonarQube Cloud

@zoewangg zoewangg added this pull request to the merge queue Mar 6, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 6, 2026
@zoewangg zoewangg added this pull request to the merge queue Mar 6, 2026
@github-merge-queue github-merge-queue bot removed this pull request from the merge queue due to failed status checks Mar 6, 2026
@zoewangg zoewangg added this pull request to the merge queue Mar 6, 2026
Merged via the queue into master with commit 9a36a37 Mar 6, 2026
55 of 58 checks passed
@github-actions
Copy link

github-actions bot commented Mar 6, 2026

This pull request has been closed and the conversation has been locked. Comments on closed PRs are hard for our team to see. If you need more assistance, please open a new issue that references this one.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators Mar 6, 2026
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

no-api-surface-area-change Indicate there is no API surface area change and thus API surface area review is not required

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants