surefire单元测试 并发 提速-程序员宅基地

技术标签: 单元测试与powerMock  

http://maven.apache.org/surefire/maven-surefire-plugin/examples/fork-options-and-parallel-execution.html

这是官方地址


parallel 这个参数可以说是很重要的参数,因为其控制并发执行的对象,基于它我们可以设置并发执行类,类中的方法或者测试集suits.

The most obviousone is by using the parallel parameter. The possible values dependon the test provider used. For JUnit 4.7 and onwards, this may be methodsclassesbothsuitessuitesAndClassessuitesAndMethodsclassesAndMethods or all. As aprerequisite in JUnit tests, the JUnit runner should extend org.junit.runners.ParentRunner. If no runner is specified through theannotation @org.junit.runner.RunWith, the prerequisite is accomplished.

As ofmaven-surefire-plugin:2.16, the value "both" isdeprecated but it still can be used and behaves same as classesAndMethods.

这是官方上的原文,语音也很简单,就是说明 parallel可以有哪些属性值和含义,methodsclassessuites,以及两两的组合和all.  

surefire 2.16版本是对于并发配置而言是一个变更的节点。2.16以上版本属性和属性名上发生了很多变化。或者可以说是里程碑。

几个例子:

As an example with an unlimited number of threads, there is maximum ofthree concurrent threads to execute suites: parallel=alluseUnlimitedThreads=truethreadCountSuites=3.  并发,不限制线程数,但是suits线程数是3.

这里又提到useUnlimitedThreads 和threadCountSuites 属性。

那么必然也有threadCountClasses属性  和  threadCountMethods 属性


In the second example, the number of concurrent methods is not strictlylimited: parallel=classesAndMethodsthreadCount=8threadCountClasses=3. Here thenumber of parallel methods is varying from 5 to 7. Accordingly parallel=all, but the sumof threadCountSuites and threadCountClasses must notexceed certain (threadCount - 1). Other combinations are possiblewith unspecified thread-count leaf. Make sure that the leaf islast from the order suites-classes-methods in parallel.

这个例子宽泛定义了method线程数的区间。


In the third example the thread-counts represent a ratio, e.g. for parallel=allthreadCount=16threadCountSuites=2threadCountClasses=3threadCountMethods=5. Thus theconcurrent suites will be 20%, concurrent classes 30%, and concurrent methods50%.

线程数,百分比的定义。



The parameters parallelTestsTimeoutInSeconds and parallelTestsTimeoutForcedInSeconds are usedto specify an optional timeout in parallel execution. If the timeout iselapsed, the plugin prints the summary log with ERROR lines: "Thesetests were executed in prior to the shutdown operation", and "Thesetests are incomplete" if the running Threads were interrupted.

这是 parallelTestsTimeoutInSeconds  parallelTestsTimeoutForcedInSeconds    说明。大概意思:

参数parallelTestsTimeoutInSeconds和parallelTestsTimeoutForcedInSeconds用于在并行执行中指定可选超时。如果超时过期,插件将使用错误行打印摘要日志:“这些测试在关闭操作之前执行”,如果正在运行的线程中断,则“这些测试不完整”。


forkCount 进程级别限制:

The parameter forkCount definesthe maximum number of JVM processes that maven-surefire-plugin will spawn concurrently toexecute the tests. It supports the same syntax as -T  in maven-core:if you terminate the value with a 'C', that value will be multiplied with thenumber of available CPU cores in your system. For example forkCount=2.5C on aQuad-Core system will result in forking up to ten concurrent JVM processes thatexecute tests.

The parameter reuseForks is used todefine whether to terminate the spawned process after one test class and tocreate a new process for the next test in line (reuseForks=false), or whether toreuse the processes to execute the next tests (reuseForks=true).

这里提及到 forkCount  和  reuseForks 两个重要的参数;forkcount 控制jvm进程数,reuseForks 设置进程数的可增长性。

CombiningforkCount and parallel

The modes forkCount=0 and forkCount=1/reuseForks=true canbe combined freely with the available settings for parallel.

As reuseForks=false creates a new JVM process for each test class, using parallel=classes wouldhave no effect. You can still use parallel=methods, though.

When using reuseForks=true anda forkCount valuelarger than one, test classes are handed over to the forked process one-by-one.Thus, parallel=classes wouldnot change anything. However, you can use parallel=methods: classes are executed in forkCount concurrent processes, each of the processes can thenuse threadCount threadsto execute the methods of one class in parallel.

forkCount = 0和forkCount = 1 /reuseForks = true的模式可以与可用的并行设置自由组合。

由于reuseForks = false为每个测试类创建一个新的JVM进程,使用parallel = classes将不起作用。你仍然可以使用parallel = methods。

当使用reuseForks = true和大于1的forkCount值时,测试类将逐个移交给并发出来的进程。因此,parallel = classes不会改变任何东西。但是,可以使用parallel =methods,parellel限制了类不能并发,但在forkCount并发进程中可以执行类,然后每个进程可以使用threadCount线程并行执行一个类的方法。   这句话说明

了parallel只能限制在jvm内部是并发执行方法或者类,说白是限制线程,而对进程没有约束。parallel和forkcount分别是线程和进程级别。


Migratingthe Deprecated forkMode Parameter to forkCount and reuseForks

surefire versions prior 2.14 used theparameter forkMode to configure forking. Although that parameter is stillsupported for backward compatibility, users are strongly encouraged to migratetheir configuration and use forkCount and reuseForks instead.

The migration is quite simple, giventhe following mapping:

将已弃用的forkMode参数迁移到forkCount和reuseForks

surefire版本之前2.14使用参数forkMode配置分岔。尽管该参数仍然支持向后兼容性,但强烈建议用户迁移其配置,并使用forkCount和reuseForks。

Old Setting

New Setting

forkMode=once (default)

forkCount=1(default), 

reuseForks=true (default)

forkMode=always

forkCount=1 (default), reuseForks=false

forkMode=never

forkCount=0

forkMode=perthreadthreadCount=N

forkCount=N, (reuseForks=false,

 if you did not had that one set)



版权声明:本文为博主原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://blog.csdn.net/lxlmycsdnfree/article/details/77886072

智能推荐

总线概述及常见总线(转)-程序员宅基地

文章浏览阅读5.3k次。目录(?)[+]一 总线概念二 常见总线一. 总线概念所谓总线(Bus),是指计算机设备和设备之间传输信息的公共数据通道。总线是连接计算机硬件系统内多种设备的通信线路,它的一个重要特征是由总线上的所有设备共享,可以将计算机系统内的多种设备连接到总线上。如果是某两个设备或设备之间专用的信号连线,就不能称之为总线。系统总线架构图如下所示: 微机中的总线分为数据总线、地址总线和控制总线3类。..._总线

龙贝格积分法C++11实现_romberg c++-程序员宅基地

文章浏览阅读6.4k次。龙贝格积分,数学,算法,C++11,代码_romberg c++

Oracle JAVAVM 组件 Reload 说明_java vm组件更新-程序员宅基地

文章浏览阅读1.1w次。一.JAVAVM 组件 说明 有关Oracle 所有组件的概述,参考:Oracle 8i/9i/10g/11g 组件(Components) 说明http://blog.csdn.net/tianlesoftware/article/details/5937382 现在我们查看组件的信息:SQL> col comp_id for a15SQL> col version for a15SQL> co_java vm组件更新

Spring Boot Actuator 未授权的测试与利用思路_sb-actuator-程序员宅基地

文章浏览阅读1.9k次,点赞2次,收藏4次。Spring Boot Actuator 未授权的测试与利用思路0x0 前言  最近遇到的一个漏洞,但是因为目标关掉了一些端点导致没利用起来达到RCE的效果,不过在提升漏洞危害的时候,参考了不少文章,也做了一些尝试,所以分享出来自己的经历,希望大家如果遇到跟我一样的情况,可以省下自己调试时间,来做更有意义的事情。0x1 Actuator 简介官方简介: Spring Boot Actuator: Production-ready FeaturesSpring Bo..._sb-actuator

在python3.7+vs2019环境下使用f2py将fortran和c++程序编译为python库_python调用fortran代码-程序员宅基地

文章浏览阅读1.3k次。在python3.7+vs2019环境下使用f2py将fortran和c++程序编译为python库前言步骤1安装Fortran和Visual Studio编译环境2配置vs在python中的路径3测试c++编译环境4测试Fortran编译环境参考链接前言今天务必开贴记录下将Fortran或c++程序编译为python库的方法。起因是老师给了一个Fortran函数,无奈本人看不懂,因而想办法..._python调用fortran代码

uboot模式下怎么备份uboot和uImage_uboot备份固件命令-程序员宅基地

文章浏览阅读1.3k次。uboot中如果支持spi/qspi flash, 那么可以使用sf的erase, read, write命令操作spi flashsf read用来读取flash数据到内存sf write写内存数据到flashsf erase 擦除指定位置,指定长度的flash内容, 擦除后内容全1以备份uboot文件举例:1 、设置环境变量setenv serverip 192.168.230.111setenv ipaddr 192.168.230.124saping 192.168.230.111_uboot备份固件命令

随便推点

《APUE》笔记-第六章-系统数据文件和信息_intitle:"根据用户名调用getspnam获取对应的spwd项-程序员宅基地

文章浏览阅读577次。1.口令文件口令文件,即Unix系统用户数据库,存储在/etc/passwd中,是一个ASCII文件,包含的字段信息在定义的passwd数据结构中。  pwd.h文件所在位置:/usr/include/pwd.hstruct passwd{ char *pw_name; char *pw_passwd; uid_t uid; _intitle:"根据用户名调用getspnam获取对应的spwd项

[bzoj2638]黑白染色——思维题+最短路_黑白染色 bzoj-程序员宅基地

文章浏览阅读854次。题目大意:你有一个n*m的矩形,一开始所有格子都是白色,然后给出一个目标状态的矩形,有的地方是白色,有的地方是黑色,你每次可以选择一个连通块(四连通块,且不要求颜色一样)进行染色操作(染成白色或者黑色)。问最少操作次数。思路:可以证明每一次操作的范围都是上一次操作的子集,并且颜色与上一次相反(但是我不会证)。于是我们可以把黑色连通块和白色连通块之间互相连边,这样就形成了一个图,我们枚举最后..._黑白染色 bzoj

Codeforces 1511D. Min Cost String(构造)_codefroces 字符串 构造-程序员宅基地

文章浏览阅读354次。传送门题目描述给出一个字符串sss,若其两个位置i,j(i<j<n)i, j(i < j < n)i,j(i<j<n)满足ai=aj && ai+1=aj+1a_i = a_j ~~\&\&~~ a_{i+1} = a_{j+1}ai​=aj​ && ai+1​=aj+1​那么会对该字符串的价值加一,给定n,kn,kn,k,仅适用_codefroces 字符串 构造

zcmu-1951_zcmu oj 1951-程序员宅基地

文章浏览阅读133次。1951: ly和wjw的无聊游戏Time Limit: 1 Sec Memory Limit: 128 MBSubmit: 60 Solved: 20[Submit][Status][Web Board]Description 众所周知,ly和wjw是好朋友,某天特别无聊,他们想自己编一个游戏代码,无奈水平有限,只会写个random每次输出一个随机数,于是他们自己制定了一个游..._zcmu oj 1951

matlab做互相关实验(1024程序员节投稿)_互相关的实验验证-程序员宅基地

文章浏览阅读4.9k次,点赞2次,收藏23次。摘要:振动测试有的时候需要做互相关,本文演示一个简单的互相关实验。_互相关的实验验证

河北工业大学城市学院2019级-计算机网络实验报告一_城市学院计算机网络实验教程报告-程序员宅基地

文章浏览阅读107次。《计算机网络》实 验 报 告实验名称: 连接Internet 学生姓名: 学 号: 专业班级: 实验时间: 实验目的(注:标题三号、黑体;正文小四号宋体,1.5倍行距)写出_城市学院计算机网络实验教程报告