Ori Marko
Ori Marko

Reputation: 58892

JMeter - Pause (and resume) execution on demand

I'm executing JMeter task for a few hours on a server,

I want to be able to pause execution for a few seconds/minutes and resume when server finish restarted

Is there a way to signal JMeter to pause and resume its execution?

I saw similar question, but it doesn't fit my issue

Upvotes: 1

Views: 636

Answers (1)

Dmitri T
Dmitri T

Reputation: 168217

As of current JMeter version 5.3 there is no way to accomplish your "issue" with built-in JMeter components.

The easiest solution I can think if is: given you're restarting your server it should be not available for some time and when it becomes available - it should respond with a HTML page containing some text.

So you can "wait" for the server to be up and running as follows:

  1. Add JSR223 Sampler to the appropriate place in the Test Plan where you need to "wait' for the server to be up and running
  2. Put the following code into "Script" area:

    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. That's it, the code will try to open the web page and look for some text in it, if the page doesn't open and/or text is not present - it will wait for 5 seconds and retry

More information:

Upvotes: 1

Related Questions