我使用JMeter属性来存储threadLocalCachedConnection对象。我确保使用唯一的属性名作为属性。
在线程组1中,我有一个JSR223 PostProcessor来抓取每个线程的会话(VU),然后将它存储在一个名为sessionID的属性中。

我在Thread Group1中添加了另一个PostProcessor,作为最后一个采样器的一个子程序。
def connection = sampler.threadLocalCachedConnection
props.put("presenterConnection" + ctx.getThreadNum(), connection.get())在线程组2中,我添加了一个JSR223 PreProcessor作为第一个采样器的子程序。
def presenterConnection = props.get('presenterConnection' + ctx.getThreadNum())
sampler.threadLocalCachedConnection.set(presenterConnection)

String sendCommand = "SEND\n" +
"content-type:application/json;charset=UTF-8\n" +
"destination:/v1/session/${__property(sessionId)}/command\n" +
"id:perftest01-presenter-${__property(sessionId)}\n" +
"\n" +
"{\"type\": \"go-to-slide\", \"data\": {\"index\": 0}}\n" +
'\0' // note: NULL char at end
;
vars.put("wsStompSendCommand", sendCommand);我用两个线程(VUs)进行了测试。为什么两个线程都使用最后一个sessionId而不是每个线程使用一个sessionId?
发布于 2022-07-12 08:20:48
根据JMeter文档
属性与变量不相同。变量是线程的本地变量;属性是所有线程的公共属性()。
所以你的台词
props.put('sessionId', vars.get('sessionUUID'))创建一个全局sessionId程序,即:
你需要和presenterConnection玩同样的把戏,比如:
props.put('sessionId_'+ ctx.getThreadNum(), vars.get('sessionUUID'))然后在需要的地方阅读:
def sessionId = props.get('sessionId_'+ ctx.getThreadNum())更多信息::Groovy用于什么?
https://stackoverflow.com/questions/72948930
复制相似问题