我有一个gatling场景,我订阅了一个websocket,并希望检查收到的消息是否内部一致。
E.g。来自websocket的消息是<user>: <sequence number>
,我想检查每个用户字符串,序列号是连续的,从1开始增加。
a: 1
b: 1
a: 2
b: 2
a: 1 // <= this would be an error because last a was 2, so should be 3
我的第一种方法是在会话变量中存储类似Map[String, Int]
的内容。但在我看来,gatling webservice API不允许存储非字符串会话变量:
这(只是连接我们通过WS获得的所有内容)编译:
def updateState(text: String, session: Session): String = {
session("wsState").as[String] + "\n" + text
}
val scn = scenario("String")
.exec(ws("Connect WS")
.open("/indexWS?topic=${topic}")
.check(
wsListen
.within(3600.seconds)
.until(10)
.message
.find
.transform(updateState _)
.saveAs("wsState"))
)
但是只要updateState函数返回字符串以外的东西,它就不再编译了
def updateState(text: String, session: Session): Map[String, Int] = {
session("counts").as[Map[String, Int]] // + update from message text
}
val scn = scenario("String")
.exec(ws("Connect WS")
.open("/indexWS?topic=${topic}")
.check(
wsListen
.within(3600.seconds)
.until(10)
.message
.find
.transform(updateState _)
.saveAs("counts"))
)
以下是错误消息:
[error] found : io.gatling.core.check.CheckBuilder[io.gatling.http.check.ws.WsCheck,String,String,Int]
[error] required: io.gatling.http.check.ws.WsCheckBuilder
[error] (which expands to) io.gatling.core.check.CheckBuilder[io.gatling.http.check.ws.WsCheck, String, _, String]
现在显然我可以在每次更新时将地图序列化为字符串。但我宁愿避免这种情况。 gatling中似乎允许使用非字符串会话变量,为什么不在websockets中使用?