use of io.grpc.ClientCall.Listener in project grpc-java by grpc.
the class DelayedClientCallTest method listenerEventsPropagated.
@Test
public void listenerEventsPropagated() {
DelayedClientCall<String, Integer> delayedClientCall = new DelayedClientCall<>(callExecutor, fakeClock.getScheduledExecutorService(), Deadline.after(10, SECONDS));
delayedClientCall.start(listener, new Metadata());
delayedClientCall.setCall(mockRealCall);
ArgumentCaptor<Listener<Integer>> listenerCaptor = ArgumentCaptor.forClass(null);
verify(mockRealCall).start(listenerCaptor.capture(), any(Metadata.class));
Listener<Integer> realCallListener = listenerCaptor.getValue();
Metadata metadata = new Metadata();
metadata.put(Metadata.Key.of("key", Metadata.ASCII_STRING_MARSHALLER), "value");
realCallListener.onHeaders(metadata);
verify(listener).onHeaders(metadata);
realCallListener.onMessage(3);
verify(listener).onMessage(3);
realCallListener.onReady();
verify(listener).onReady();
Metadata trailer = new Metadata();
trailer.put(Metadata.Key.of("key2", Metadata.ASCII_STRING_MARSHALLER), "value2");
realCallListener.onClose(Status.DATA_LOSS, trailer);
verify(listener).onClose(statusCaptor.capture(), eq(trailer));
assertThat(statusCaptor.getValue().getCode()).isEqualTo(Status.Code.DATA_LOSS);
}