I’m new to Scala.
I’m using Gatling for stress testing.
I’m able to make a Gatling test that makes a request to a WS, I save the JSON response in the session variable. The response is a JSON array that contains several links to images that are provided by my backend.
Specifically, The first request retrieves points in a map, each point has an image assigned, each image must be fetched by accessing the link provided by the response of the first WS.
I have following code:
class BasicSimulation extends Simulation
{
object Points
{
val jsonFileFeeder = jsonFile(“input.json”).circular
val points=exec(http(“r1”).get("/"))
.feed(jsonFileFeeder)
.exec(http(“r2”)
.post("/ws/getPoints")
.check(bodyString.saveAs(“points”))
)
}
object Images
{
val images=exec(session=>{
val respMap = session(“points”).as[String]
val mapper = new ObjectMapper()
val rA = mapper.readTree(respMap)
for( a ← 0 until (rA.size()-1))
{
val lnk=rA.get(a).get(“image”).toString()
exec(http(“r3”).get(lnk))
}
session
}
)
}
val httpConf = http
.baseURL(“http://localhost:8000/”)
.userAgentHeader(“Mozilla/5.0 (Macintosh; Intel Mac OS X 10.8; rv:16.0) Gecko/20100101 Firefox/16.0”)
val scn = scenario(“Test1”).exec(Points.points,Images.images)
setUp(scn.inject(atOnceUsers(2)).protocols(httpConf))
}
A sample of the JSON response of the first WS:
[
{
“bid”: 1375,
“image”: “http://localhost:8000/ws/image/1375”,
“position”: [2.326609,48.872678],
},
{
“bid”: 1375,
“image”: “http://localhost:8000/ws/image/1375”,
“position”: [2.352725,48.87323],
}
]
The first request works fine, I don’t parse the response with jsonPath since I get always the error:
could not extract : string matching regex [$_\p{L}][$_\-\d\p{L}]*' expected but
[’ found
Though I have veryfied my jsonpath expression with
https://jsonpath.curiousconcept.com/
With
import io.gatling.core.json.Jackson
I’m able to parse the response, the problem is that when trying to make
the second request exec(http(“r3”).get(lnk)), the request isn’t made, since
I’m logging on backend size the requests that are made, when making the first request, the backend logs the request, when making the second request, the request is not logged on backend side.
If I put the request directly depending on the scenario:
scenario(“Test1”).exec(http(“r”).get(“http://localhost:8000/ws/image/1375”))
The request is made.
I want to make a request to WS, parse the response, iterate over the JSON elements of the response and for each element make a second call to other webservice.
Thank you for your help.