Skip to content

Commit 6dc4633

Browse files
authored
stub: add withWaitForReady
1 parent c1a7984 commit 6dc4633

File tree

2 files changed

+32
-2
lines changed

2 files changed

+32
-2
lines changed

stub/src/main/java/io/grpc/stub/AbstractStub.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -181,4 +181,12 @@ public final S withInterceptors(ClientInterceptor... interceptors) {
181181
public final S withCallCredentials(CallCredentials credentials) {
182182
return build(channel, callOptions.withCallCredentials(credentials));
183183
}
184+
185+
/**
186+
* Returns a new stub that uses the 'wait for ready' call option.
187+
*/
188+
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1915")
189+
public final S withWaitForReady() {
190+
return build(channel, callOptions.withWaitForReady());
191+
}
184192
}

stub/src/test/java/io/grpc/stub/AbstractStubTest.java

Lines changed: 24 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,19 +31,30 @@
3131

3232
package io.grpc.stub;
3333

34+
import static org.junit.Assert.assertFalse;
35+
import static org.junit.Assert.assertTrue;
36+
3437
import io.grpc.CallOptions;
3538
import io.grpc.Channel;
39+
40+
import org.junit.Before;
3641
import org.junit.Test;
3742
import org.junit.runner.RunWith;
3843
import org.junit.runners.JUnit4;
3944
import org.mockito.Mock;
45+
import org.mockito.MockitoAnnotations;
4046

4147
@RunWith(JUnit4.class)
4248
public class AbstractStubTest {
4349

4450
@Mock
4551
Channel channel;
4652

53+
@Before
54+
public void setup() {
55+
MockitoAnnotations.initMocks(this);
56+
}
57+
4758
@Test(expected = NullPointerException.class)
4859
public void channelMustNotBeNull() {
4960
new NoopStub(null);
@@ -55,8 +66,19 @@ public void callOptionsMustNotBeNull() {
5566
}
5667

5768
@Test(expected = NullPointerException.class)
58-
public void callOptionsAndChannelMustNotBeNull() {
59-
new NoopStub(null, null);
69+
public void channelMustNotBeNull2() {
70+
new NoopStub(null, CallOptions.DEFAULT);
71+
}
72+
73+
@Test()
74+
public void withWaitForReady() {
75+
NoopStub stub = new NoopStub(channel);
76+
CallOptions callOptions = stub.getCallOptions();
77+
assertFalse(callOptions.isWaitForReady());
78+
79+
stub = stub.withWaitForReady();
80+
callOptions = stub.getCallOptions();
81+
assertTrue(callOptions.isWaitForReady());
6082
}
6183

6284
class NoopStub extends AbstractStub<NoopStub> {

0 commit comments

Comments
 (0)