Search in sources :

Example 1 with JumpToApplicationThreadServerStreamListener

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());
    }
}
Also used : JumpToApplicationThreadServerStreamListener(io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener) JumpToApplicationThreadServerStreamListener(io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener) Test(org.junit.Test)

Example 2 with JumpToApplicationThreadServerStreamListener

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());
    }
}
Also used : JumpToApplicationThreadServerStreamListener(io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener) JumpToApplicationThreadServerStreamListener(io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener) Test(org.junit.Test)

Example 3 with JumpToApplicationThreadServerStreamListener

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());
    }
}
Also used : JumpToApplicationThreadServerStreamListener(io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener) JumpToApplicationThreadServerStreamListener(io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 4 with JumpToApplicationThreadServerStreamListener

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());
    }
}
Also used : JumpToApplicationThreadServerStreamListener(io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener) JumpToApplicationThreadServerStreamListener(io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener) ByteArrayInputStream(java.io.ByteArrayInputStream) InputStream(java.io.InputStream) Test(org.junit.Test)

Example 5 with JumpToApplicationThreadServerStreamListener

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());
    }
}
Also used : JumpToApplicationThreadServerStreamListener(io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener) JumpToApplicationThreadServerStreamListener(io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener) Test(org.junit.Test)

Aggregations

JumpToApplicationThreadServerStreamListener (io.grpc.internal.ServerImpl.JumpToApplicationThreadServerStreamListener)6 Test (org.junit.Test)6 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InputStream (java.io.InputStream)2