Class StreamRecorder<T>

java.lang.Object
io.grpc.internal.testing.StreamRecorder<T>
All Implemented Interfaces:
io.grpc.stub.StreamObserver<T>

public class StreamRecorder<T> extends Object implements io.grpc.stub.StreamObserver<T>
Utility implementation of StreamObserver used in testing. Records all the observed values produced by the stream as well as any errors.
  • Field Details

    • latch

      private final CountDownLatch latch
    • results

      private final List<T> results
    • error

      private Throwable error
    • firstValue

      private final com.google.common.util.concurrent.SettableFuture<T> firstValue
  • Constructor Details

    • StreamRecorder

      private StreamRecorder()
  • Method Details

    • create

      public static <T> StreamRecorder<T> create()
      Creates a new recorder.
    • onNext

      public void onNext(T value)
      Specified by:
      onNext in interface io.grpc.stub.StreamObserver<T>
    • onError

      public void onError(Throwable t)
      Specified by:
      onError in interface io.grpc.stub.StreamObserver<T>
    • onCompleted

      public void onCompleted()
      Specified by:
      onCompleted in interface io.grpc.stub.StreamObserver<T>
    • awaitCompletion

      public void awaitCompletion() throws Exception
      Waits for the stream to terminate.
      Throws:
      Exception
    • awaitCompletion

      public boolean awaitCompletion(int timeout, TimeUnit unit) throws Exception
      Waits a fixed timeout for the stream to terminate.
      Throws:
      Exception
    • getValues

      public List<T> getValues()
      Returns the current set of received values.
    • getError

      @Nullable public Throwable getError()
      Returns the stream terminating error.
    • firstValue

      public com.google.common.util.concurrent.ListenableFuture<T> firstValue()
      Returns a ListenableFuture for the first value received from the stream. Useful for testing unary call patterns.