![](/img/trans.png)
[英]Accessing HttpServletRequest and Response from JSR223 sampler within Jmeter
[英]Read response from JSR223 Assertion to Java Code
我想從 Java 代碼中讀取處理后的值。 我的 jmx 中有一個 jsr233 斷言,它處理了值 ({"timestamp": 23893865465, "diff": 34}) 我想在我的 JMeterEngine 實例中調用 run() 命令后在我的 java 代碼中讀取這個。
我嘗試使用 SamplerListner 但不工作。 我如何閱讀該回復。
JSR 233 斷言代碼:
mport groovy.json.JsonBuilder
String totalIDs = vars.get("assetIdCount_matchNr");
Integer result = Integer.valueOf(totalIDs);
Date currentDate = new Date();
if (result > 10){
vars.put("SEARCH_SUCCESS_TIMESTAMP",currentDate.getTime().toString());
log.info("ASSET_CREATION_TIMESTAMP:" + props.get("ASSET_CREATION_TIMESTAMP"));
log.info("ASSET_CREATION_TIMESTAMPAfter:" + props.get("ASSET_CREATION_TIMESTAMP"));
log.info("SEARCH_SUCCESS_TIMESTAMP:" + vars.get("SEARCH_SUCCESS_TIMESTAMP"));
def diff = Long.valueOf(vars.get("SEARCH_SUCCESS_TIMESTAMP").toString()) - Long.valueOf(props.get("ASSET_CREATION_TIMESTAMP").toString());
def timestamp = vars.get("SEARCH_SUCCESS_TIMESTAMP");
vars.putObject("Diff", diff);
log.info(String.valueOf(diff));
def json = new JsonBuilder()
def root = json timestamp: "5241234134134", diff: "345"
def file = new File(vars.get("file_location").toString())
file.write('\n'+json.toString());
sleep 10
AssertionResult.setFailure(true);
}
Java碼
StandardJMeterEngine jmeterSecondary = configJmeter(jmxFileName, argumentObject, jmeter, jMeterAssetECListnerService); //get the jmeter to run by configuring it
jmeterSecondary.run();
// I want to get the timestamp and diff here
jmeterSecondary.reset();
jmeterSecondary.exit();
提前致謝!
我能想到的最簡單的選擇是使用System.setProperty() function 將值寫入 JSR223 斷言中的 Java 系統屬性。
整個 JVM 的系統屬性是全局的,因此您可以在調用jmeterSecondary.run();
后使用System.getProperty() function 訪問它;
示例用法:
有關不同 JMeter 屬性類型和使用它們的方式的更多信息: Apache JMeter 屬性自定義指南
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.