本篇文章接直接分享性能测试案例,分为map操作性和INCR操作。
map
思路
设计了一个简单的测试场景,用户先往某个值为map类型数据里面放一个key-value数据,然后查询这个key的value是否预期一致(其实有点多余),然后删除这个key。
这个用例实在没想到具体的适用场景,就当我为了演示空想的用例。
用例
import com.funtester.base.constaint.FixedThread
import com.funtester.base.constaint.ThreadBase
import com.funtester.config.Constant
import com.funtester.db.redis.RedisBase
import com.funtester.frame.execute.Concurrent
import com.funtester.utils.StringUtil
import java.util.concurrent.atomic.AtomicInteger
/**
* FunTester测试框架,Redis压测,map
*/
class RedisList05 extends RedisBase {
static AtomicInteger num = new AtomicInteger(0)
static RedisBase drive
public static void main(String[] args) {
String host = "FunTester"
int port = 6379
drive = new RedisBase(host, port)
drive.index = 2
int times = 200
int thread = 10
Constant.RUNUP_TIME = 0
def tester = new FunTester(times)
def task = new Concurrent(tester, thread, "redis测试实践之map")
task.start()
drive.close()
}
private static class FunTester extends FixedThread {
String key = DEFAULT_STRING + num.getAndIncrement()
FunTester(int limit) {
super(null, limit, true)
}
@Override
protected void doing() throws Exception {
def k = "f" + getNanoMark()
def v = StringUtil.getString(10000)
drive.hset(key, k, v)
def hget = drive.hget(key, k)
if (v != hget) fail()
drive.hdel(key, k)
}
@Override
ThreadBase clone() {
return new FunTester(this.limit)
}
}
}
测试结果
此处省略一千八百字和二百七十张图。
INCR
Redis Incr 命令将 key 中储存的数字值增一。而decr方式是数字值减一。这个可以设计成为两个用例。
- 多线程对一个key进行递增操作,看是否线程安全
- 多线程对一个可以进行等量递增和递减,看是否线程安全
为了省事儿,我只演示第一种用例。
用例
import com.funtester.base.constaint.FixedThread
import com.funtester.base.constaint.ThreadBase
import com.funtester.config.Constant
import com.funtester.db.redis.RedisBase
import com.funtester.frame.execute.Concurrent
import java.util.concurrent.atomic.AtomicInteger
/**
* FunTester测试框架,Redis压测,incr
*/
class RedisList06 extends RedisBase {
static AtomicInteger num = new AtomicInteger(0)
static RedisBase drive
public static void main(String[] args) {
String host = "FunTester"
int port = 6379
drive = new RedisBase(host, port)
drive.index =2
int times = 200
int thread = 20
Constant.RUNUP_TIME = 0
def tester = new FunTester(times)
def task = new Concurrent(tester, thread, "redis测试实践之INCR")
task.start()
drive.close()
}
private static class FunTester extends FixedThread {
String listName = DEFAULT_STRING + num.getAndIncrement()
FunTester(int limit) {
super(null, limit, true)
}
@Override
protected void doing() throws Exception {
drive.incr("FunTester1123")
}
@Override
ThreadBase clone() {
return new FunTester(this.limit)
}
}
}
测试结果
此处省略一千八百字。
总结
FunTester测试框架对Redis的性能测试系列已经完结,下一步会写FunTester测试框架对MySQL进行压测的实践系列,敬请期待……
最后: 可以在公众号:伤心的辣条 ! 免费领取一份216页软件测试工程师面试宝典文档资料。以及相对应的视频学习教程免费分享!,其中包括了有基础知识、Linux必备、Shell、互联网程序原理、Mysql数据库、抓包工具专题、接口测试工具、测试进阶-Python编程、Web自动化测试、APP自动化测试、接口自动化测试、测试高级持续集成、测试架构开发测试框架、性能测试、安全测试等。
如果我的博客对你有帮助、如果你喜欢我的博客内容,请 “点赞” “评论” “收藏” 一键三连哦!喜欢软件测试的小伙伴们,可以加入我们的测试技术交流扣扣群:914172719(里面有各种软件测试资源和技术讨论)
好文推荐
转行面试,跳槽面试,软件测试人员都必须知道的这几种面试技巧!