Skip to content
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

grpc-java supports onReadyThreshold property setting #11320

Merged
merged 1 commit into from
Jun 27, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions api/src/main/java/io/grpc/CallOptions.java
Original file line number Diff line number Diff line change
Expand Up @@ -512,6 +512,7 @@ private static Builder toBuilder(CallOptions other) {
builder.waitForReady = other.waitForReady;
builder.maxInboundMessageSize = other.maxInboundMessageSize;
builder.maxOutboundMessageSize = other.maxOutboundMessageSize;
builder.onReadyThreshold = other.onReadyThreshold;
return builder;
}

Expand All @@ -527,6 +528,7 @@ public String toString() {
.add("waitForReady", isWaitForReady())
.add("maxInboundMessageSize", maxInboundMessageSize)
.add("maxOutboundMessageSize", maxOutboundMessageSize)
.add("onReadyThreshold", onReadyThreshold)
.add("streamTracerFactories", streamTracerFactories)
.toString();
}
Expand Down
12 changes: 12 additions & 0 deletions api/src/test/java/io/grpc/CallOptionsTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,16 @@ public void withAndWithoutWaitForReady() {
.isFalse();
}

@Test
public void withOnReadyThreshold() {
int onReadyThreshold = 1024;
CallOptions callOptions = CallOptions.DEFAULT.withOnReadyThreshold(onReadyThreshold);
callOptions = callOptions.withWaitForReady();
assertThat(callOptions.getOnReadyThreshold()).isEqualTo(onReadyThreshold);
callOptions = callOptions.clearOnReadyThreshold();
assertThat(callOptions.getOnReadyThreshold()).isNull();
}

@Test
public void allWiths() {
assertThat(allSet.getAuthority()).isSameInstanceAs(sampleAuthority);
Expand Down Expand Up @@ -148,6 +158,7 @@ public void toStringMatches_noDeadline_default() {
.withCallCredentials(null)
.withMaxInboundMessageSize(44)
.withMaxOutboundMessageSize(55)
.withOnReadyThreshold(1024)
.toString();

assertThat(actual).contains("deadline=null");
Expand All @@ -159,6 +170,7 @@ public void toStringMatches_noDeadline_default() {
assertThat(actual).contains("waitForReady=true");
assertThat(actual).contains("maxInboundMessageSize=44");
assertThat(actual).contains("maxOutboundMessageSize=55");
assertThat(actual).contains("onReadyThreshold=1024");
assertThat(actual).contains("streamTracerFactories=[tracerFactory1, tracerFactory2]");
}

Expand Down
10 changes: 10 additions & 0 deletions stub/src/main/java/io/grpc/stub/AbstractStub.java
Original file line number Diff line number Diff line change
Expand Up @@ -252,6 +252,16 @@ public final S withMaxOutboundMessageSize(int maxSize) {
return build(channel, callOptions.withMaxOutboundMessageSize(maxSize));
}

/**
* Returns a new stub that limits the maximum number of bytes per stream in the queue.
*
* @since 1.1.0
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/11021")
public final S withOnReadyThreshold(int numBytes) {
return build(channel, callOptions.withOnReadyThreshold(numBytes));
}

/**
* A factory class for stub.
*
Expand Down
13 changes: 13 additions & 0 deletions stub/src/test/java/io/grpc/stub/BaseAbstractStubTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@

package io.grpc.stub;

import static com.google.common.truth.Truth.assertThat;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNull;
Expand Down Expand Up @@ -90,4 +91,16 @@ public void withExecutor() {

assertEquals(callOptions.getExecutor(), executor);
}

@Test
public void withOnReadyThreshold() {
T stub = create(channel);
CallOptions callOptions = stub.getCallOptions();
assertNull(callOptions.getOnReadyThreshold());

int onReadyThreshold = 1024;
stub = stub.withOnReadyThreshold(onReadyThreshold);
callOptions = stub.getCallOptions();
assertThat(callOptions.getOnReadyThreshold()).isEqualTo(onReadyThreshold);
}
}
Loading