一次关于长链接的测试
2018-03-22 09:43
204 查看
测试需求
AdLogServer主要负责接收、处理客户端(家长端、园丁端)广告展现、点击的日志。 AdCountSrv提供广告系统的统计功能
adlogserver和countserver之间采用长链接进行通讯,此次主要是针对这个长链接进行测试
开发文档
采用的协议:长连接通信采用序列化的对象进行传输,传输对象实现序列化Serializable接口,编码、解码采用Netty自带的编解码工具类;
可靠性设计
(1)报活
借助Netty IdleStateHandler实现Ping-Pong双向心跳机制,保证通信哪一方出现网络故障,都能及时发现。
如果发送三次ping包,均未收到pong回包,则认为报活失败,客户端将主动断开链接;
(2)重连机制,如果链路中断(包括网络异常、AdCountServer异常),等待INTERVAL(可配置,现在配置为2秒)时间后,重连;
(3)消息缓存重发:定时重传机制,在长连接正常情况下,如果AdCountServer在60秒(可配置)内没有回消息响应,消息将会重传;当发生链路中断之后,缓存在消息队列中的代发消息不能丢失,等待链路恢复之后,重新发送这些消息;
测试方案:
模拟场景,通过打印日志查看
测试用例
长链接测试
1、client和server正常通讯
2、客户端ping三次失败 情况可能是(client和server之间网络异常,可以采用server这面网络断开)
测试步骤:
(1)将countserver的jar包放在另外一台机器上,放在一个目录下面,然后再这个目录下面运行即可
运行命令:java -jar -Dspring.profiles.active=test AdCountServer-1.0-SNAPSHOT.jar
即可运行起来
(2)在logserver 的配置文件中配置成新机器上面的IP 端口默认使用9001 因为长连接默认使用的是9001
(3)断开另外一台机器上面的网络
adlogserver中就会出现 三次ping包的日志
如下:
3、还有一种情况countserver挂掉之后,logserver会收到一个标志,会发起重试
消息缓存重发测试
e81a
1、正常发送上报请求,查看
2、countserver挂掉,发送上报请求 一直存在队列中,无法发送到countserver
3、将countserver开启来,然后查看
4、设置缓存的最大数量 在logserver的配置文件中设置成3条,然后发送5条数据查看 logserver的日志是否会丢掉后面的那几个数据
我设置发送4个展示埋点,队列中只存3个埋点值,有一个会被丢掉
AdLogServer主要负责接收、处理客户端(家长端、园丁端)广告展现、点击的日志。 AdCountSrv提供广告系统的统计功能
adlogserver和countserver之间采用长链接进行通讯,此次主要是针对这个长链接进行测试
开发文档
采用的协议:长连接通信采用序列化的对象进行传输,传输对象实现序列化Serializable接口,编码、解码采用Netty自带的编解码工具类;
可靠性设计
(1)报活
借助Netty IdleStateHandler实现Ping-Pong双向心跳机制,保证通信哪一方出现网络故障,都能及时发现。
如果发送三次ping包,均未收到pong回包,则认为报活失败,客户端将主动断开链接;
(2)重连机制,如果链路中断(包括网络异常、AdCountServer异常),等待INTERVAL(可配置,现在配置为2秒)时间后,重连;
(3)消息缓存重发:定时重传机制,在长连接正常情况下,如果AdCountServer在60秒(可配置)内没有回消息响应,消息将会重传;当发生链路中断之后,缓存在消息队列中的代发消息不能丢失,等待链路恢复之后,重新发送这些消息;
测试方案:
模拟场景,通过打印日志查看
测试用例
长链接测试
1、client和server正常通讯
[2018-03-21 16:10:13,899][epollEventLoopGroup-2-1][DEBUG][com.ztwl.netty.heartbeat.common.BaseHeartbeatHandler:] ---ALL_IDLE--- [2018-03-21 16:10:13,900][epollEventLoopGroup-2-1][DEBUG][com.ztwl.netty.heartbeat.client.Client:] send ping MessageDTO{type=1, uuid='1ac98502a711476d8d2ab442028ae13b', logBO=null} pingCount 1 [2018-03-21 16:10:13,902][epollEventLoopGroup-2-1][DEBUG][com.ztwl.netty.heartbeat.client.Client:] get pong MessageDTO{type=2, uuid='null', logBO=null} pingCount 0
2、客户端ping三次失败 情况可能是(client和server之间网络异常,可以采用server这面网络断开)
测试步骤:
(1)将countserver的jar包放在另外一台机器上,放在一个目录下面,然后再这个目录下面运行即可
运行命令:java -jar -Dspring.profiles.active=test AdCountServer-1.0-SNAPSHOT.jar
即可运行起来
(2)在logserver 的配置文件中配置成新机器上面的IP 端口默认使用9001 因为长连接默认使用的是9001
(3)断开另外一台机器上面的网络
adlogserver中就会出现 三次ping包的日志
如下:
[2018-03-21 19:49:56,024][epollEventLoopGroup-2-1][DEBUG][com.ztwl.netty.heartbeat.common.BaseHeartbeatHandler:] ---ALL_IDLE--- [2018-03-21 19:49:56,025][epollEventLoopGroup-2-1][DEBUG][com.ztwl.netty.heartbeat.client.Client:] send ping MessageDTO{type=1, uuid='48f478a4981742b3b2613e9e470199cb', logBO=null} pingCount 1 [2018-03-21 19:50:01,025][epollEventLoopGroup-2-1][DEBUG][com.ztwl.netty.heartbeat.common.BaseHeartbeatHandler:] ---ALL_IDLE--- [2018-03-21 19:50:01,026][epollEventLoopGroup-2-1][DEBUG][com.ztwl.netty.heartbeat.client.Client:] send ping MessageDTO{type=1, uuid='ebc186ccdce94fc6ae67559daae257df', logBO=null} pingCount 2 [2018-03-21 19:50:06,026][epollEventLoopGroup-2-1][DEBUG][com.ztwl.netty.heartbeat.common.BaseHeartbeatHandler:] ---ALL_IDLE--- [2018-03-21 19:50:06,027][epollEventLoopGroup-2-1][DEBUG][com.ztwl.netty.heartbeat.client.Client:] send ping MessageDTO{type=1, uuid='621653d864e3430d9cb88a66d14bd185', logBO=null} pingCount 3 [2018-03-21 19:50:11,029][epollEventLoopGroup-2-1][DEBUG][com.ztwl.netty.heartbeat.client.Client:] pingCount > 3 断开链接,重新链接,同时清空 ping count = 0 [2018-03-21 19:50:11,057][epollEventLoopGroup-2-1][WARN][com.ztwl.netty.heartbeat.common.BaseHeartbeatHandler:] ---172.16.208.207/172.16.208.207:9001 is inactive--- [2018-03-21 19:50:43,060][epollEventLoopGroup-2-2][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s [2018-03-21 19:51:15,063][epollEventLoopGroup-2-3][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s [2018-03-21 19:51:47,066][epollEventLoopGroup-2-4][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s [2018-03-21 19:52:19,068][epollEventLoopGroup-2-1][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s [2018-03-21 19:52:51,069][epollEventLoopGroup-2-2][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s [2018-03-21 19:53:06,102][epollEventLoopGroup-2-3][INFO][com.ztwl.netty.heartbeat.client.Client:] Connect to AdCountServer successfully! [2018-03-21 19:53:06,102][epollEventLoopGroup-2-3][INFO][com.ztwl.netty.heartbeat.common.BaseHeartbeatHandler:] ---172.16.208.207/172.16.208.207:9001 is active--- [2018-03-21 19:53:11,102][epollEventLoopGroup-2-3][DEBUG][com.ztwl.netty.heartbeat.common.BaseHeartbeatHandler:] ---ALL_IDLE--- [2018-03-21 19:53:11,104][epollEventLoopGroup-2-3][DEBUG][com.ztwl.netty.heartbeat.client.Client:] send ping MessageDTO{type=1, uuid='fc37de0381d9453889296561ee4d817a', logBO=null} pingCount 1 [2018-03-21 19:53:11,107][epollEventLoopGroup-2-3][DEBUG][com.ztwl.netty.heartbeat.client.Client:] get pong MessageDTO{type=2, uuid='null', logBO=null} pingCount 0
3、还有一种情况countserver挂掉之后,logserver会收到一个标志,会发起重试
[2018-03-21 16:12:09,390][epollEventLoopGroup-2-1][WARN][com.ztwl.netty.heartbeat.common.BaseHeartbeatHandler:] ---172.16.200.17/172.16.200.17:9001 is inactive--- [2018-03-21 16:12:11,394][epollEventLoopGroup-2-2][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s [2018-03-21 16:12:13,396][epollEventLoopGroup-2-3][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s [2018-03-21 16:12:15,398][epollEventLoopGroup-2-4][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s
消息缓存重发测试
e81a
1、正常发送上报请求,查看
2、countserver挂掉,发送上报请求 一直存在队列中,无法发送到countserver
[2018-03-21 16:13:51,471][epollEventLoopGroup-2-4][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s [2018-03-21 16:13:51,850][epollEventLoopGroup-4-2][DEBUG][com.ztwl.netty.logserver.handler.OwnAdHandler:] redis time :0 [2018-03-21 16:13:51,850][epollEventLoopGroup-4-2][DEBUG][com.ztwl.netty.heartbeat.client.ClientHandler:] LogQueue count 1 [2018-03-21 16:13:51,851][epollEventLoopGroup-4-2][DEBUG][com.ztwl.netty.logserver.handler.OwnAdHandler:] write2Queue time :0 [2018-03-21 16:13:51,856][epollEventLoopGroup-4-2][DEBUG][com.ztwl.netty.heartbeat.client.ClientHandler:] LogQueue count 2 [2018-03-21 16:13:51,856][epollEventLoopGroup-4-2][DEBUG][com.ztwl.netty.logserver.handler.OwnAdHandler:] write2Queue time :0 [2018-03-21 16:13:51,864][redis Handler][DEBUG][com.ztwl.netty.redis.RedisHandler:] 插入UserViewTime,日志服务器打时间戳 [2018-03-21 16:13:51,868][redis Handler][DEBUG][com.ztwl.netty.redis.RedisHandler:] update Redis [2018-03-21 16:13:53,473][epollEventLoopGroup-2-1][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s [2018-03-21 16:14:09,486][epollEventLoopGroup-2-1][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s [2018-03-21 16:14:11,488][epollEventLoopGroup-2-2][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s [2018-03-21 16:14:13,420][epollEventLoopGroup-4-4][DEBUG][com.ztwl.netty.logserver.handler.OwnAdHandler:] redis time :0 [2018-03-21 16:14:13,420][epollEventLoopGroup-4-4][DEBUG][com.ztwl.netty.heartbeat.client.ClientHandler:] LogQueue count 3 [2018-03-21 16:14:13,420][epollEventLoopGroup-4-4][DEBUG][com.ztwl.netty.logserver.handler.OwnAdHandler:] write2Queue time :0 [2018-03-21 16:14:13,428][epollEventLoopGroup-4-4][DEBUG][com.ztwl.netty.heartbeat.client.ClientHandler:] LogQueue count 4 [2018-03-21 16:14:13,428][epollEventLoopGroup-4-4][DEBUG][com.ztwl.netty.logserver.handler.OwnAdHandler:] write2Queue time :1 [2018-03-21 16:14:13,431][redis Handler][DEBUG][com.ztwl.netty.redis.RedisHandler:] 插入UserViewTime,日志服务器打时间戳 [2018-03-21 16:14:13,432][redis Handler][DEBUG][com.ztwl.netty.redis.RedisHandler:] update Redis [2018-03-21 16:14:13,490][epollEventLoopGroup-2-3][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s
3、将countserver开启来,然后查看
[2018-03-21 16:16:33,595][epollEventLoopGroup-2-2][INFO][com.ztwl.netty.heartbeat.common.BaseHeartbeatHandler:] ---172.16.200.17/172.16.200.17:9001 is active--- [2018-03-21 16:16:34,073][KeepAlive client][DEBUG][com.ztwl.netty.heartbeat.client.ClientHandler:] LogQueue count 3 [2018-03-21 16:16:34,074][KeepAlive client][DEBUG][com.ztwl.netty.heartbeat.client.Client:] client sendData : MessageDTO{type=3, uuid='7225cffd45dd4140a16a5b1777ba1fe2', logBO={"uid":"2e779945d42d0a8f0697","ad_id":1,"space_id":1001,"ad_platform":1,"os":2,"activity_id":2,"log_type":"show","date":"2018-03-21 16:13:51"}} [2018-03-21 16:16:34,075][KeepAlive client][DEBUG][com.ztwl.netty.heartbeat.client.ClientHandler:] LogQueue count 2 [2018-03-21 16:16:34,075][KeepAlive client][DEBUG][com.ztwl.netty.heartbeat.client.Client:] client sendData : MessageDTO{type=3, uuid='24bbf5e6d0c84ee39fb358c3b1bca40c', logBO={"uid":"2e779945d42d0a8f0697","ad_id":1,"space_id":1001,"ad_platform":1,"os":2,"activity_id":2,"log_type":"click","date":"2018-03-21 16:13:51"}} [2018-03-21 16:16:34,075][KeepAlive client][DEBUG][com.ztwl.netty.heartbeat.client.ClientHandler:] LogQueue count 1 [2018-03-21 16:16:34,075][KeepAlive client][DEBUG][com.ztwl.netty.heartbeat.client.Client:] client sendData : MessageDTO{type=3, uuid='ce0e6ce322cd41f79b45825cb5cb7454', logBO={"uid":"2e779945d42d0a8f0697","ad_id":1,"space_id":1001,"ad_platform":1,"os":2,"activity_id":2,"log_type":"show","date":"2018-03-21 16:14:13"}} [2018-03-21 16:16:34,075][KeepAlive client][DEBUG][com.ztwl.netty.heartbeat.client.ClientHandler:] LogQueue count 0 [2018-03-21 16:16:34,075][KeepAlive client][DEBUG][com.ztwl.netty.heartbeat.client.Client:] client sendData : MessageDTO{type=3, uuid='e5610c2d6d624c07977c3c69490b2053', logBO={"uid":"2e779945d42d0a8f0697","ad_id":1,"space_id":1001,"ad_platform":1,"os":2,"activity_id":2,"log_type":"click","date":"2018-03-21 16:14:13"}} [2018-03-21 16:16:34,110][epollEventLoopGroup-2-2][DEBUG][com.ztwl.netty.heartbeat.client.Client:] removeMessageDTOBuffer MessageDTO{type=4, uuid='7225cffd45dd4140a16a5b1777ba1fe2', logBO=null} [2018-03-21 16:16:34,111][epollEventLoopGroup-2-2][DEBUG][com.ztwl.netty.heartbeat.client.Client:] removeMessageDTOBuffer MessageDTO{type=4, uuid='24bbf5e6d0c84ee39fb358c3b1bca40c', logBO=null} [2018-03-21 16:16:34,112][epollEventLoopGroup-2-2][DEBUG][com.ztwl.netty.heartbeat.client.Client:] removeMessageDTOBuffer MessageDTO{type=4, uuid='ce0e6ce322cd41f79b45825cb5cb7454', logBO=null} [2018-03-21 16:16:34,112][epollEventLoopGroup-2-2][DEBUG][com.ztwl.netty.heartbeat.client.Client:] removeMessageDTOBuffer MessageDTO{type=4, uuid='e5610c2d6d624c07977c3c69490b2053', logBO=null}
4、设置缓存的最大数量 在logserver的配置文件中设置成3条,然后发送5条数据查看 logserver的日志是否会丢掉后面的那几个数据
我设置发送4个展示埋点,队列中只存3个埋点值,有一个会被丢掉
# 最大缓存队列 logQueueMax=3
[2018-03-21 20:11:08,681][epollEventLoopGroup-4-1][DEBUG][com.ztwl.netty.logserver.handler.OwnAdHandler:] redis time :0 [2018-03-21 20:11:08,683][epollEventLoopGroup-4-1][DEBUG][com.ztwl.netty.heartbeat.client.ClientHandler:] LogQueue count 1 [2018-03-21 20:11:08,683][epollEventLoopGroup-4-1][DEBUG][com.ztwl.netty.logserver.handler.OwnAdHandler:] write2Queue time :2 [2018-03-21 20:11:08,688][redis Handler][DEBUG][com.ztwl.netty.redis.RedisHandler:] 插入UserViewTime,日志服务器打时间戳 [2018-03-21 20:11:08,694][redis Handler][DEBUG][com.ztwl.netty.redis.RedisHandler:] update Redis [2018-03-21 20:11:08,702][epollEventLoopGroup-4-1][DEBUG][com.ztwl.netty.heartbeat.client.ClientHandler:] LogQueue count 2 [2018-03-21 20:11:08,702][epollEventLoopGroup-4-1][DEBUG][com.ztwl.netty.logserver.handler.OwnAdHandler:] write2Queue time :1 [2018-03-21 20:11:08,961][epollEventLoopGroup-4-3][DEBUG][com.ztwl.netty.logserver.handler.OwnAdHandler:] redis time :0 [2018-03-21 20:11:08,961][epollEventLoopGroup-4-3][DEBUG][com.ztwl.netty.heartbeat.client.ClientHandler:] LogQueue count 3 [2018-03-21 20:11:08,962][epollEventLoopGroup-4-3][DEBUG][com.ztwl.netty.logserver.handler.OwnAdHandler:] write2Queue time :0 [2018-03-21 20:11:08,969][epollEventLoopGroup-4-3][DEBUG][com.ztwl.netty.logserver.handler.OwnAdHandler:] write2Queue time :0 [2018-03-21 20:11:08,973][redis Handler][DEBUG][com.ztwl.netty.redis.RedisHandler:] 插入UserViewTime,日志服务器打时间戳 [2018-03-21 20:11:08,973][redis Handler][DEBUG][com.ztwl.netty.redis.RedisHandler:] update Redis [2018-03-21 20:11:09,485][epollEventLoopGroup-3-3][INFO][com.ztwl.netty.heartbeat.client.Client:] Failed to connect to AdCountServer, try connect after 2s
相关文章推荐
- 【MongoDb】一次关于Oracle和MongoDb的插入和查询性能测试
- 写了一个自动加链接的工具, 关于SEO的,测试一下效果
- 一次测试引发的探索:关于分号在java web中的一个特性
- 今天看到个关于讨论测试Socket服务器端满负荷链接的讨论帖!y
- 关于一次文本读取的速度测试 TStringList PK AssignFile
- LR:测试接口并发测试时,关于ORACL数据库连接池,及MySql链接池的的配置及说明
- 关于SQL 参数的一次测试(重新又测了一次)
- 关于Android开发中Java对象序列化的一次测试
- 关于AysncController的一次测试(url重写后静态页文件内容的读取是否需要使用异步?)
- 关于request.getParameterMap()返回的map对象——我的一次移植测试经历
- 关于C#测试Oracle数据库链接的问题
- 测试数据库链接数
- 关于类的继承测试程序
- 关于 Android 下的自动化测试方法介绍
- XX行关于联机交易(OLTP)系统类项目的性能测试技术方案
- 关于测试的起始 : 测试系统工程师TSE的职责与培养
- 关于链接出现 unauthenticated user 用户问题研究
- 《软件测试的艺术》读书心得 ---一次自我评价测试
- 记一次VNC远程连接Linux问题解决记录(5900端口测试、KDE桌面安装)
- 色深的一次测试。