Search in sources :

Example 21 with DefaultChannelPromise

use of io.netty.channel.DefaultChannelPromise in project grpc-java by grpc.

the class NettyStreamTestBase method shouldBeReadyForDataAfterWritingSmallMessage.

@Test
public void shouldBeReadyForDataAfterWritingSmallMessage() throws IOException {
    sendHeadersIfServer();
    // Make sure the writes don't complete so we "back up"
    ChannelPromise uncompletedPromise = new DefaultChannelPromise(channel);
    when(writeQueue.enqueue(any(QueuedCommand.class), anyBoolean())).thenReturn(uncompletedPromise);
    assertTrue(stream.isReady());
    byte[] msg = smallMessage();
    stream.writeMessage(new ByteArrayInputStream(msg));
    stream.flush();
    assertTrue(stream.isReady());
    verify(listener(), never()).onReady();
}
Also used : ByteArrayInputStream(java.io.ByteArrayInputStream) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) QueuedCommand(io.grpc.netty.WriteQueue.QueuedCommand) Test(org.junit.Test)

Example 22 with DefaultChannelPromise

use of io.netty.channel.DefaultChannelPromise in project grpc-java by grpc.

the class NettyStreamTestBase method setUp.

/**
 * Set up for test.
 */
@Before
public void setUp() {
    MockitoAnnotations.initMocks(this);
    when(channel.alloc()).thenReturn(UnpooledByteBufAllocator.DEFAULT);
    when(channel.pipeline()).thenReturn(pipeline);
    when(channel.eventLoop()).thenReturn(eventLoop);
    when(channel.newPromise()).thenReturn(new DefaultChannelPromise(channel));
    when(channel.voidPromise()).thenReturn(new DefaultChannelPromise(channel));
    ChannelPromise completedPromise = new DefaultChannelPromise(channel).setSuccess();
    when(channel.write(any())).thenReturn(completedPromise);
    when(channel.writeAndFlush(any())).thenReturn(completedPromise);
    when(writeQueue.enqueue(any(QueuedCommand.class), anyBoolean())).thenReturn(completedPromise);
    when(pipeline.firstContext()).thenReturn(ctx);
    when(eventLoop.inEventLoop()).thenReturn(true);
    when(http2Stream.id()).thenReturn(STREAM_ID);
    doAnswer(new Answer<Void>() {

        @Override
        public Void answer(InvocationOnMock invocation) throws Throwable {
            Runnable runnable = (Runnable) invocation.getArguments()[0];
            runnable.run();
            return null;
        }
    }).when(eventLoop).execute(any(Runnable.class));
    stream = createStream();
}
Also used : DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) InvocationOnMock(org.mockito.invocation.InvocationOnMock) ChannelPromise(io.netty.channel.ChannelPromise) DefaultChannelPromise(io.netty.channel.DefaultChannelPromise) QueuedCommand(io.grpc.netty.WriteQueue.QueuedCommand) Before(org.junit.Before)

Aggregations

DefaultChannelPromise (io.netty.channel.DefaultChannelPromise)22 ChannelPromise (io.netty.channel.ChannelPromise)13 Test (org.junit.Test)8 ChannelFuture (io.netty.channel.ChannelFuture)6 InvocationOnMock (org.mockito.invocation.InvocationOnMock)6 QueuedCommand (io.grpc.netty.WriteQueue.QueuedCommand)4 ByteBuf (io.netty.buffer.ByteBuf)4 ChannelFutureListener (io.netty.channel.ChannelFutureListener)4 Before (org.junit.Before)4 BeforeEach (org.junit.jupiter.api.BeforeEach)4 Channel (io.netty.channel.Channel)3 GenericFutureListener (io.netty.util.concurrent.GenericFutureListener)3 ChannelHandler (io.netty.channel.ChannelHandler)2 EventExecutor (io.netty.util.concurrent.EventExecutor)2 Future (io.netty.util.concurrent.Future)2 ByteArrayInputStream (java.io.ByteArrayInputStream)2 InetSocketAddress (java.net.InetSocketAddress)2 TimeUnit (java.util.concurrent.TimeUnit)2 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)2 AssertionFailedError (junit.framework.AssertionFailedError)2