In simplest way I need to save result set of gatling tests to postgreSQL. In scenario I placed:
.exec(Report.writedbReportHeader)
Earlier I just push parameters from session and save them like this.
} .exec(session => { session.set(“startDate4Log”, LocalDateTime.now()) .set(“nanoTimeCreate”,System.nanoTime) })
I have code below. (I’am using 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 }
But it’s bring me and error
missing parameter type session =>
I also tried place exec under exec like it looks in save to file option. When my code look like below then only first run id’s are saved
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 + “’”) ) }
And working code for save in file example below.
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 }
Please give me tip how to exec JDBC statement in session or how to face this problem.