Search in sources :

Example 1 with ServerStreamListenerImpl

use of io.grpc.internal.ServerCallImpl.ServerStreamListenerImpl in project grpc-java by grpc.

the class ServerCallImplTest method streamListener_messageRead_onlyOnce.

@Test
public void streamListener_messageRead_onlyOnce() {
    ServerStreamListenerImpl<Long> streamListener = new ServerCallImpl.ServerStreamListenerImpl<>(call, callListener, context);
    streamListener.messagesAvailable(new SingleMessageProducer(UNARY_METHOD.streamRequest(1234L)));
    // canceling the call should short circuit future halfClosed() calls.
    streamListener.closed(Status.CANCELLED);
    streamListener.messagesAvailable(new SingleMessageProducer(UNARY_METHOD.streamRequest(1234L)));
    verify(callListener).onMessage(1234L);
}
Also used : SingleMessageProducer(io.grpc.internal.testing.SingleMessageProducer) ServerStreamListenerImpl(io.grpc.internal.ServerCallImpl.ServerStreamListenerImpl) Test(org.junit.Test)

Example 2 with ServerStreamListenerImpl

use of io.grpc.internal.ServerCallImpl.ServerStreamListenerImpl in project grpc-java by grpc.

the class ServerCallImplTest method streamListener_unexpectedRuntimeException.

@Test
public void streamListener_unexpectedRuntimeException() {
    ServerStreamListenerImpl<Long> streamListener = new ServerCallImpl.ServerStreamListenerImpl<>(call, callListener, context);
    doThrow(new RuntimeException("unexpected exception")).when(callListener).onMessage(any(Long.class));
    InputStream inputStream = UNARY_METHOD.streamRequest(1234L);
    thrown.expect(RuntimeException.class);
    thrown.expectMessage("unexpected exception");
    streamListener.messagesAvailable(new SingleMessageProducer(inputStream));
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) SingleMessageProducer(io.grpc.internal.testing.SingleMessageProducer) ServerStreamListenerImpl(io.grpc.internal.ServerCallImpl.ServerStreamListenerImpl) Test(org.junit.Test)

Example 3 with ServerStreamListenerImpl

use of io.grpc.internal.ServerCallImpl.ServerStreamListenerImpl in project grpc-java by grpc.

the class ServerCallImplTest method streamListener_messageRead.

@Test
public void streamListener_messageRead() {
    ServerStreamListenerImpl<Long> streamListener = new ServerCallImpl.ServerStreamListenerImpl<>(call, callListener, context);
    streamListener.messagesAvailable(new SingleMessageProducer(UNARY_METHOD.streamRequest(1234L)));
    verify(callListener).onMessage(1234L);
}
Also used : SingleMessageProducer(io.grpc.internal.testing.SingleMessageProducer) ServerStreamListenerImpl(io.grpc.internal.ServerCallImpl.ServerStreamListenerImpl) Test(org.junit.Test)

Aggregations

ServerStreamListenerImpl (io.grpc.internal.ServerCallImpl.ServerStreamListenerImpl)3 SingleMessageProducer (io.grpc.internal.testing.SingleMessageProducer)3 Test (org.junit.Test)3 ByteArrayInputStream (java.io.ByteArrayInputStream)1 InputStream (java.io.InputStream)1