use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.CallOptions in project grpc-java by grpc.
the class AbstractBlockingStubTest method newStub_futureStub_throwsException.
@Test
@SuppressWarnings("AssertionFailureIgnored")
public void newStub_futureStub_throwsException() {
try {
NoopFutureStub unused = NoopBlockingStub.newStub(new StubFactory<NoopFutureStub>() {
@Override
public NoopFutureStub newStub(Channel channel, CallOptions callOptions) {
return new NoopFutureStub(channel, callOptions);
}
}, channel, CallOptions.DEFAULT);
fail("should not reach here");
} catch (AssertionError e) {
assertThat(e).hasMessageThat().startsWith("Expected AbstractBlockingStub");
}
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.CallOptions in project grpc-java by grpc.
the class AbstractStubTest method defaultCallOptions.
@Test
public void defaultCallOptions() {
NoopStub stub = NoopStub.newStub(new StubFactory<NoopStub>() {
@Override
public NoopStub newStub(Channel channel, CallOptions callOptions) {
return create(channel, callOptions);
}
}, channel, CallOptions.DEFAULT);
assertThat(stub.getCallOptions().getOption(ClientCalls.STUB_TYPE_OPTION)).isNull();
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.CallOptions in project grpc-java by grpc.
the class BinderChannelSmokeTest method testSingleRequestCallOptionHeaders.
@Test
public void testSingleRequestCallOptionHeaders() throws Exception {
CallOptions callOptions = CallOptions.DEFAULT.withDeadlineAfter(1234, MINUTES);
assertThat(doCall(method, "Hello", callOptions).get()).isEqualTo("Hello");
assertThat(headersCapture.get().get(GrpcUtil.TIMEOUT_KEY)).isGreaterThan(0);
}
use of org.apache.beam.vendor.grpc.v1p43p2.io.grpc.CallOptions in project grpc-java by grpc.
the class BinderChannelSmokeTest method testStreamingCallOptionHeaders.
@Test
public void testStreamingCallOptionHeaders() throws Exception {
CallOptions callOptions = CallOptions.DEFAULT.withDeadlineAfter(1234, MINUTES);
QueueingStreamObserver<String> responseStreamObserver = new QueueingStreamObserver<>();
StreamObserver<String> streamObserver = ClientCalls.asyncBidiStreamingCall(channel.newCall(bidiMethod, callOptions), responseStreamObserver);
streamObserver.onCompleted();
assertThat(withTestTimeout(responseStreamObserver.getAllStreamElements()).get()).isEmpty();
assertThat(headersCapture.get().get(GrpcUtil.TIMEOUT_KEY)).isGreaterThan(0);
}
use of org.apache.beam.vendor.grpc.v1p43p2.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 = mock(ClientCall.Listener.class, delegatesTo(responseListener));
super.start(responseListener, headers);
}
};
}
}
SpyingClientInterceptor clientInterceptor = new SpyingClientInterceptor();
GreeterBlockingStub blockingStub = GreeterGrpc.newBlockingStub(channel).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));
}
Aggregations