方法 职责
writeInbound(Object... msgs) 将入站消息写入到EmbeddedChannel中
readInbound() 从EmbeddedChannel中读取一个入站消息,任何返回的消息都穿过了整个ChannelPipeLine
writeOutbound(Object... msgs) 将出站消息写入到EmbeddedChannel中
readOutbound() 从EmbeddedChannel中读取一个出站消息,任何返回的消息都穿过了整个ChannelPipeLine

10.1 示例

//测试结果
Received message:0
Received Finished!
Received message:1
Received Finished!
Received message:2
Received Finished!
embeddedChannel readInbound:0
embeddedChannel readInbound:1
embeddedChannel readInbound:2
public class EmBeddedChannelTest {
public static void main(String[] args) {
ByteBuf byteBuf = Unpooled.buffer();
for (int i = 0; i < 3; i++) {
byteBuf.writeInt(i);
} EmbeddedChannel embeddedChannel = new EmbeddedChannel(); //获取channelPipeLine
ChannelPipeline channelPipeline = embeddedChannel.pipeline();
channelPipeline.addLast(new SimpleChannelInBoundHandlerTest());
channelPipeline.addFirst(new DecodeTest()); //写入测试数据
embeddedChannel.writeInbound(byteBuf); System.out.println("embeddedChannel readInbound:"+embeddedChannel.readInbound());
System.out.println("embeddedChannel readInbound:"+embeddedChannel.readInbound());
System.out.println("embeddedChannel readInbound:"+embeddedChannel.readInbound()); } } //解码器
class DecodeTest extends ByteToMessageDecoder {
@Override
protected void decode(ChannelHandlerContext ctx, ByteBuf in, List<Object> out) throws Exception {
if( in.readableBytes()>=4 ){
out.add(in.readInt());
}
}
} //channelHandler
class SimpleChannelInBoundHandlerTest extends SimpleChannelInboundHandler {
@Override
protected void channelRead0(ChannelHandlerContext ctx, Object msg) throws Exception {
System.out.println("Received message:"+msg);
System.out.println("Received Finished!");
ctx.fireChannelRead(msg);
}
}

10 - EmbeddedChannel-测试ChannelHandler链的更多相关文章

  1. 【转】Java学习---10个测试框架介绍

    [原文]https://www.toutiao.com/i6594302925458113027/ JAVA 程序员需要用到 10 个测试框架和库 Java 程序员需要用到十大单元测试和自动化集成测试 ...

  2. Rspec: everyday-rspec实操: 第10章测试其他功能,第11章TDD 第12章总结。

    10.测试文件上传 作者推荐的Paperclip,官方维护组已经不推荐使用deprecated. 推荐使用rails自带的 ActiveStorage. Active Storage: 推进文件上传到 ...

  3. FreeNAS-9.10虚拟机测试安装

     虚拟机安装NreeNAS-9.10步骤 需求:网络监控磁盘要扩容 测试环境: CPU 内存 系统盘 共享盘 网卡 2核 2G 20G 20G 桥接 系统版本:FreeNAS-9.10 一.配置虚拟机 ...

  4. 在ubuntu16.10 PHP测试连接MySQL中出现Call to undefined function: mysql_connect()

    1.问题: 测试php7.0 链接mysql数据库的时候发生错误: Fatal error: Uncaught Error: Call to undefined function mysqli_con ...

  5. Delphi Berlin 10.1 for 小米平板2 (Win 10) 电子罗盘测试

    Windows 10 下没有 Sensor.HeadingXSensor.HeadingYSensor.HeadingZ 需改用 Sensor.CompMagHeading

  6. 2015.10.14-TransactionScope测试

    测试代码: ; ; List<string> lst = null; Action doSth = () => { using (var db = new TestSystemEnt ...

  7. 【10.10校内测试】【线段树维护第k小+删除】【lca+主席树维护前驱后驱】

    贪心思想.将a排序后,对于每一个a,找到对应的删除m个后最小的b,每次更新答案即可. 如何删除才是合法并且最优的?首先,对于排了序的a,第$i$个那么之前就应该删除前$i-1$个a对应的b.剩下$m- ...

  8. win10序列号 2019年10月测试

    win10序列号 N3415-266GF-AH13H-WA3UE-5HBT4 win10序列号 NPK3G-4Q81M-X4A61-D553L-NV68D win10序列号 N617H-84K11-6 ...

  9. TestNg 10. 多线程测试-xml文件实现

    代码如下: package com.course.testng.multiThread; import org.testng.annotations.Test; public class MultiT ...

随机推荐

  1. Java访问子类对象的实例变量

    对于Java这种语言来说,一般来说,子类可以调用父类中的非private变量,但在一些特殊情况下, Java语言可以通过父类调用子类的变量 具体的还是请按下面的例子吧! package com.yon ...

  2. asp后端弹出框

    RegisterStartupScript("提示信息", "<script>alert('Hello')</script>"); 这样 ...

  3. Java学习路线-知乎

    鼬自来晓 378 人赞同 可以从几方面来看Java:JVM Java JVM:内存结构和相关参数含义 · Issue #24 · pzxwhc/MineKnowContainer · GitHub J ...

  4. mongodb循环插入测试数据

    for (var i = 1; i <= 100000; i++) {   db.testdata2.insert( { x : i , name: "MACLEAN" , ...

  5. Java探索之旅(6)——对象和类

    1.知识要点 假设: public ClassName{     int data;   String name;     ClassName(){data=1;}     public static ...

  6. Pig FOREACH 嵌套循环

    Example: Nested Block Suppose we have relations A and B. Note that relation B contains an inner bag. ...

  7. 《精通Spring4.X企业应用开发实战》读后感第六章(容器事件)

  8. p2371&bzoj2118 墨墨的等式

    传送门(bzoj) 题目 墨墨突然对等式很感兴趣,他正在研究a1x1+a2y2+…+anxn=B存在非负整数解的条件,他要求你编写一个程序,给定N.{an}.以及B的取值范围,求出有多少B可以使等式存 ...

  9. 6.7 安装vim

  10. Eclipse提交svn错误svn E210003 connection refused by the server

    错误明细: org.apache.subversion.javahl.ClientException: svn: E210003: connection refused by the server o ...