多线程测试工具groboutils的使用
多线程 测试工具 使用
2023-09-11 14:20:54 时间
一直使用junit做为服务测试框架,感觉不错。最近有人反映在高并发的情况下,存在服务调不到。无奈再次打开单元测试模拟高并发的情况,却发现junit不支持并发测试
引入groboutils jar包,其实我主要使用MultiThreadedTestRunner类和TestRunnable类。
原有的junit框架不做改变,导入GroboTestingJUnit-1.2.1-core.jar包
代码如下
private IFaultService faultService; private static final int NUM_THREAD = 100; // 测试线程总数 public FaultServiceTest() { super(); IInitService initService = (IInitService) CustomBeanFactory .getBean("initService"); initService.initSiteDatabase(); this.faultService = (IFaultService) CustomBeanFactory .getBean("faultService"); public FaultServiceTest(String name) { super(name); IInitService initService = (IInitService) CustomBeanFactory .getBean("initService"); initService.initSiteDatabase(); this.faultService = (IFaultService) CustomBeanFactory .getBean("faultService"); // 高并发测试 public void testGetEquipEventAlertListByPage() throws Throwable { EquipmentQueryBean equipmentQueryBean = new EquipmentQueryBean(); // 生成所有测试线程 TestRunnable[] test = new TestRunnable[NUM_THREAD]; long start = System.currentTimeMillis(); for (int i = 0; i test.length; i++) { test[i] = new FaultServiceThread(faultService, equipmentQueryBean); // 生成测试线程运行器 MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(test); // 运行测试线程 mttr.runTestRunnables(); long used = System.currentTimeMillis() - start; System.out.printf("%s 调用花费 %s milli-seconds.\n", NUM_THREAD, used); public static Test suite() { TestSuite test = new TestSuite("HealthService接口类测试"); test.addTest(new FaultServiceTest("testGetEquipEventAlertListByPage")); return test; * 测试线程类定义 private static class FaultServiceThread extends TestRunnable { private IFaultService faultService; private EquipmentQueryBean equipmentQueryBean; public FaultServiceThread(IFaultService faultService, EquipmentQueryBean equipmentQueryBean) { super(); this.faultService = faultService; this.equipmentQueryBean = equipmentQueryBean; @Override public void runTest() throws Throwable { faultService.getEquipEventAlertListByPage(equipmentQueryBean);
运行代码,并发数开到100个后观察运行时间发现运行运行时间到了12秒了,看来问题出在DAO。需要进行sql代码优化了 导入的测试包有:
import net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner; import net.sourceforge.groboutils.junit.v1.TestRunnable; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; 最新内容请见作者的GitHub页:http://qaseven.github.io/
性能测试工具的 Coordinated Omission 问题 很早之前就看过 Gil 大神的一篇文章《Your Load Generator Is Probably Lying To You - Take The Red Pill And Find Out Why》,里面提到了性能测试工具 coordinated omission 的问题,但当时并没有怎么在意。这几天有人在我们自己的性能测试工具 go-ycsb 上面问了这个问题,我才陡然发现,原来我们也有。 什么是 coordinated omission 首先来说说什么是 coordinated omission。对于绝大多数 benchmark 工具来说,通常都是这样的模型——启动多个线程,每个线
在python中单线程,多线程,多进程对CPU的利用率实测以及GIL原理分析 首先关于在python中单线程,多线程,多进程对cpu的利用率实测如下: 单线程,多线程,多进程测试代码使用死循环。 1)单线程: 2)多线程: 3)多进程:
压力测试工具JMeter入门教程 压力测试工具JMeter入门教程 1.Jmeter 概要描叙 jmeter 是一款专门用于功能测试和压力测试的轻量级测试开发平台。多数情况下是用作压力测试,该测试工具在阿里巴巴有着广泛的使用,估计是不要钱吧,哈哈,功能上来说,整个平台实现了许多和互联网相关的网络测试组件,同时还保留着很强的扩展性方便用于一些非标准的测试场景,让伟大的程序猿同学来告诉它该如何工作。
private IFaultService faultService; private static final int NUM_THREAD = 100; // 测试线程总数 public FaultServiceTest() { super(); IInitService initService = (IInitService) CustomBeanFactory .getBean("initService"); initService.initSiteDatabase(); this.faultService = (IFaultService) CustomBeanFactory .getBean("faultService"); public FaultServiceTest(String name) { super(name); IInitService initService = (IInitService) CustomBeanFactory .getBean("initService"); initService.initSiteDatabase(); this.faultService = (IFaultService) CustomBeanFactory .getBean("faultService"); // 高并发测试 public void testGetEquipEventAlertListByPage() throws Throwable { EquipmentQueryBean equipmentQueryBean = new EquipmentQueryBean(); // 生成所有测试线程 TestRunnable[] test = new TestRunnable[NUM_THREAD]; long start = System.currentTimeMillis(); for (int i = 0; i test.length; i++) { test[i] = new FaultServiceThread(faultService, equipmentQueryBean); // 生成测试线程运行器 MultiThreadedTestRunner mttr = new MultiThreadedTestRunner(test); // 运行测试线程 mttr.runTestRunnables(); long used = System.currentTimeMillis() - start; System.out.printf("%s 调用花费 %s milli-seconds.\n", NUM_THREAD, used); public static Test suite() { TestSuite test = new TestSuite("HealthService接口类测试"); test.addTest(new FaultServiceTest("testGetEquipEventAlertListByPage")); return test; * 测试线程类定义 private static class FaultServiceThread extends TestRunnable { private IFaultService faultService; private EquipmentQueryBean equipmentQueryBean; public FaultServiceThread(IFaultService faultService, EquipmentQueryBean equipmentQueryBean) { super(); this.faultService = faultService; this.equipmentQueryBean = equipmentQueryBean; @Override public void runTest() throws Throwable { faultService.getEquipEventAlertListByPage(equipmentQueryBean);
运行代码,并发数开到100个后观察运行时间发现运行运行时间到了12秒了,看来问题出在DAO。需要进行sql代码优化了 导入的测试包有:
import net.sourceforge.groboutils.junit.v1.MultiThreadedTestRunner; import net.sourceforge.groboutils.junit.v1.TestRunnable; import junit.framework.Test; import junit.framework.TestCase; import junit.framework.TestSuite; 最新内容请见作者的GitHub页:http://qaseven.github.io/
性能测试工具的 Coordinated Omission 问题 很早之前就看过 Gil 大神的一篇文章《Your Load Generator Is Probably Lying To You - Take The Red Pill And Find Out Why》,里面提到了性能测试工具 coordinated omission 的问题,但当时并没有怎么在意。这几天有人在我们自己的性能测试工具 go-ycsb 上面问了这个问题,我才陡然发现,原来我们也有。 什么是 coordinated omission 首先来说说什么是 coordinated omission。对于绝大多数 benchmark 工具来说,通常都是这样的模型——启动多个线程,每个线
在python中单线程,多线程,多进程对CPU的利用率实测以及GIL原理分析 首先关于在python中单线程,多线程,多进程对cpu的利用率实测如下: 单线程,多线程,多进程测试代码使用死循环。 1)单线程: 2)多线程: 3)多进程:
压力测试工具JMeter入门教程 压力测试工具JMeter入门教程 1.Jmeter 概要描叙 jmeter 是一款专门用于功能测试和压力测试的轻量级测试开发平台。多数情况下是用作压力测试,该测试工具在阿里巴巴有着广泛的使用,估计是不要钱吧,哈哈,功能上来说,整个平台实现了许多和互联网相关的网络测试组件,同时还保留着很强的扩展性方便用于一些非标准的测试场景,让伟大的程序猿同学来告诉它该如何工作。
相关文章
- Linux以下基于TCP多线程聊天室(server)
- 城市经纬度 json 理解SignalR Main(string[] args)之args传递的几种方式 串口编程之端口 多线程详细介绍 递归一个List<T>,可自己根据需要改造为通用型。 Sql 优化解决方案
- 第二十三节: EF性能篇(三)之基于开源组件 Z.EntityFrameWork.Plus.EF6解决EF性能问题 第四节:一些指令总结 定时调度系列之Quartz.Net详解 第十七节:易混淆的概念(静态和非静态、拆箱和装箱) 那些年我们一起追逐的多线程(Thread、ThreadPool、委托异步调用、Task/TaskFactory、Parallerl、async和await)
- 158 python网络编程 - 多线程服务器
- C#【多线程篇】AutoResetEvent和ManualResetEvent的区别
- 《C#多线程编程实战(原书第2版)》——2.8 使用Barrier类
- 多线程 ForkJoinPool
- 关于C#中Timer定时器的重入问题解决方法(也适用于多线程)
- 由获取微信access_token引出的Java多线程并发问题
- C#多线程之Thread,ThreadPool,Task,Parallel
- 多线程面试题开胃菜10(5道)
- 多线程中的"断点"续传《notify()和wait()》
- C# 多线程学习系列四之ThreadPool取消、超时子线程操作以及ManualResetEvent和AutoResetEvent信号量的使用
- 【转】bat等大公司常考java多线程面试题