本文整理匯總了Java中io.netty.channel.embedded.EmbeddedChannel.runPendingTasks方法的典型用法代碼示例。如果您正苦於以下問題:Java EmbeddedChannel.runPendingTasks方法的具體用法?Java EmbeddedChannel.runPendingTasks怎麽用?Java EmbeddedChannel.runPendingTasks使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類io.netty.channel.embedded.EmbeddedChannel
的用法示例。
在下文中一共展示了EmbeddedChannel.runPendingTasks方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: sendRequest
import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
static Reply sendRequest(EmbeddedChannel channel, Request request) throws Exception {
channel.writeInbound(request);
Object encodedReply = channel.readOutbound();
for (int i = 0; encodedReply == null && i < 50; i++) {
channel.runPendingTasks();
Thread.sleep(10);
encodedReply = channel.readOutbound();
}
if (encodedReply == null) {
throw new IllegalStateException("No reply to request: " + request);
}
WireCommand decoded = CommandDecoder.parseCommand((ByteBuf) encodedReply);
((ByteBuf) encodedReply).release();
assertNotNull(decoded);
return (Reply) decoded;
}
示例2: triggerRequest
import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Override
public void triggerRequest(Subscriber<? super Long> subscriber) {
EmbeddedChannel channel = ((SubscriberWithChannel) subscriber).channel;
channel.runPendingTasks();
while (channel.readOutbound() != null) {
channel.runPendingTasks();
}
channel.runPendingTasks();
}
開發者ID:playframework,項目名稱:netty-reactive-streams,代碼行數:11,代碼來源:HandlerSubscriberBlackboxVerificationTest.java
示例3: testUserDefinedWritability
import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test
public void testUserDefinedWritability() {
final StringBuilder buf = new StringBuilder();
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter() {
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
buf.append(ctx.channel().isWritable());
buf.append(' ');
}
});
ch.config().setWriteBufferLowWaterMark(128);
ch.config().setWriteBufferHighWaterMark(256);
ChannelOutboundBuffer cob = ch.unsafe().outboundBuffer();
// Ensure that the default value of a user-defined writability flag is true.
for (int i = 1; i <= 30; i ++) {
assertThat(cob.getUserDefinedWritability(i), is(true));
}
// Ensure that setting a user-defined writability flag to false affects channel.isWritable();
cob.setUserDefinedWritability(1, false);
ch.runPendingTasks();
assertThat(buf.toString(), is("false "));
// Ensure that setting a user-defined writability flag to true affects channel.isWritable();
cob.setUserDefinedWritability(1, true);
ch.runPendingTasks();
assertThat(buf.toString(), is("false true "));
safeClose(ch);
}
示例4: testUserDefinedWritability2
import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test
public void testUserDefinedWritability2() {
final StringBuilder buf = new StringBuilder();
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter() {
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
buf.append(ctx.channel().isWritable());
buf.append(' ');
}
});
ch.config().setWriteBufferLowWaterMark(128);
ch.config().setWriteBufferHighWaterMark(256);
ChannelOutboundBuffer cob = ch.unsafe().outboundBuffer();
// Ensure that setting a user-defined writability flag to false affects channel.isWritable()
cob.setUserDefinedWritability(1, false);
ch.runPendingTasks();
assertThat(buf.toString(), is("false "));
// Ensure that setting another user-defined writability flag to false does not trigger
// channelWritabilityChanged.
cob.setUserDefinedWritability(2, false);
ch.runPendingTasks();
assertThat(buf.toString(), is("false "));
// Ensure that setting only one user-defined writability flag to true does not affect channel.isWritable()
cob.setUserDefinedWritability(1, true);
ch.runPendingTasks();
assertThat(buf.toString(), is("false "));
// Ensure that setting all user-defined writability flags to true affects channel.isWritable()
cob.setUserDefinedWritability(2, true);
ch.runPendingTasks();
assertThat(buf.toString(), is("false true "));
safeClose(ch);
}
示例5: testMixedWritability
import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test
public void testMixedWritability() {
final StringBuilder buf = new StringBuilder();
EmbeddedChannel ch = new EmbeddedChannel(new ChannelInboundHandlerAdapter() {
@Override
public void channelWritabilityChanged(ChannelHandlerContext ctx) throws Exception {
buf.append(ctx.channel().isWritable());
buf.append(' ');
}
});
ch.config().setWriteBufferLowWaterMark(128);
ch.config().setWriteBufferHighWaterMark(256);
ChannelOutboundBuffer cob = ch.unsafe().outboundBuffer();
// Trigger channelWritabilityChanged() by writing a lot.
ch.write(buffer().writeZero(256));
assertThat(buf.toString(), is("false "));
// Ensure that setting a user-defined writability flag to false does not trigger channelWritabilityChanged()
cob.setUserDefinedWritability(1, false);
ch.runPendingTasks();
assertThat(buf.toString(), is("false "));
// Ensure reducing the totalPendingWriteBytes down to zero does not trigger channelWritabilityChannged()
// because of the user-defined writability flag.
ch.flush();
assertThat(cob.totalPendingWriteBytes(), is(0L));
assertThat(buf.toString(), is("false "));
// Ensure that setting the user-defined writability flag to true triggers channelWritabilityChanged()
cob.setUserDefinedWritability(1, true);
ch.runPendingTasks();
assertThat(buf.toString(), is("false true "));
safeClose(ch);
}
示例6: testWrite
import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test
public void testWrite() throws Exception {
ActiveMQBuffer buff = ActiveMQBuffers.wrappedBuffer(ByteBuffer.allocate(128));
EmbeddedChannel channel = createChannel();
Assert.assertEquals(0, channel.outboundMessages().size());
NettyConnection conn = new NettyConnection(emptyMap, channel, new MyListener(), false, false);
conn.write(buff);
channel.runPendingTasks();
Assert.assertEquals(1, channel.outboundMessages().size());
}
示例7: throwsExceptionOnBlockUntilWritableIfClosed
import io.netty.channel.embedded.EmbeddedChannel; //導入方法依賴的package包/類
@Test(expected = IllegalStateException.class)
public void throwsExceptionOnBlockUntilWritableIfClosed() {
EmbeddedChannel channel = createChannel();
NettyConnection conn = new NettyConnection(emptyMap, channel, new MyListener(), false, false);
conn.close();
//to make sure the channel is closed it needs to run the pending tasks
channel.runPendingTasks();
conn.blockUntilWritable(0, 0, TimeUnit.NANOSECONDS);
}