我在服务器上执行JMeter任务几个小时,
我希望能够暂停执行几秒钟/分钟,并在服务器完成重新启动时恢复
有没有办法向JMeter发出暂停并恢复执行的信号?
我看到了类似的问题,但它不适合我的问题
从当前的JMeter版本5.3开始,没有办法用内置的JMeter组件来完成你的"问题"。
我能想到的最简单的解决方案是:鉴于您正在重新启动服务器,它应该在一段时间内不可用,当它变得可用时 - 它应该以包含一些文本的 HTML 页面响应。
因此,您可以"等待"服务器启动并运行,如下所示:
- 将JSR223采样器添加到测试计划中需要"等待"服务器启动并运行的适当位置
-
将以下代码放入"脚本"区域:
import org.apache.http.client.config.RequestConfig import org.apache.http.client.methods.HttpGet import org.apache.http.impl.client.HttpClientBuilder import org.apache.http.util.EntityUtils SampleResult.setIgnore() def retry = true def requestConfig = RequestConfig.custom().setConnectTimeout(1000).setSocketTimeout(1000).build() def httpClient = HttpClientBuilder.create().setDefaultRequestConfig(requestConfig).build() while (retry) { def httpGet = new HttpGet('http://jmeter.apache.org') try { def entity = httpClient.execute(httpGet).getEntity() if (EntityUtils.toString(entity).contains('Apache JMeter')) { log.info('Application is up, proceeding') retry = false } else { log.info('Application is still down, waiting for 5 seconds before retry') sleep(5000) } } catch (Throwable ex) { sleep(5000) ex.printStackTrace() } }
- 就是这样,代码将尝试打开网页并在其中查找一些文本,如果页面没有打开和/或文本不存在 - 它将等待 5 秒钟并重试
更多信息:
- HttpClient 快速入门
- Apache Groovy - 为什么以及如何使用它