ngrinder项目-本地调试遇到的坑

server/2024/10/19 15:33:52/

前提-maven mirrors配置

 <mirrors><!--阿里公有仓库--><mirror><id>nexus-aliyun</id><mirrorOf>central</mirrorOf><name>Nexus aliyun</name><url>http://maven.aliyun.com/nexus/content/groups/public</url></mirror>
</mirrors>

问题1

描述:ngrinder-groovy3.4.jar包下载失败

ngrinder3.4创建的maven项目-ngrinder-groovy3.4依赖一直下载失败-解决办法

通过运行脚本,报错信息如下:

Cannot resolve org.ngrinder:ngrinder-groovy:pom:3.4 failed to transfer from https://github.com/naver/ngrinder/raw/ngrinder.maven.repo/releases during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of ngrinder.maven.repo has elapsed or updates are forced. Original error: Could not transfer artifact org.ngrinder:ngrinder-runtime:pom:3.4.4 from/to ngrinder.maven.repo (https://github.com/naver/ngrinder/raw/ngrinder.maven.repo/releases): transfer failed for https://github.com/naver/ngrinder/raw/ngrinder.maven.repo/releases/org/ngrinder/ngrinder-groovy/3.4/ngrinder-groovy-3.4.pom

解决:下载ngrinder-groovy-3.4.jar

1、通过运行脚本,报错信息可以看到,ngrinder-groovy-3.4.jar对应的ngrinder的github远程仓库地址为 https://github.com/naver/ngrinder/raw/ngrinder.maven.repo/releases

下载ngrinder-groovy-3.4.jar,如下图:

https://github.com/naver/ngrinder/tree/ngrinder.maven.repo/releases/org/ngrinder/ngrinder-groovy/3.4

点击下载 ngrinder-groovy-3.4.jar。

2、存储到项目对应的maven目录下,和线上仓库相同路径。

并且放入maven仓库对应的目录下(maven配置参考地址),如下:

C:\D\soft\Maven_Repo\org\ngrinder\ngrinder-groovy\3.4

刷新maven依赖,后依赖问题解决。

刷新maven依赖,后依赖问题解决。

###############

问题2

描述:本地调试脚本时,提示错误,如下

java.lang.RuntimeException: Please add -javaagent:C:\D\soft\Maven_Repo\net\sf\grinder\grinder-dcr-agent\3.9.1\grinder-dcr-agent-3.9.1.jar in 'Run As JUnit' vm argument.

解决:配置grinder-dcr-agent-3.9.1.jar

这个错误信息指示你需要在运行JUnit测试时,向Java虚拟机(JVM)添加一个Java代理(javaagent)参数。这个参数是为了加载grinder-dcr-agent-3.9.1.jar,它是Grinder分布式测试框架的一部分,用于监控和管理性能测试。

要解决这个问题,在你的IDEA中按照以下步骤操作:

IntelliJ IDEA:

  1. 打开运行/调试配置:在顶部菜单中选择“Run” -> “Edit Configurations...”。

  2. 选择或创建JUnit配置:在弹出的窗口中,找到你的测试类对应的JUnit配置,或者点击左上角的“+”号添加一个新的JUnit配置。

  3. 配置VM选项:在配置界面中,找到“VM options”字段。

  4. 添加代理参数:在此字段中,输入与Eclipse中相同的Java代理参数:-ea -javaagent:C:\D\soft\Maven_Repo\net\sf\grinder\grinder-dcr-agent\3.9.1\grinder-dcr-agent-3.9.1.jar,如图

  5. 检查下载的maven仓库中,C:\D\soft\Maven_Repo\net\sf\grinder\grinder-dcr-agent\3.9.1\grinder-dcr-agent-3.9.1.jar是正确的,并且该JAR文件存在于指定位置。如果路径有误,你需要根据实际情况调整,确保grinder-dcr-agent-3.9.1.jar文件正常。如果下载的文件不全,则删除不完整的文件后,重新下载。

  6. 应用并运行:点击“OK”应用设置,然后你可以直接运行这个配置来执行测试。运行正常。如图注意:本地调试ngrinder时,不需要启动agent客户端。

问题3:ngrinder-runtime下载失败

添加pom.xml 中添加 maven如下
        <dependency><groupId>org.ngrinder</groupId><artifactId>ngrinder-runtime</artifactId><version>3.4.4</version></dependency>
刷新maven时,idea项目提示如下错误

Cannot resolve org.ngrinder:ngrinder-runtime:pom:3.4.4 failed to transfer from https://github.com/naver/ngrinder/raw/ngrinder.maven.repo/releases during a previous attempt. This failure was cached in the local repository and resolution is not reattempted until the update interval of ngrinder.maven.repo has elapsed or updates are forced. Original error: Could not transfer artifact org.ngrinder:ngrinder-runtime:pom:3.4.4 from/to ngrinder.maven.repo (https://github.com/naver/ngrinder/raw/ngrinder.maven.repo/releases): transfer failed for https://github.com/naver/ngrinder/raw/ngrinder.maven.repo/releases/org/ngrinder/ngrinder-runtime/3.4.4/ngrinder-runtime-3.4.4.pom

错误提示表明

1、没有下载成功的依赖包名为:ngrinder-runtime-3.4.4.jar

2、通过远端仓库路径,对应本地仓库中没有下载成功的文件:maven本地仓库地址 + org/ngrinder/ngrinder-runtime/3.4.4/目录下,如图

3、也可以在本地maven仓库地址下搜索关键字:lastUpdated,也能查到上图未下载完成的文件。

4、可以通过maven下载失败的提示,从github,ngrinder远程仓库下载,远程仓库地址为:

https://github.com/naver/ngrinder/raw/ngrinder.maven.repo/releases

从远端参考下载jar包

下载ngrinder-runtime-3.4.4.jar文件后,放入对应的 本地maven本地仓库路径,刷新maven依赖。问题解决。

注意点

注意1:ngrinder-groovy依赖包

ngrinder的基础依赖,必须下载正常,否则几乎脚本的所有内容都报红。

        <dependency><groupId>org.ngrinder</groupId><artifactId>ngrinder-groovy</artifactId><version>${ngrinder.version}</version><scope>provided</scope></dependency>

读文件&发起http请求,只需要这一个依赖就足够了。

 注意2:读文件操作,和设置headers参数设置
@BeforeProcesspublic static void beforeProcess() {// 设置header参数List<NVPair> headerList = new ArrayList<NVPair>()headerList.add(new NVPair("Content-Type", "application/json"));headers = headerList.toArray()//获取数据,文件:/resources/phone.txtString path = this.getClassLoader().getResource("phone.txt").getPath()phoneNumList = new File(path).readLines(); #三行内容为 [111, 222, 333]}

注意3:json格式处理

如果接口返回的时json格式,压测脚本应导入工具类RecorderUtils

使用RecorderUtils类时,需要maven导入ngrinder-runtime-3.4.4.jar包。

        <dependency><groupId>org.ngrinder</groupId><artifactId>ngrinder-runtime</artifactId><version>3.4.4</version></dependency>

压测脚本: 

import org.ngrinder.recorder.RecorderUtils
import org.hamcrest.Matchers

#使用工具类的RecorderUtils.parseRequestToJson 方法解析json数据,使用如下:
def json_object = RecorderUtils.parseRequestToJson(result.getText()) println(json_object); println(json_object['msg']);

#assert方式如下 assertThat(json_object.get('msg'), Matchers.is("success")) assertThat(1,Matchers.is(1))
assertEquals(1,1)

注意4:生成随机字符串

需要maven导入依赖:

<dependency><groupId>org.apache.commons</groupId><artifactId>commons-lang3</artifactId><version>3.12.0</version> <!-- 可以指定为最新的稳定版本 -->
</dependency>

压测脚本编写导入RandomStringUtils

  1. 数字:RandomStringUtils.randomNumeric(length);

  2. 字母:RandomStringUtils.randomAlphabetic(length);

  3. 字母加数字:RandomStringUtils.randomAlphanumeric(length);

  4. 所有ASCCII字符:RandomStringUtils.randomAscii(length);

  5. 自定义混合字符:RandomStringUtils.randomAscii(length, string);

压测脚本:

import org.apache.commons.lang.RandomStringUtils
RandomStringUtils.randomNumeric(3)

pom.xml文件 参考

<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd"><modelVersion>4.0.0</modelVersion><groupId>ngrinder</groupId><artifactId>www.baidu.com</artifactId><version>0.0.1</version><properties><ngrinder.version>3.4</ngrinder.version><maven.compiler.source>1.7</maven.compiler.source><maven.compiler.target>1.7</maven.compiler.target><project.build.sourceEncoding>UTF-8</project.build.sourceEncoding></properties><repositories><!--<repository><id>ngrinder.maven.repo</id><url>https://github.com/naver/ngrinder/raw/ngrinder.maven.repo/releases</url></repository>--></repositories><dependencies><dependency><groupId>org.ngrinder</groupId><artifactId>ngrinder-groovy</artifactId><version>${ngrinder.version}</version><scope>provided</scope></dependency><dependency><groupId>net.sf.grinder</groupId><artifactId>grinder-core</artifactId><version>3.9.1</version></dependency><dependency><groupId>org.ngrinder</groupId><artifactId>grinder</artifactId><version>3.9.1-patch</version></dependency><dependency><groupId>net.sf.grinder</groupId><artifactId>grinder-http</artifactId><version>3.9.1</version></dependency><dependency><groupId>net.sf.grinder</groupId><artifactId>grinder-httpclient</artifactId><version>3.9.1</version></dependency><dependency><groupId>net.sf.grinder</groupId><artifactId>grinder-dcr-agent</artifactId><version>3.9.1</version></dependency><dependency><groupId>commons-httpclient</groupId><artifactId>commons-httpclient</artifactId><version>3.1</version></dependency><dependency><groupId>com.h2database</groupId><artifactId>h2</artifactId><version>1.3.168</version></dependency><dependency><groupId>commons-fileupload</groupId><artifactId>commons-fileupload</artifactId><version>1.3.1</version></dependency><dependency><groupId>commons-dbcp</groupId><artifactId>commons-dbcp</artifactId><version>1.4</version></dependency><dependency><groupId>cglib</groupId><artifactId>cglib</artifactId><version>2.2.2</version></dependency><!-- Json conversion --><dependency><groupId>com.google.code.gson</groupId><artifactId>gson</artifactId><version>2.2</version></dependency><dependency><groupId>junit</groupId><artifactId>junit-dep</artifactId><version>4.9</version><scope>compile</scope></dependency><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-api</artifactId><version>1.7.22</version></dependency><!-- https://mvnrepository.com/artifact/org.slf4j/slf4j-log4j12 --><dependency><groupId>org.slf4j</groupId><artifactId>slf4j-log4j12</artifactId><version>1.7.22</version></dependency><!-- Commons --><dependency><groupId>commons-io</groupId><artifactId>commons-io</artifactId><version>2.0.1</version></dependency><dependency><groupId>commons-lang</groupId><artifactId>commons-lang</artifactId><version>2.6</version></dependency><dependency><groupId>junit</groupId><artifactId>junit</artifactId><version>4.9</version><scope>compile</scope></dependency></dependencies><build><plugins><plugin><groupId>org.apache.maven.plugins</groupId><artifactId>maven-eclipse-plugin</artifactId><version>2.9</version><configuration><additionalProjectnatures><projectnature>org.eclipse.jdt.groovy.core.groovyNature</projectnature><projectnature>org.eclipse.m2e.core.maven2Nature</projectnature></additionalProjectnatures></configuration></plugin></plugins></build>
</project>

参考:

https://www.cnblogs.com/xiaowei89426/p/9365211.html

nGrinder介绍、编写脚本与执行(完整版)_ngrinder 压测脚本-CSDN博客


http://www.ppmy.cn/server/28629.html

相关文章

织梦云端:网络信号原理的艺术解码

hello &#xff01;大家好呀&#xff01; 欢迎大家来到我的Linux高性能服务器编程系列之《织梦云端&#xff1a;网络信号原理的艺术解码》&#xff0c;在这篇文章中&#xff0c;你将会学习到网络信号原理以及应用&#xff0c;并且我会给出源码进行剖析&#xff0c;以及手绘UML图…

Redis基本數據結構 ― Set

Redis基本數據結構 ― Set 介紹常用命令範例1. 將元素添加到集合2. 移除指定元素3. 獲取集合包含的所有元素4. 交集5. 聯集6. 差集 介紹 元素不能重複無序集合底層透過hash table實現 常用命令 命令功能SADD將元素添加到集合SREM從集合中移除元素SMOVE將元素從一個集合移動到…

使用FPGA实现串-并型乘法器

介绍 其实我们知道&#xff0c;用FPGA实现乘法器并不是一件很简单的事&#xff0c;而且在FPGA中也有乘法器的IP核可以直接调用&#xff0c;我这里完全就是为了熟悉一些FPGA的语法然后写了这样一个电路。 串-并型乘法器模块 从字面上看&#xff0c;串-并乘法器就是其中一个乘数…

unity制作app(1)--登录 注册 界面

把学到的知识投入到生产中反而是一件简单的事情&#xff01; 1.调整canvas的形状&#xff0c;这里和camera没有任何关系! overlay&#xff01; 2.既然自适应&#xff0c;空间按钮的位置比例就很重要了&#xff01; game窗口中新增720*1280的分辨率&#xff01; 3.再回到can…

fdfs安装启动及性能优化

fsatDFS安装 1、使用 wget 命令下载压缩包&#xff0c;如果没有 wget 命令使用 yum 命令安装 yum install wget 2、下载 fastdfs wget -c “https://github.com/happyfish100/fastdfs/archive/V6.06.tar.gz” 3、下载 libfastcommon wget -c “https://github.com/happyfish10…

Android 文件传输

目录 device explorer 文件目录关系对应&#xff1a; device explorer 经常写adb命令传文件&#xff0c;结果发现Android studio有自带的文件管理器&#xff0c;可以上传下载文件。 tool windows ->device explorer 文件目录关系对应&#xff1a; Android java获取的程序…

操作系统安全:安全审计,Windows系统日志详解,Windows事件ID汇总

「作者简介」&#xff1a;2022年北京冬奥会网络安全中国代表队&#xff0c;CSDN Top100&#xff0c;就职奇安信多年&#xff0c;以实战工作为基础对安全知识体系进行总结与归纳&#xff0c;著作适用于快速入门的 《网络安全自学教程》&#xff0c;内容涵盖系统安全、信息收集等…

【机器学习与流体力学交叉领域的期刊】

当涉及到机器学习与流体力学交叉领域的期刊时&#xff0c;以下是一些建议的期刊&#xff0c;这些期刊涵盖了机器学习和流体力学领域的最新研究和发展&#xff1a; Journal of Fluid Mechanics&#xff1a;这是流体力学领域的顶级期刊&#xff0c;虽然主要关注流体力学的理论、…