Hi,
Following are the steps :
- Establishing WS connection
- Subscribing to a topic with sendText
- Parsing server response
- Wait until server sends a notification for the subscribed topic whenever an event occurs.
- Then parse that reply
Please find below the complete code:
`
import scala.concurrent.duration._
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
class WebSockets extends Simulation {
val httpConf = http
.baseUrl("ws://x.x.x.x:8080/v2.0/api/name/dave/ws
")
.header(“Someheader”, “Value”)
.wsBaseUrl(“ws://x.x.x.x:8080/v2.0/api/name/dave/ws”)
val scn = scenario(“Load TESTING”)
.exec(ws(“Connect WS”).connect("ws://x.x.x.x:8080/v2.0/api/name/dave/ws
"))
.pause(1)
.exec(ws(“Send Notification Subscription”).sendText("""{
“type”: “PUT”,
“uri”: “/v1.0/api/name/dave/subscriptions”,
“body”: {
“subscriptions”: [
{
“resource_key”: “sales”
},
{
“resource_key”: “offers”
}
]
}
}""").await(10 seconds)
(ws.checkTextMessage(“Subs_Res_Body”).check(jsonPath("$").saveAs(“code”))))
.exec(session => {
val response = session(“code”).as[String]
println(s"Response body: \n$response")
session
})
//THIS PART WAITS FOR SERVER NOTIFICATION FOR AN EVENT TO OCCUR. UPON WHICH SERVER SENDS NOTIFICATION. NEED TO KNOW HOW THIS PART OF CODE SHOULD BE FORMED
.exec(ws(“Subscription Notification Message from Server”)
(ws.checkTextMessage(“SubsNotif_Res_Body”).check(await(60 seconds).until(1).jsonPath("$").saveAs(“ccode”))))
.exec(session => {
val response = session(“ccode”).as[String]
println(s"Notification Response body: \n$response")
session
})
.exec(ws(“Close WS”).close)
setUp(scn.inject(atOnceUsers(1))).protocols(httpConf)
}
`
Here, I need to know how to properly plug-in the second message check which server sends when there is any notification.
Thanks