mirror of https://github.com/grpc/grpc-java.git
Support setting onReadyThreshold through AbstractStub
Add copy of the onReadyThreshold property when copying CallOptions(fix bug)
This commit is contained in:
parent
e7c3803b5a
commit
25a8b7c507
|
@ -512,6 +512,7 @@ public final class CallOptions {
|
||||||
builder.waitForReady = other.waitForReady;
|
builder.waitForReady = other.waitForReady;
|
||||||
builder.maxInboundMessageSize = other.maxInboundMessageSize;
|
builder.maxInboundMessageSize = other.maxInboundMessageSize;
|
||||||
builder.maxOutboundMessageSize = other.maxOutboundMessageSize;
|
builder.maxOutboundMessageSize = other.maxOutboundMessageSize;
|
||||||
|
builder.onReadyThreshold = other.onReadyThreshold;
|
||||||
return builder;
|
return builder;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -527,6 +528,7 @@ public final class CallOptions {
|
||||||
.add("waitForReady", isWaitForReady())
|
.add("waitForReady", isWaitForReady())
|
||||||
.add("maxInboundMessageSize", maxInboundMessageSize)
|
.add("maxInboundMessageSize", maxInboundMessageSize)
|
||||||
.add("maxOutboundMessageSize", maxOutboundMessageSize)
|
.add("maxOutboundMessageSize", maxOutboundMessageSize)
|
||||||
|
.add("onReadyThreshold", onReadyThreshold)
|
||||||
.add("streamTracerFactories", streamTracerFactories)
|
.add("streamTracerFactories", streamTracerFactories)
|
||||||
.toString();
|
.toString();
|
||||||
}
|
}
|
||||||
|
|
|
@ -81,6 +81,16 @@ public class CallOptionsTest {
|
||||||
.isFalse();
|
.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
|
@Test
|
||||||
public void allWiths() {
|
public void allWiths() {
|
||||||
assertThat(allSet.getAuthority()).isSameInstanceAs(sampleAuthority);
|
assertThat(allSet.getAuthority()).isSameInstanceAs(sampleAuthority);
|
||||||
|
@ -148,6 +158,7 @@ public class CallOptionsTest {
|
||||||
.withCallCredentials(null)
|
.withCallCredentials(null)
|
||||||
.withMaxInboundMessageSize(44)
|
.withMaxInboundMessageSize(44)
|
||||||
.withMaxOutboundMessageSize(55)
|
.withMaxOutboundMessageSize(55)
|
||||||
|
.withOnReadyThreshold(1024)
|
||||||
.toString();
|
.toString();
|
||||||
|
|
||||||
assertThat(actual).contains("deadline=null");
|
assertThat(actual).contains("deadline=null");
|
||||||
|
@ -159,6 +170,7 @@ public class CallOptionsTest {
|
||||||
assertThat(actual).contains("waitForReady=true");
|
assertThat(actual).contains("waitForReady=true");
|
||||||
assertThat(actual).contains("maxInboundMessageSize=44");
|
assertThat(actual).contains("maxInboundMessageSize=44");
|
||||||
assertThat(actual).contains("maxOutboundMessageSize=55");
|
assertThat(actual).contains("maxOutboundMessageSize=55");
|
||||||
|
assertThat(actual).contains("onReadyThreshold=1024");
|
||||||
assertThat(actual).contains("streamTracerFactories=[tracerFactory1, tracerFactory2]");
|
assertThat(actual).contains("streamTracerFactories=[tracerFactory1, tracerFactory2]");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -252,6 +252,16 @@ public abstract class AbstractStub<S extends AbstractStub<S>> {
|
||||||
return build(channel, callOptions.withMaxOutboundMessageSize(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.
|
* A factory class for stub.
|
||||||
*
|
*
|
||||||
|
|
|
@ -16,6 +16,7 @@
|
||||||
|
|
||||||
package io.grpc.stub;
|
package io.grpc.stub;
|
||||||
|
|
||||||
|
import static com.google.common.truth.Truth.assertThat;
|
||||||
import static org.junit.Assert.assertEquals;
|
import static org.junit.Assert.assertEquals;
|
||||||
import static org.junit.Assert.assertFalse;
|
import static org.junit.Assert.assertFalse;
|
||||||
import static org.junit.Assert.assertNull;
|
import static org.junit.Assert.assertNull;
|
||||||
|
@ -90,4 +91,16 @@ abstract class BaseAbstractStubTest<T extends AbstractStub<T>> {
|
||||||
|
|
||||||
assertEquals(callOptions.getExecutor(), executor);
|
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…
Reference in New Issue