运行groovy脚本总是报错

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

运行groovy脚本总是报错

littleboy
脚本如下:
import static net.grinder.script.Grinder.grinder
import static org.junit.Assert.*
import static org.hamcrest.Matchers.*
import net.grinder.plugin.http.HTTPRequest
import net.grinder.plugin.http.HTTPPluginControl
import net.grinder.script.GTest
import net.grinder.script.Grinder
import net.grinder.scriptengine.groovy.junit.GrinderRunner
import net.grinder.scriptengine.groovy.junit.annotation.BeforeProcess
import net.grinder.scriptengine.groovy.junit.annotation.BeforeThread
// import static net.grinder.util.GrinderUtils.* // You can use this if you're using nGrinder after 3.2.3
import org.junit.Before
import org.junit.BeforeClass
import org.junit.Test
import org.junit.runner.RunWith

import java.util.Date
import java.util.List
import java.util.ArrayList

import HTTPClient.Cookie
import HTTPClient.CookieModule
import HTTPClient.HTTPResponse
import HTTPClient.NVPair

/**
 * A simple example using the HTTP plugin that shows the retrieval of a
 * single page via HTTP.
 *
 * This script is automatically generated by ngrinder.
 *
 * @author admin
 */
@RunWith(GrinderRunner)
class TestRunner {

        public static GTest test
        public static HTTPRequest request
        public static NVPair[] headers = []
        public static NVPair[] params = []
        public static Cookie[] cookies = []

        @BeforeProcess
        public static void beforeProcess() {
                HTTPPluginControl.getConnectionDefaults().timeout = 6000
                test = new GTest(1, "www.baidu.com")
                request = new HTTPRequest()
                grinder.logger.info("before process.");
        }

        @BeforeThread
        public void beforeThread() {
                test.record(this, "test")
                grinder.statistics.delayReports=true;
                grinder.logger.info("before thread.");
        }
       
        @Before
        public void before() {
                request.setHeaders(headers)
                cookies.each { CookieModule.addCookie(it, HTTPPluginControl.getThreadHTTPClientContext()) }
                grinder.logger.info("before thread. init headers and cookies");
        }

        @Test
        public void test(){
                HTTPResponse result = request.GET("https://www.baidu.com", params)

                if (result.statusCode == 301 || result.statusCode == 302) {
                        grinder.logger.warn("Warning. The response may not be correct. The response code was {}.", result.statusCode);
                } else {
                        assertThat(result.statusCode, is(200));
                }
        }
}



错误日志如下:

2017-08-07 12:39:28,151 INFO  The Grinder version 3.9.1
2017-08-07 12:39:28,158 INFO  Java(TM) SE Runtime Environment 1.8.0_131-b11: Java HotSpot(TM) 64-Bit Server VM (25.131-b11, mixed mode) on Linux amd64 2.6.32-504.el6.x86_64
2017-08-07 12:39:28,162 INFO  time zone is CST (+0800)
2017-08-07 12:39:28,258 INFO  worker process 0 of agent number 0
2017-08-07 12:39:28,279 INFO  Instrumentation agents: byte code transforming instrumenter for Java; byte code transforming instrumenter for Java
2017-08-07 12:39:29,638 INFO  registered plug-in net.grinder.plugin.http.HTTPPlugin
2017-08-07 12:39:29,657 INFO  before process.
2017-08-07 12:39:29,660 INFO  Running "testgroovy.groovy" using GroovyScriptEngine running with groovy version: 2.2.1
2017-08-07 12:39:29,732 INFO  before thread.
2017-08-07 12:39:29,732 INFO  starting, will do 1 run
2017-08-07 12:39:29,733 INFO  Start time is 1502080769732 ms since Epoch
2017-08-07 12:39:29,806 INFO  before thread. init headers and cookies
2017-08-07 12:39:30,333 INFO  https://www.baidu.com/ -> 200 OK, 227 bytes
2017-08-07 12:39:30,375 INFO  finished 1 run
2017-08-07 12:39:30,377 INFO  elapsed time is 644 ms
2017-08-07 12:39:30,377 INFO  Final statistics for this process:
2017-08-07 12:39:30,387 INFO  
             Tests        Errors       Mean Test    Test Time    TPS          Mean         Response     Response     Mean time to Mean time to Mean time to
                                       Time (ms)    Standard                  response     bytes per    errors       resolve host establish    first byte  
                                                    Deviation                 length       second                                 connection                
                                                    (ms)                                                                                                    

Test 1       1            0            562.00       0.00         1.55         227.00       352.48       0            186.00       219.00       487.00        "www.baidu.com"

Totals       1            0            562.00       0.00         1.55         227.00       352.48       0            186.00       219.00       487.00      

  Tests resulting in error only contribute to the Errors column.          
  Statistics for individual tests can be found in the data file, including
  (possibly incomplete) statistics for erroneous tests. Composite tests  
  are marked with () and not included in the totals.
Reply | Threaded
Open this post in threaded view
|

Re: 运行groovy脚本总是报错

veryyoung
没报错啊
Reply | Threaded
Open this post in threaded view
|

Re: 运行groovy脚本总是报错

littleboy
日志信息后面总是打印如下error,看着挺别扭的
Tests resulting in error only contribute to the Errors column.          
  Statistics for individual tests can be found in the data file, including
  (possibly incomplete) statistics for erroneous tests. Composite tests  
  are marked with () and not included in the totals.