api: expose if waitForReady has been set on CallOptions

This commit is contained in:
Carl Mastrangelo 2019-04-25 10:56:40 -07:00 committed by GitHub
parent ce6358e57f
commit 53a3f12666
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 49 additions and 3 deletions

View File

@ -69,7 +69,8 @@ public final class CallOptions {
/**
* Opposite to fail fast.
*/
private boolean waitForReady;
@Nullable
private Boolean waitForReady;
@Nullable
private Integer maxInboundMessageSize;
@ -154,7 +155,7 @@ public final class CallOptions {
*/
public CallOptions withWaitForReady() {
CallOptions newOptions = new CallOptions(this);
newOptions.waitForReady = true;
newOptions.waitForReady = Boolean.TRUE;
return newOptions;
}
@ -164,7 +165,7 @@ public final class CallOptions {
*/
public CallOptions withoutWaitForReady() {
CallOptions newOptions = new CallOptions(this);
newOptions.waitForReady = false;
newOptions.waitForReady = Boolean.FALSE;
return newOptions;
}
@ -369,6 +370,10 @@ public final class CallOptions {
* calls and 'wait for ready' is the opposite to it.
*/
public boolean isWaitForReady() {
return Boolean.TRUE.equals(waitForReady);
}
Boolean getWaitForReady() {
return waitForReady;
}

View File

@ -0,0 +1,32 @@
/*
* Copyright 2019 The gRPC Authors
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.grpc;
/**
* Internal accessor for {@link CallOptions}.
*/
@Internal
public final class InternalCallOptions {
private InternalCallOptions() {}
/**
* Gets the waitForReady bit or {@code null} if it was never set.
*/
public static Boolean getWaitForReady(CallOptions callOptions) {
return callOptions.getWaitForReady();
}
}

View File

@ -24,6 +24,8 @@ import static java.util.concurrent.TimeUnit.MILLISECONDS;
import static java.util.concurrent.TimeUnit.MINUTES;
import static java.util.concurrent.TimeUnit.NANOSECONDS;
import static java.util.concurrent.TimeUnit.SECONDS;
import static org.junit.Assert.assertNull;
import static org.junit.Assert.assertSame;
import static org.junit.Assert.fail;
import static org.mockito.Mockito.mock;
@ -234,6 +236,13 @@ public class CallOptionsTest {
}
}
@Test
public void getWaitForReady() {
assertNull(CallOptions.DEFAULT.getWaitForReady());
assertSame(CallOptions.DEFAULT.withWaitForReady().getWaitForReady(), Boolean.TRUE);
assertSame(CallOptions.DEFAULT.withoutWaitForReady().getWaitForReady(), Boolean.FALSE);
}
// Only used in noStrayModifications()
// TODO(carl-mastrangelo): consider making a CallOptionsSubject for Truth.
private static boolean equal(CallOptions o1, CallOptions o2) {