FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

fix: Fix watchdog to start with WAITING state by mutianf · Pull Request #2468 · googleapis/sdk-platform-java · GitHub

This repository was archived by the owner on May 14, 2026. It is now read-only.
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension .java  (2) All 1 file type selected
Viewed files
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Unified
Split
Hide whitespace
Diff view
Unified
Split
Hide whitespace
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
Expand Up @@ -193,8 +193,11 @@ class WatchdogStream<ResponseT> extends StateCheckingResponseObserver<ResponseT>
private final ResponseObserver<ResponseT> outerResponseObserver;
private volatile StreamController innerController;

// When a stream is created it has automatic inbound flow control enabled. The stream
// won't wait for the caller to request a message. Setting the default to WAITING
// to reflect this state.
@GuardedBy("lock")
private State state = State.IDLE;
Comment thread
mutianf marked this conversation as resolved.
private State state = State.WAITING;

@GuardedBy("lock")
private int pendingCount = 0;
Expand All @@ -220,6 +223,16 @@ public void onStartImpl(StreamController controller) {
public void disableAutoInboundFlowControl() {
Preconditions.checkState(
!hasStarted, "Can't disable automatic flow control after the stream has started");

// Adding the lock only to satisfy the annotation. It doesn't matter because before
// the stream is started, this is only accessed by the caller.
synchronized (lock) {
Comment thread
mutianf marked this conversation as resolved.
// When auto flow control is disabled, caller needs to call onRequest() to request a
// message. Setting the state to IDLE because now we're waiting for caller to call
// onRequest().
state = State.IDLE;
}

autoAutoFlowControl = false;
innerController.disableAutoInboundFlowControl();
}
Expand Down
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
Expand Up @@ -154,6 +154,31 @@ public void testTimedOutBeforeStart() throws InterruptedException {
assertThat(error).isInstanceOf(WatchdogTimeoutException.class);
}

@Test
public void testTimedOutBeforeResponse() throws InterruptedException {
MockServerStreamingCallable<String, String> autoFlowControlCallable =
new MockServerStreamingCallable<>();
AutoFlowControlObserver<String> downstreamObserver = new AutoFlowControlObserver<>();

autoFlowControlCallable.call("request", watchdog.watch(downstreamObserver, waitTime, idleTime));
MockServerStreamingCall<String, String> call1 = autoFlowControlCallable.popLastCall();

clock.incrementNanoTime(idleTime.toNanos() + 1);
watchdog.run();
assertThat(downstreamObserver.done.isDone()).isFalse();
assertThat(call1.getController().isCancelled()).isTrue();
call1.getController().getObserver().onError(new CancellationException("cancelled"));
Comment thread
lqiu96 marked this conversation as resolved.

Throwable actualError = null;
try {
downstreamObserver.done.get();
} catch (ExecutionException e) {
actualError = e.getCause();
}
assertThat(actualError).isInstanceOf(WatchdogTimeoutException.class);
assertThat(actualError.getMessage()).contains("waiting for next response");
Comment thread
lqiu96 marked this conversation as resolved.
}

@Test
public void testMultiple() throws Exception {
// Start stream1
Expand Down Expand Up @@ -310,4 +335,30 @@ public void onComplete() {
done.set(null);
}
}

static class AutoFlowControlObserver<T> implements ResponseObserver<T> {
SettableApiFuture<StreamController> controller = SettableApiFuture.create();
Queue<T> responses = Queues.newLinkedBlockingDeque();
SettableApiFuture<Void> done = SettableApiFuture.create();

@Override
public void onStart(StreamController controller) {
this.controller.set(controller);
}

@Override
public void onResponse(T response) {
responses.add(response);
}

@Override
public void onError(Throwable t) {
done.setException(t);
}

@Override
public void onComplete() {
done.set(null);
}
}
}

Back | FazBrowse Home | New Git URL