JMeter-按需暂停(和恢复)执行

问题描述 投票:1回答:1

我正在服务器上执行JMeter任务几个小时,

我希望能够暂停执行几秒钟/分钟,并在服务器完成重启后恢复执行

是否有信号通知JMeter暂停并恢复其执行?

我看到了similar question,但不适合我的问题

jmeter pause
1个回答
1
投票

截至当前JMeter version 5.3,尚无办法用built-in JMeter components完成您的“问题”。

我认为,最简单的解决方案是:鉴于您要重新启动服务器,因此它应该在一段时间内不可用,并且在服务器可用时-它应该以包含一些文本的HTML页面作为响应。

因此,您可以按照以下步骤“等待”服务器启动并运行:

  1. 将JSR223 Sampler添加到测试计划中您需要“等待”服务器启动并运行的适当位置
  2. 将以下代码放入“脚本”区域:

    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()
        }
    }
    
  3. 就是这样,代码将尝试打开网页并在其中查找一些文本,如果该页面没有打开和/或文本不存在-将等待5秒钟然后重试

更多信息:

© www.soinside.com 2019 - 2024. All rights reserved.