Gatling Load测试错误:406响应时不可接受

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

我是加特负载测试的新手。我想加载测试我的简单项目。但我得到了响应错误(406不可接受),我的加特林代码如下

import io.gatling.core.Predef._
import io.gatling.http.Predef._

class simu extends Simulation {


val httpConf = http
.baseURL("http://172.24.15.225:10050/sample")
.header(HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson)
.acceptHeader("application/json, text/plain, */*")
.acceptEncodingHeader("gzip, deflate")
.acceptLanguageHeader("en-US,en;q=0.5")

val scn = scenario("Scenario Name")
.exec(
  http("request_1")
  .post("http://172.24.15.225:10050/sample")
    .header(HttpHeaderNames.Accept, HttpHeaderValues.ApplicationJson)
    //.check(status.is(406))
   .body(StringBody("""{ "inputData": "Wonderful" }""")).asJSON
)

setUp(scn.inject(atOnceUsers(30)).protocols(httpConf))
} 

而上述的回应是

failed in Response
    Errors ------------------------------------------------------------
     status.find.in(200,304,201,202,203,204,205,206,207,208,209),       
    but actually found 406

有人请更正我的代码。但Rest API(postman)正确返回响应。

load-testing gatling
1个回答
0
投票

最后我找到了答案。在加载负载测试中没有错误。但问题是我的后端编码。我已将我的响应从String类型更改为JSON格式,如下所示

object ServiceJsonProtocol extends DefaultJsonProtocol {

implicit val RequestProtocol : RootJsonFormat[Text] = jsonFormat1(Text)//request json format

implicit val ResponseProtocol : RootJsonFormat[SampleText] = jsonFormat1(SampleText) // response json format

}

它工作正常

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