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 String body = "{\n \"kind\": \"Service\", \n \"apiVersion\": \"v1\", \n \"metadata\": {\n \"name\": \"omc-tomcat7\"\n }, \n \"spec\": {\n \"selector\": {\n \"role\": \"omc-tomcat7\"\n }, \n \"ports\": [\n {\n \"protocol\": \"TCP\"\n }, \n {\n \"port\": \"8080\"\n }, \n {\n \"targetPort\": \"8080\" \n }\n ]\n }\n}" public static Cookie[] cookies = [] @BeforeProcess public static void beforeProcess() { HTTPPluginControl.getConnectionDefaults().timeout = 6000 test = new GTest(1, "181") request = new HTTPRequest() // Set header datas List<NVPair> headerList = new ArrayList<NVPair>() headerList.add(new NVPair("Content-Type", "application/json")) headers = headerList.toArray() 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.POST("http://172.18.1.181:9326/api/v1/namespaces/default/services", body.getBytes()) //print logInfo grinder.logger.info(result.getText()); grinder.logger.info(result.getHeader("Content-type")); 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)); } } } ----------------------------------------------------------------------------- Result (errorInfo) as follows: 2017-08-07 16:50:48,321 INFO The Grinder version 3.9.1 2017-08-07 16:50:48,343 INFO Java(TM) SE Runtime Environment 1.7.0_51-b13: Java HotSpot(TM) 64-Bit Server VM (24.51-b03, mixed mode) on Windows 7 amd64 6.1 2017-08-07 16:50:48,351 INFO time zone is CST (+0800) 2017-08-07 16:50:48,542 INFO worker process 0 of agent number 0 2017-08-07 16:50:48,596 INFO Instrumentation agents: byte code transforming instrumenter for Java; byte code transforming instrumenter for Java 2017-08-07 16:50:50,764 INFO registered plug-in net.grinder.plugin.http.HTTPPlugin 2017-08-07 16:50:50,872 INFO before process. 2017-08-07 16:50:50,877 INFO Running "groovy181-resource.groovy" using GroovyScriptEngine running with groovy version: 2.2.1 2017-08-07 16:50:50,983 INFO before thread. 2017-08-07 16:50:50,997 INFO starting, will do 1 run 2017-08-07 16:50:50,997 INFO Start time is 1502095850997 ms since Epoch 2017-08-07 16:50:51,043 INFO before thread. init headers and cookies 2017-08-07 16:50:51,111 INFO http://172.18.1.181:9326/api/v1/namespaces/default/services -> 400 Bad Request, 217 bytes 2017-08-07 16:50:51,123 INFO {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Service in version \"v1\" cannot be handled as a Service: [pos 245]: json: decNum: got first char '\"'","reason":"BadRequest","code":400} 2017-08-07 16:50:51,123 INFO application/json 2017-08-07 16:50:51,171 ERROR Expected: is <200> got: <400> java.lang.AssertionError: Expected: is <200> got: <400> at TestRunner.test(groovy181-resource.groovy:83) ~[na:na] at net.grinder.scriptengine.groovy.junit.GrinderRunner.run(GrinderRunner.java:170) ~[ngrinder-groovy-3.4.1.jar:na] at net.grinder.scriptengine.groovy.GroovyScriptEngine$GroovyWorkerRunnable.run(GroovyScriptEngine.java:147) ~[ngrinder-groovy-3.4.1.jar:na] at net.grinder.engine.process.GrinderThread.run(GrinderThread.java:118) ~[grinder-core-3.9.1.jar:na] 2017-08-07 16:50:51,174 INFO finished 1 run 2017-08-07 16:50:51,179 INFO elapsed time is 182 ms 2017-08-07 16:50:51,179 INFO Final statistics for this process: 2017-08-07 16:50:51,201 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 0 1 ? 0.00 0.00 ? 0.00 0 ? ? ? "181" Totals 0 1 ? 0.00 0.00 ? 0.00 0 ? ? ? 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. 2017-08-07 16:50:50,888 INFO validation-0: Starting threads 2017-08-07 16:50:51,201 INFO validation-0: Finished |
after removing the " before demical 8080, as follows:
public static String body = "{\n \"kind\": \"Service\", \n \"apiVersion\": \"v1\", \n \"metadata\": {\n \"name\": \"omc-tomcat7\"\n }, \n \"spec\": {\n \"selector\": {\n \"role\": \"omc-tomcat7\"\n }, \n \"ports\": [\n {\n \"protocol\": \"TCP\"\n }, \n {\n \"port\": 8080\n }, \n {\n \"targetPort\": 8080 \n }\n ]\n }\n}" -------------------------------------------------------------------- Then the error result is also show , the content is : 2017-08-07 16:54:57,527 INFO The Grinder version 3.9.1 2017-08-07 16:54:57,541 INFO Java(TM) SE Runtime Environment 1.7.0_51-b13: Java HotSpot(TM) 64-Bit Server VM (24.51-b03, mixed mode) on Windows 7 amd64 6.1 2017-08-07 16:54:57,549 INFO time zone is CST (+0800) 2017-08-07 16:54:57,752 INFO worker process 0 of agent number 0 2017-08-07 16:54:57,808 INFO Instrumentation agents: byte code transforming instrumenter for Java; byte code transforming instrumenter for Java 2017-08-07 16:55:00,199 INFO registered plug-in net.grinder.plugin.http.HTTPPlugin 2017-08-07 16:55:00,271 INFO before process. 2017-08-07 16:55:00,292 INFO Running "groovy181-resource.groovy" using GroovyScriptEngine running with groovy version: 2.2.1 2017-08-07 16:55:00,399 INFO before thread. 2017-08-07 16:55:00,399 INFO starting, will do 1 run 2017-08-07 16:55:00,399 INFO Start time is 1502096100399 ms since Epoch 2017-08-07 16:55:00,439 INFO before thread. init headers and cookies 2017-08-07 16:55:00,500 INFO http://172.18.1.181:9326/api/v1/namespaces/default/services -> 422 Unprocessable Entity, 1214 bytes 2017-08-07 16:55:00,530 INFO {"kind":"Status","apiVersion":"v1","metadata":{},"status":"Failure","message":"Service \"omc-tomcat7\" is invalid: [spec.ports[0].name: Required value, spec.ports[0].port: Invalid value: 0: must be between 1 and 65535, inclusive, spec.ports[0].targetPort: Invalid value: 0: must be between 1 and 65535, inclusive, spec.ports[1].name: Required value, spec.ports[2].name: Required value, spec.ports[2].port: Invalid value: 0: must be between 1 and 65535, inclusive]","reason":"Invalid","details":{"name":"omc-tomcat7","kind":"Service","causes":[{"reason":"FieldValueRequired","message":"Required value","field":"spec.ports[0].name"},{"reason":"FieldValueInvalid","message":"Invalid value: 0: must be between 1 and 65535, inclusive","field":"spec.ports[0].port"},{"reason":"FieldValueInvalid","message":"Invalid value: 0: must be between 1 and 65535, inclusive","field":"spec.ports[0].targetPort"},{"reason":"FieldValueRequired","message":"Required value","field":"spec.ports[1].name"},{"reason":"FieldValueRequired","message":"Required value","field":"spec.ports[2].name"},{"reason":"FieldValueInvalid","message":"Invalid value: 0: must be between 1 and 65535, inclusive","field":"spec.ports[2].port"}]},"code":422} 2017-08-07 16:55:00,532 INFO application/json 2017-08-07 16:55:00,584 ERROR Expected: is <200> got: <422> java.lang.AssertionError: Expected: is <200> got: <422> at TestRunner.test(groovy181-resource.groovy:83) ~[na:na] at net.grinder.scriptengine.groovy.junit.GrinderRunner.run(GrinderRunner.java:170) ~[ngrinder-groovy-3.4.1.jar:na] at net.grinder.scriptengine.groovy.GroovyScriptEngine$GroovyWorkerRunnable.run(GroovyScriptEngine.java:147) ~[ngrinder-groovy-3.4.1.jar:na] at net.grinder.engine.process.GrinderThread.run(GrinderThread.java:118) ~[grinder-core-3.9.1.jar:na] 2017-08-07 16:55:00,587 INFO finished 1 run 2017-08-07 16:55:00,593 INFO elapsed time is 195 ms 2017-08-07 16:55:00,593 INFO Final statistics for this process: 2017-08-07 16:55:00,615 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 0 1 ? 0.00 0.00 ? 0.00 0 ? ? ? "181" Totals 0 1 ? 0.00 0.00 ? 0.00 0 ? ? ? 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. 2017-08-07 16:55:00,305 INFO validation-0: Starting threads 2017-08-07 16:55:00,616 INFO validation-0: Finished + |
Free forum by Nabble | Edit this page |