当前位置: 首页>>代码示例>>Java>>正文


Java EmbeddedChannel.runPendingTasks方法代码示例

本文整理汇总了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;
}
 
开发者ID:pravega,项目名称:pravega,代码行数:17,代码来源:AppendTest.java

示例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);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:34,代码来源:ChannelOutboundBufferTest.java

示例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);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:40,代码来源:ChannelOutboundBufferTest.java

示例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);
}
 
开发者ID:wuyinxian124,项目名称:netty4.0.27Learn,代码行数:39,代码来源:ChannelOutboundBufferTest.java

示例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());
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:13,代码来源:NettyConnectionTest.java

示例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);
}
 
开发者ID:apache,项目名称:activemq-artemis,代码行数:10,代码来源:NettyConnectionTest.java


注:本文中的io.netty.channel.embedded.EmbeddedChannel.runPendingTasks方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。