mirror of https://github.com/grpc/grpc-java.git
stub: add withWaitForReady
This commit is contained in:
parent
c1a798486b
commit
6dc4633bdd
|
|
@ -181,4 +181,12 @@ public abstract class AbstractStub<S extends AbstractStub<S>> {
|
||||||
public final S withCallCredentials(CallCredentials credentials) {
|
public final S withCallCredentials(CallCredentials credentials) {
|
||||||
return build(channel, callOptions.withCallCredentials(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());
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
|
||||||
|
|
@ -31,12 +31,18 @@
|
||||||
|
|
||||||
package io.grpc.stub;
|
package io.grpc.stub;
|
||||||
|
|
||||||
|
import static org.junit.Assert.assertFalse;
|
||||||
|
import static org.junit.Assert.assertTrue;
|
||||||
|
|
||||||
import io.grpc.CallOptions;
|
import io.grpc.CallOptions;
|
||||||
import io.grpc.Channel;
|
import io.grpc.Channel;
|
||||||
|
|
||||||
|
import org.junit.Before;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
import org.junit.runner.RunWith;
|
import org.junit.runner.RunWith;
|
||||||
import org.junit.runners.JUnit4;
|
import org.junit.runners.JUnit4;
|
||||||
import org.mockito.Mock;
|
import org.mockito.Mock;
|
||||||
|
import org.mockito.MockitoAnnotations;
|
||||||
|
|
||||||
@RunWith(JUnit4.class)
|
@RunWith(JUnit4.class)
|
||||||
public class AbstractStubTest {
|
public class AbstractStubTest {
|
||||||
|
|
@ -44,6 +50,11 @@ public class AbstractStubTest {
|
||||||
@Mock
|
@Mock
|
||||||
Channel channel;
|
Channel channel;
|
||||||
|
|
||||||
|
@Before
|
||||||
|
public void setup() {
|
||||||
|
MockitoAnnotations.initMocks(this);
|
||||||
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void channelMustNotBeNull() {
|
public void channelMustNotBeNull() {
|
||||||
new NoopStub(null);
|
new NoopStub(null);
|
||||||
|
|
@ -55,8 +66,19 @@ public class AbstractStubTest {
|
||||||
}
|
}
|
||||||
|
|
||||||
@Test(expected = NullPointerException.class)
|
@Test(expected = NullPointerException.class)
|
||||||
public void callOptionsAndChannelMustNotBeNull() {
|
public void channelMustNotBeNull2() {
|
||||||
new NoopStub(null, null);
|
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> {
|
class NoopStub extends AbstractStub<NoopStub> {
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue