以最简单的方式,我需要将加特林测试的结果集保存到PostgreSQL。 在方案中,我放置了:
.exec(Report.writedbReportHeader)
以前,我只是从会话中推送参数,并像这样保存它们。
}
.exec(session => {
session.set("startDate4Log", LocalDateTime.now())
.set("nanoTimeCreate",System.nanoTime)
})
我下面有代码。 (我正在使用rbraeunlich / gatling-jdbc libarary)
val writedbReportHeader: ChainBuilder = {
session =>
val dbc_test_name = testName
val dbc_environment = envType
val dbc_startDate = "${startDate}"
val dbc_endDate = "${endDate}"
val dbc_communityID = "${communityID}"
val dbc_groupID = "${groupID}"
val dbc_businessSegments = "${businessSegments}"
val dbc_storyTopics = "${storyTopics}"
exec(jdbc("insertion")
.insert()
.into("audit.log_performance_header(test_name, environment, startDate, endDate, communityID, groupID, businessSegments, storyTopics)")
.values("'" + dbc_test_name + "', '" + dbc_environment + "', '" + dbc_startDate + "', '" + dbc_endDate + "', '" + dbc_communityID + "', '" + dbc_groupID + "', '" + dbc_businessSegments + "', '" + dbc_storyTopics + "'")
)
session
}
但这给我带来了错误
缺少参数类型 会话=>
我也尝试将exec放在exec下,就像它在“保存到文件”选项中一样。 当我的代码如下所示时,则仅保存第一次运行的ID:(
val writedbReportHeader: ChainBuilder = {
val dbc_test_name = testName
val dbc_environment = envType
val dbc_startDate = "${startDate}"
val dbc_endDate = "${endDate}"
val dbc_communityID = "${communityID}"
val dbc_groupID = "${groupID}"
val dbc_businessSegments = "${businessSegments}"
val dbc_storyTopics = "${storyTopics}"
exec(jdbc("insertion")
.insert()
.into("audit.log_performance_header(test_name, environment, startDate, endDate, communityID, groupID, businessSegments, storyTopics)")
.values("'" + dbc_test_name + "', '" + dbc_environment + "', '" + dbc_startDate + "', '" + dbc_endDate + "', '" + dbc_communityID + "', '" + dbc_groupID + "', '" + dbc_businessSegments + "', '" + dbc_storyTopics + "'")
)
}
以及下面用于保存在文件示例中的工作代码。
val writeReportHeader: ChainBuilder =
exec { session =>
val writer = new PrintWriter(new FileOutputStream(new File(logFile), true))
writer.write("================================================================================================\n")
writer.write("Test parameters: \n")
writer.write("Test name: " + testName + "\n")
writer.write("Environment: " + envType + "\n")
writer.write("- startDate: " + session("startDate").as[String] + "\n")
writer.write("- endDate: " + session("endDate").as[String] + "\n")
writer.write("- communityID: " + session("communityID").as[String] + "\n")
writer.write("- groupID: " + session("groupID").as[String] + "\n")
writer.write("- businessSegments: " + session("businessSegments").as[String] + "\n")
writer.write("- storyTopics: " + session("storyTopics").as[String] + "\n\n")
writer.close()
session
}
请给我提示如何在会话中执行JDBC语句或如何面对此问题。