stub: add withWaitForReady

This commit is contained in:
ZHANG Dapeng 2016-11-28 18:13:22 -08:00 committed by GitHub
parent c1a798486b
commit 6dc4633bdd
2 changed files with 32 additions and 2 deletions

View File

@ -181,4 +181,12 @@ public abstract class AbstractStub<S extends AbstractStub<S>> {
public final S withCallCredentials(CallCredentials credentials) {
return build(channel, callOptions.withCallCredentials(credentials));
}
/**
* Returns a new stub that uses the 'wait for ready' call option.
*/
@ExperimentalApi("https://github.com/grpc/grpc-java/issues/1915")
public final S withWaitForReady() {
return build(channel, callOptions.withWaitForReady());
}
}

View File

@ -31,12 +31,18 @@
package io.grpc.stub;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertTrue;
import io.grpc.CallOptions;
import io.grpc.Channel;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.junit.runners.JUnit4;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
@RunWith(JUnit4.class)
public class AbstractStubTest {
@ -44,6 +50,11 @@ public class AbstractStubTest {
@Mock
Channel channel;
@Before
public void setup() {
MockitoAnnotations.initMocks(this);
}
@Test(expected = NullPointerException.class)
public void channelMustNotBeNull() {
new NoopStub(null);
@ -55,8 +66,19 @@ public class AbstractStubTest {
}
@Test(expected = NullPointerException.class)
public void callOptionsAndChannelMustNotBeNull() {
new NoopStub(null, null);
public void channelMustNotBeNull2() {
new NoopStub(null, CallOptions.DEFAULT);
}
@Test()
public void withWaitForReady() {
NoopStub stub = new NoopStub(channel);
CallOptions callOptions = stub.getCallOptions();
assertFalse(callOptions.isWaitForReady());
stub = stub.withWaitForReady();
callOptions = stub.getCallOptions();
assertTrue(callOptions.isWaitForReady());
}
class NoopStub extends AbstractStub<NoopStub> {