use of io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener in project grpc-java by grpc.
the class ServerImplTest method halfClosed_errorCancelsCall.
@Test
public void halfClosed_errorCancelsCall() {
JumpToApplicationThreadServerStreamListener listener = new JumpToApplicationThreadServerStreamListener(executor.getScheduledExecutorService(), stream, Context.ROOT.withCancellation());
ServerStreamListener mockListener = mock(ServerStreamListener.class);
listener.setListener(mockListener);
Throwable expectedT = new AssertionError();
doThrow(expectedT).when(mockListener).halfClosed();
listener.halfClosed();
try {
executor.runDueTasks();
fail("Expected exception");
} catch (Throwable t) {
assertSame(expectedT, t);
verify(stream).close(statusCaptor.capture(), any(Metadata.class));
assertSame(expectedT, statusCaptor.getValue().getCause());
}
}
use of io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener in project grpc-java by grpc.
the class ServerImplTest method halfClosed_runtimeExceptionCancelsCall.
@Test
public void halfClosed_runtimeExceptionCancelsCall() {
JumpToApplicationThreadServerStreamListener listener = new JumpToApplicationThreadServerStreamListener(executor.getScheduledExecutorService(), stream, Context.ROOT.withCancellation());
ServerStreamListener mockListener = mock(ServerStreamListener.class);
listener.setListener(mockListener);
Throwable expectedT = new RuntimeException();
doThrow(expectedT).when(mockListener).halfClosed();
listener.halfClosed();
try {
executor.runDueTasks();
fail("Expected exception");
} catch (Throwable t) {
assertSame(expectedT, t);
verify(stream).close(statusCaptor.capture(), any(Metadata.class));
assertSame(expectedT, statusCaptor.getValue().getCause());
}
}
use of io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener in project grpc-java by grpc.
the class ServerImplTest method messageRead_runtimeExceptionCancelsCall.
@Test
public void messageRead_runtimeExceptionCancelsCall() throws Exception {
JumpToApplicationThreadServerStreamListener listener = new JumpToApplicationThreadServerStreamListener(executor.getScheduledExecutorService(), stream, Context.ROOT.withCancellation());
ServerStreamListener mockListener = mock(ServerStreamListener.class);
listener.setListener(mockListener);
Throwable expectedT = new RuntimeException();
doThrow(expectedT).when(mockListener).messageRead(any(InputStream.class));
// Closing the InputStream is done by the delegated listener (generally ServerCallImpl)
listener.messageRead(mock(InputStream.class));
try {
executor.runDueTasks();
fail("Expected exception");
} catch (Throwable t) {
assertSame(expectedT, t);
verify(stream).close(statusCaptor.capture(), any(Metadata.class));
assertSame(expectedT, statusCaptor.getValue().getCause());
}
}
use of io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener in project grpc-java by grpc.
the class ServerImplTest method messageRead_errorCancelsCall.
@Test
public void messageRead_errorCancelsCall() throws Exception {
JumpToApplicationThreadServerStreamListener listener = new JumpToApplicationThreadServerStreamListener(executor.getScheduledExecutorService(), stream, Context.ROOT.withCancellation());
ServerStreamListener mockListener = mock(ServerStreamListener.class);
listener.setListener(mockListener);
Throwable expectedT = new AssertionError();
doThrow(expectedT).when(mockListener).messageRead(any(InputStream.class));
// Closing the InputStream is done by the delegated listener (generally ServerCallImpl)
listener.messageRead(mock(InputStream.class));
try {
executor.runDueTasks();
fail("Expected exception");
} catch (Throwable t) {
assertSame(expectedT, t);
verify(stream).close(statusCaptor.capture(), any(Metadata.class));
assertSame(expectedT, statusCaptor.getValue().getCause());
}
}
use of io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener in project grpc-java by grpc.
the class ServerImplTest method onReady_runtimeExceptionCancelsCall.
@Test
public void onReady_runtimeExceptionCancelsCall() {
JumpToApplicationThreadServerStreamListener listener = new JumpToApplicationThreadServerStreamListener(executor.getScheduledExecutorService(), stream, Context.ROOT.withCancellation());
ServerStreamListener mockListener = mock(ServerStreamListener.class);
listener.setListener(mockListener);
Throwable expectedT = new RuntimeException();
doThrow(expectedT).when(mockListener).onReady();
listener.onReady();
try {
executor.runDueTasks();
fail("Expected exception");
} catch (Throwable t) {
assertSame(expectedT, t);
verify(stream).close(statusCaptor.capture(), any(Metadata.class));
assertSame(expectedT, statusCaptor.getValue().getCause());
}
}
Aggregations