10 - EmbeddedChannel-测试ChannelHandler链
| 方法 | 职责 |
|---|---|
| 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链的更多相关文章
- 【转】Java学习---10个测试框架介绍
[原文]https://www.toutiao.com/i6594302925458113027/ JAVA 程序员需要用到 10 个测试框架和库 Java 程序员需要用到十大单元测试和自动化集成测试 ...
- Rspec: everyday-rspec实操: 第10章测试其他功能,第11章TDD 第12章总结。
10.测试文件上传 作者推荐的Paperclip,官方维护组已经不推荐使用deprecated. 推荐使用rails自带的 ActiveStorage. Active Storage: 推进文件上传到 ...
- FreeNAS-9.10虚拟机测试安装
虚拟机安装NreeNAS-9.10步骤 需求:网络监控磁盘要扩容 测试环境: CPU 内存 系统盘 共享盘 网卡 2核 2G 20G 20G 桥接 系统版本:FreeNAS-9.10 一.配置虚拟机 ...
- 在ubuntu16.10 PHP测试连接MySQL中出现Call to undefined function: mysql_connect()
1.问题: 测试php7.0 链接mysql数据库的时候发生错误: Fatal error: Uncaught Error: Call to undefined function mysqli_con ...
- Delphi Berlin 10.1 for 小米平板2 (Win 10) 电子罗盘测试
Windows 10 下没有 Sensor.HeadingXSensor.HeadingYSensor.HeadingZ 需改用 Sensor.CompMagHeading
- 2015.10.14-TransactionScope测试
测试代码: ; ; List<string> lst = null; Action doSth = () => { using (var db = new TestSystemEnt ...
- 【10.10校内测试】【线段树维护第k小+删除】【lca+主席树维护前驱后驱】
贪心思想.将a排序后,对于每一个a,找到对应的删除m个后最小的b,每次更新答案即可. 如何删除才是合法并且最优的?首先,对于排了序的a,第$i$个那么之前就应该删除前$i-1$个a对应的b.剩下$m- ...
- win10序列号 2019年10月测试
win10序列号 N3415-266GF-AH13H-WA3UE-5HBT4 win10序列号 NPK3G-4Q81M-X4A61-D553L-NV68D win10序列号 N617H-84K11-6 ...
- TestNg 10. 多线程测试-xml文件实现
代码如下: package com.course.testng.multiThread; import org.testng.annotations.Test; public class MultiT ...
随机推荐
- 【转】 Pro Android学习笔记(五八):Preferences(2):CheckBoxPreference
目录(?)[-] CheckBox Preference xml文件 设备的存贮文件 复合preference 在ListPreference的例子中显示的是单选,如果是多选,可采用CheckBoxP ...
- css中的块级和内联元素
块级元素: 首先说明display是块级元素,会单独站一行,如 代码: <!DOCTYPE html> <html> <head lang="en"& ...
- sharepoint 2013 创建母版页
一.创建新的母版页, 并添加了新的样式表 1.从CodePlex 上获得Starter Master Pages for SharePoint 2010 或复制以下母版代码 <%@Master ...
- Ubuntu 12.04 LTS为例演示vsftpd虚拟用户 的配置
vsftpd虚拟用户 2012-05-19 15:46:59| 分类: GNU/Linux | 标签:ubuntu vsftpd ftp 虚拟用户 |举报|字号 订阅 我们登录FTP有 ...
- 关于login/interactive/no-interactive shell和profile/bash_profile/bashrc
login shell:第一次登录进系统时的shell,一般是指本机启动时的控制台shell或者ssh远程登录时的shell. interactive shell:登录以后,再打开控制台时运行的she ...
- eos命令
ps -ef|grep javakill -9 端口号cd /opt/sudytrue>nohup.outnohup eos7.5/startServer.sh &
- php小块代码
//页面本身网址 "http://".$_SERVER["HTTP_HOST"].preg_replace("/[^\/]+$/",&quo ...
- linux下mysql远程链接
前言:我的系统是ubuntu,默认不支持mysql远程链接.接下来的步骤改变这点. 1,首先取消mysql本机绑定 编辑/etc/mysql/my.cnf 将”bind-address = 127.0 ...
- CodeForces 279B Books (滑动窗口)
题意:给定n本书的阅读时间,然后你从第 i 本开始阅读,问你最多能看多少本书在给定时间内. 析:就是一个滑动窗口的水题. 代码如下: #pragma comment(linker, "/ST ...
- 用ORBSLAM2运行TUM Dataset数据集Monocular Examples
参照https://github.com/raulmur/ORB_SLAM2/blob/master/README.md 运行 4. Monocular Examples TUM Dataset 数据 ...