public class StreamRecorder<T> extends Object implements StreamObserver<T>
StreamObserver
used in testing. Records all the observed
values produced by the stream as well as any errors.Modifier and Type | Method and Description |
---|---|
void |
awaitCompletion()
Waits for the stream to terminate.
|
boolean |
awaitCompletion(int timeout,
TimeUnit unit)
Waits a fixed timeout for the stream to terminate.
|
static <T> StreamRecorder<T> |
create()
Creates a new recorder.
|
ListenableFuture<T> |
firstValue()
Returns a
ListenableFuture for the first value received from the stream. |
Throwable |
getError()
Returns the stream terminating error.
|
List<T> |
getValues()
Returns the current set of received values.
|
void |
onCompleted()
Receives a notification of successful stream completion.
|
void |
onError(Throwable t)
Receives a terminating error from the stream.
|
void |
onValue(T value)
Receives a value from the stream.
|
public static <T> StreamRecorder<T> create()
public void onValue(T value)
StreamObserver
Can be called many times but is never called after StreamObserver.onError(Throwable)
or StreamObserver.onCompleted()
are called.
If an exception is thrown by an implementation the caller is expected to terminate the
stream by calling StreamObserver.onError(Throwable)
with the caught exception prior to
propagating it.
onValue
in interface StreamObserver<T>
value
- the value passed to the streampublic void onError(Throwable t)
StreamObserver
May only be called once and is never called after StreamObserver.onCompleted()
. In particular if
an exception is thrown by an implementation of onError
no further calls to any
method are allowed.
onError
in interface StreamObserver<T>
t
- the error occurred on the streampublic void onCompleted()
StreamObserver
May only be called once and is never called after StreamObserver.onError(Throwable)
. In particular
if an exception is thrown by an implementation of onCompleted
no further calls to
any method are allowed.
onCompleted
in interface StreamObserver<T>
public void awaitCompletion() throws Exception
Exception
public boolean awaitCompletion(int timeout, TimeUnit unit) throws Exception
Exception
public ListenableFuture<T> firstValue()
ListenableFuture
for the first value received from the stream. Useful
for testing unary call patterns.