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();
}
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();
}
Aggregations