io.grpc.ClientCall.Listener Java Examples

The following examples show how to use io.grpc.ClientCall.Listener. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: LoggingInterceptorTest.java    From google-ads-java with Apache License 2.0 6 votes vote down vote up
private static Listener simulateCall(
    RequestLogger requestLogger,
    Detail detail,
    Summary summary,
    MethodDescriptor methodDescriptor,
    Channel nextChannel,
    ClientCall nextCall) {
  LoggingInterceptor interceptor =
      new LoggingInterceptor(requestLogger, detail.getRawRequestHeaders(), summary.getEndpoint());

  // Simulate a call (mocked channel doesn't actually make a call).
  ClientCall call = interceptor.interceptCall(methodDescriptor, null, nextChannel);
  Metadata upstreamHeaders = new Metadata();
  call.start(new Listener() {}, upstreamHeaders);
  call.sendMessage(detail.getRequest());

  // Capture the response listener and return this so we can test with different responses.
  ArgumentCaptor<Listener> listenerCaptor = ArgumentCaptor.forClass(Listener.class);
  verify(nextCall).start(listenerCaptor.capture(), eq(upstreamHeaders));
  return listenerCaptor.getValue();
}
 
Example #2
Source File: CompressionTest.java    From grpc-nebula-java with Apache License 2.0 5 votes vote down vote up
@Override
public <ReqT, RespT> io.grpc.ServerCall.Listener<ReqT> interceptCall(
    ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
  if (serverEncoding) {
    call.setCompression("fzip");
  }
  call.setMessageCompression(enableServerMessageCompression);
  Metadata headersCopy = new Metadata();
  headersCopy.merge(headers);
  serverResponseHeaders = headersCopy;
  return next.startCall(call, headers);
}
 
Example #3
Source File: CompressionTest.java    From grpc-java with Apache License 2.0 5 votes vote down vote up
@Override
public <ReqT, RespT> io.grpc.ServerCall.Listener<ReqT> interceptCall(
    ServerCall<ReqT, RespT> call, Metadata headers, ServerCallHandler<ReqT, RespT> next) {
  if (serverEncoding) {
    call.setCompression("fzip");
  }
  call.setMessageCompression(enableServerMessageCompression);
  Metadata headersCopy = new Metadata();
  headersCopy.merge(headers);
  serverResponseHeaders = headersCopy;
  return next.startCall(call, headers);
}
 
Example #4
Source File: TracingClientInterceptor.java    From brave with Apache License 2.0 5 votes vote down vote up
@Override public void start(Listener<RespT> responseListener, Metadata headers) {
  GrpcClientRequest request =
    new GrpcClientRequest(nameToKey, method, callOptions, delegate(), headers);

  Span span = handler.handleSendWithParent(request, invocationContext);
  spanRef.set(span);

  responseListener = new TracingClientCallListener<>(
    responseListener,
    invocationContext,
    spanRef,
    request
  );

  try (Scope scope = currentTraceContext.maybeScope(span.context())) {
    super.start(responseListener, headers);
  } catch (Throwable e) {
    propagateIfFatal(e);

    // Another interceptor may throw an exception during start, in which case no other
    // callbacks are called, so go ahead and close the span here.
    //
    // See instrumentation/grpc/RATIONALE.md for why we don't use the handler here
    spanRef.set(null);
    if (span != null) span.error(e).finish();
    throw e;
  }
}
 
Example #5
Source File: TracingClientInterceptor.java    From brave with Apache License 2.0 5 votes vote down vote up
TracingClientCallListener(
  Listener<RespT> delegate,
  @Nullable TraceContext invocationContext,
  AtomicReference<Span> spanRef,
  GrpcClientRequest request
) {
  super(delegate);
  this.invocationContext = invocationContext;
  this.spanRef = spanRef;
  this.request = request;
}
 
Example #6
Source File: CompressionTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
@Override
public void start(io.grpc.ClientCall.Listener<RespT> responseListener, Metadata headers) {
  super.start(new ClientHeadersCapture<RespT>(responseListener), headers);
  setMessageCompression(enableClientMessageCompression);
}
 
Example #7
Source File: CompressionTest.java    From grpc-nebula-java with Apache License 2.0 4 votes vote down vote up
private ClientHeadersCapture(Listener<RespT> delegate) {
  super(delegate);
}
 
Example #8
Source File: LoggingInterceptorTest.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private void runCall(BiConsumer<Listener, Detail> callback) {
  Detail detail = createDetail();
  Summary summary = createSummary();
  runCall(callback, detail, summary);
}
 
Example #9
Source File: LoggingInterceptorTest.java    From google-ads-java with Apache License 2.0 4 votes vote down vote up
private void runCall(BiConsumer<Listener, Detail> callback, Detail detail, Summary summary) {
  Listener listener =
      simulateCall(requestLogger, detail, summary, methodDescriptor, nextChannel, nextCall);
  callback.accept(listener, detail);
  verifyLoggers(detail, summary, detailLogger, summaryLogger);
}
 
Example #10
Source File: CompressionTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
@Override
public void start(io.grpc.ClientCall.Listener<RespT> responseListener, Metadata headers) {
  super.start(new ClientHeadersCapture<>(responseListener), headers);
  setMessageCompression(enableClientMessageCompression);
}
 
Example #11
Source File: CompressionTest.java    From grpc-java with Apache License 2.0 4 votes vote down vote up
private ClientHeadersCapture(Listener<RespT> delegate) {
  super(delegate);
}