-
Notifications
You must be signed in to change notification settings - Fork 16
Emit static responses exactly once regardless of subscriber demand shape #636
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
slinkydeveloper
merged 2 commits into
restatedev:main
from
nikhiln64:fix/http-vertx-response-backpressure
Jul 14, 2026
+108
−0
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
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
98 changes: 98 additions & 0 deletions
98
sdk-core/src/test/java/dev/restate/sdk/core/StaticResponseRequestProcessorTest.java
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
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,98 @@ | ||
| // Copyright (c) 2023 - Restate Software, Inc., Restate GmbH | ||
| // | ||
| // This file is part of the Restate Java SDK, | ||
| // which is released under the MIT license. | ||
| // | ||
| // You can find a copy of the license in file LICENSE in the root | ||
| // directory of this repository or package, or at | ||
| // https://github.com/restatedev/sdk-java/blob/main/LICENSE | ||
| package dev.restate.sdk.core; | ||
|
|
||
| import static org.assertj.core.api.Assertions.assertThat; | ||
|
|
||
| import dev.restate.common.Slice; | ||
| import java.util.ArrayList; | ||
| import java.util.List; | ||
| import java.util.concurrent.Flow; | ||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| /** | ||
| * The static response (discovery, health) must be emitted exactly once, no matter how the | ||
| * subscriber shapes its demand (Reactive Streams rules 1.7/2.12). Before this test, every {@code | ||
| * request()} call re-emitted the whole body and re-signalled completion, which duplicated the | ||
| * discovery response as soon as a subscriber used bounded per-item requests instead of a single | ||
| * {@code request(Long.MAX_VALUE)}. | ||
| */ | ||
| class StaticResponseRequestProcessorTest { | ||
|
|
||
| @Test | ||
| void shouldEmitTheResponseBodyExactlyOnceForBoundedDemand() { | ||
| StaticResponseRequestProcessor processor = | ||
| new StaticResponseRequestProcessor(200, "application/json", Slice.wrap("{\"a\":1}")); | ||
| RecordingSubscriber subscriber = new RecordingSubscriber(); | ||
|
|
||
| processor.subscribe(subscriber); | ||
| subscriber.subscription.request(1); | ||
| // A well-behaved publisher must ignore further demand after completion | ||
| subscriber.subscription.request(1); | ||
| subscriber.subscription.request(Long.MAX_VALUE); | ||
|
|
||
| assertThat(subscriber.received).hasSize(1); | ||
| assertThat(subscriber.completions).isEqualTo(1); | ||
| assertThat(subscriber.errors).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldEmitTheResponseBodyExactlyOnceForUnboundedDemand() { | ||
| StaticResponseRequestProcessor processor = | ||
| new StaticResponseRequestProcessor(200, "application/json", Slice.wrap("{\"a\":1}")); | ||
| RecordingSubscriber subscriber = new RecordingSubscriber(); | ||
|
|
||
| processor.subscribe(subscriber); | ||
| subscriber.subscription.request(Long.MAX_VALUE); | ||
|
|
||
| assertThat(subscriber.received).hasSize(1); | ||
| assertThat(subscriber.completions).isEqualTo(1); | ||
| assertThat(subscriber.errors).isEmpty(); | ||
| } | ||
|
|
||
| @Test | ||
| void shouldSignalAnErrorForNonPositiveDemand() { | ||
| StaticResponseRequestProcessor processor = | ||
| new StaticResponseRequestProcessor(200, "application/json", Slice.wrap("{\"a\":1}")); | ||
| RecordingSubscriber subscriber = new RecordingSubscriber(); | ||
|
|
||
| processor.subscribe(subscriber); | ||
| subscriber.subscription.request(0); | ||
|
|
||
| assertThat(subscriber.received).isEmpty(); | ||
| assertThat(subscriber.errors).hasSize(1); | ||
| } | ||
|
|
||
| private static final class RecordingSubscriber implements Flow.Subscriber<Slice> { | ||
| private Flow.Subscription subscription; | ||
| private final List<Slice> received = new ArrayList<>(); | ||
| private final List<Throwable> errors = new ArrayList<>(); | ||
| private int completions = 0; | ||
|
|
||
| @Override | ||
| public void onSubscribe(Flow.Subscription subscription) { | ||
| this.subscription = subscription; | ||
| } | ||
|
|
||
| @Override | ||
| public void onNext(Slice slice) { | ||
| received.add(slice); | ||
| } | ||
|
|
||
| @Override | ||
| public void onError(Throwable throwable) { | ||
| errors.add(throwable); | ||
| } | ||
|
|
||
| @Override | ||
| public void onComplete() { | ||
| completions++; | ||
| } | ||
| } | ||
| } |
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.