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

ops/2025/2/12 1:52:05/

前提-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/ops/28780.html

相关文章

Java中List<T>、List<?>、List<Object>、List<E>、List<U>的区别详解

前言 在Java中&#xff0c;泛型为程序员提供了编译时类型安全检查&#xff0c;减少了强制类型转换的需求&#xff0c;并提高了代码的可读性和重用性。List<T>、List<?>、List<Object>、List<E>、List<U>这些不同的泛型列表声明各有其特性和用途…

Docker-Compose概述与简单编排部署

目录 前言 一、Docker-Compose 概述 1、Docker-Compose 概念 2、Docker-Compose 优缺点 2.1 Docker-Compose 优点 2.2 Docker-Compose 缺点 3、Docker-Compose与Docker-Swarm的区别 二、两大文件格式 1、YAML 文件格式 2、JOSON 文件格式 3、YAML 与 JOSON 格式的区…

题目----移除元素

题目 给你一个数组 nums 和一个值 val&#xff0c;你需要 原地 移除所有数值等于 val 的元素&#xff0c;并返回移除后数组的新长度。 不要使用额外的数组空间&#xff0c;你必须仅使用 O(1) 额外空间并 原地 修改输入数组。 元素的顺序可以改变。你不需要考虑数组中超出新长…

19 做好微服务间依赖的治理和分布式事务

在前两讲里&#xff0c;分别从微服务的对外接口、消息消费以及微服务自身的相关编码规范上阐述了“防备上游、做好自己”这两个准则如何落地。 在本讲里&#xff0c;将会讲解为什么要“怀疑下游”&#xff0c;以及有哪些手段可以落地此条准则。此外&#xff0c;还会介绍在进行…

【SQL每日一练】统计复旦用户8月练题情况

文章目录 题目一、分析二、题解1.使用case...when..then2.使用if 题目 现在运营想要了解复旦大学的每个用户在8月份练习的总题目数和回答正确的题目数情况&#xff0c;请取出相应明细数据&#xff0c;对于在8月份没有练习过的用户&#xff0c;答题数结果返回0. 示例代码&am…

Docker consul 的容器服务更新与发现

目录 一. consul 的相关知识 1 什么是注册与发现 2. 什么是 consul 3. zookeeper 和 consul 的区别 二. consul 部署 1. consul 服务器 2. registrator 服务器 三. consul-template 1. consul-template 的作用 2. consul-template 的具体部署运用 2.1 准备 templa…

将后端返回的正则字符串转为正则对象

/*这个正则表示的是输入框前后不得有空格*/ let re v.regex.replace("\n", ""); // 将后端返回的正则字符串转为正则对象 let reg new Function("return " re)(); if (reg.test(v.value) true) { /*所需要写的事件*/ } else { /*空格的时候的…

LNMP部署wordpress

1.环境准备 总体架构介绍 序号类型名称外网地址内网地址软件02负载均衡服务器lb0110.0.0.5192.168.88.5nginx keepalived03负载均衡服务器lb0210.0.0.6192.168.88.6nginx keepalived04web服务器web0110.0.0.7192.168.88.7nginx05web服务器web0210.0.0.8192.168.88.8nginx06we…