use of io.grpc.CallOptions in project grpc-java by grpc.
the class StubConfigTest method testStubCallOptionsPopulatedToNewCall.
@Test
public void testStubCallOptionsPopulatedToNewCall() {
TestServiceGrpc.TestServiceStub stub = TestServiceGrpc.newStub(channel);
CallOptions options1 = stub.getCallOptions();
SimpleRequest request = SimpleRequest.getDefaultInstance();
stub.unaryCall(request, responseObserver);
verify(channel).newCall(same(TestServiceGrpc.METHOD_UNARY_CALL), same(options1));
stub = stub.withDeadlineAfter(2, NANOSECONDS);
CallOptions options2 = stub.getCallOptions();
assertNotSame(options1, options2);
stub.unaryCall(request, responseObserver);
verify(channel).newCall(same(TestServiceGrpc.METHOD_UNARY_CALL), same(options2));
}
use of io.grpc.CallOptions in project grpc-java by grpc.
the class HeaderServerInterceptorTest method serverHeaderDeliveredToClient.
@Test
public void serverHeaderDeliveredToClient() {
class SpyingClientInterceptor implements ClientInterceptor {
ClientCall.Listener<?> spyListener;
@Override
public <ReqT, RespT> ClientCall<ReqT, RespT> interceptCall(MethodDescriptor<ReqT, RespT> method, CallOptions callOptions, Channel next) {
return new SimpleForwardingClientCall<ReqT, RespT>(next.newCall(method, callOptions)) {
@Override
public void start(Listener<RespT> responseListener, Metadata headers) {
spyListener = responseListener = spy(responseListener);
super.start(responseListener, headers);
}
};
}
}
SpyingClientInterceptor clientInterceptor = new SpyingClientInterceptor();
GreeterBlockingStub blockingStub = GreeterGrpc.newBlockingStub(inProcessChannel).withInterceptors(clientInterceptor);
ArgumentCaptor<Metadata> metadataCaptor = ArgumentCaptor.forClass(Metadata.class);
blockingStub.sayHello(HelloRequest.getDefaultInstance());
assertNotNull(clientInterceptor.spyListener);
verify(clientInterceptor.spyListener).onHeaders(metadataCaptor.capture());
assertEquals("customRespondValue", metadataCaptor.getValue().get(HeaderServerInterceptor.CUSTOM_HEADER_KEY));
}
use of io.grpc.CallOptions in project grpc-java by grpc.
the class AbstractStubTest method withWaitForReady.
@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());
}
Aggregations