CSV parsing

190 views
Skip to first unread message

Aram

unread,
Dec 17, 2015, 8:55:12 AM12/17/15
to Gatling User Group
I am trying to parse a CSV, but am running into problems between the DSL and Scala

package scraper

import au.com.bytecode.opencsv.CSVWriter
import java.io.BufferedWriter
import java.io.FileWriter
import java.io.StringWriter
import io.gatling.core.session.Session

import scala.collection.JavaConversions._

object writeSwaggerValues extends App {

def createCSV () : Unit = {
val out = new BufferedWriter(new FileWriter("/home/aram/session.csv"))
val writer = new CSVWriter(out)
val swaggerSchema = Array("nickname", "path", "method")

val twitter = Array("${lastTweetsName}", "${lastTweetsPath}", "${lastTweetsMethod}")
val forecast = Array("${forecastName}", "${forecastPath}", "${forecastMethod}")
val listOfRecords = List(swaggerSchema, twitter, forecast)

writer.writeAll(listOfRecords)
out.close()
}
}

Stacktrace

error: overloaded method value exec with alternatives:
[ERROR]   (scenario: io.gatling.core.structure.ScenarioBuilder)io.gatling.core.structure.ScenarioBuilder <and>
[ERROR]   (chains: Iterable[io.gatling.core.structure.ChainBuilder])io.gatling.core.structure.ScenarioBuilder <and>
[ERROR]   (chains: Iterator[io.gatling.core.structure.ChainBuilder])io.gatling.core.structure.ScenarioBuilder <and>
[ERROR]   (chains: io.gatling.core.structure.ChainBuilder*)io.gatling.core.structure.ScenarioBuilder <and>
[ERROR]   (actionBuilder: io.gatling.core.action.builder.ActionBuilder)io.gatling.core.structure.ScenarioBuilder <and>
[ERROR]   (sessionFunction: io.gatling.core.session.Expression[io.gatling.core.session.Session])io.gatling.core.structure.ScenarioBuilder
[ERROR]  cannot be applied to (AnyVal)
[ERROR]   .exec(writeSwaggerValues.createCSV)
[ERROR]    ^


The problem is inthe return type if I am correct. I think the DSL chainbuilder want me to return Session (that is the reason for the import), but they I get:

error: type mismatch;
[ERROR]  found   : Unit
[ERROR]  required: io.gatling.core.session.Session
[ERROR]     out.close()
[ERROR]              ^

Does anyone have a idea to solve this?

Thank you


























adrian...@hushmail.com

unread,
Dec 17, 2015, 11:13:15 AM12/17/15
to gat...@googlegroups.com
You are returning the wrong type and I think the file I/O would be blocking. 

Is this a pre-test to extract data needed for the load test proper?

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Aram

unread,
Dec 18, 2015, 4:56:10 AM12/18/15
to Gatling User Group
Exactly. Basically I have a scraper in gatling that does one round. Then stores all the values in the session.

But I want to make a back up of my session values. I want to do this by writing to a Csv file. Then load the csv values to the real performance test.
But I cannot chain this simple csv witer in the .exec chain build because of the return value conflict.
Any idea's?
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+unsubscribe@googlegroups.com.

adrian...@hushmail.com

unread,
Dec 18, 2015, 6:49:18 AM12/18/15
to gat...@googlegroups.com
I'd probably use a logger and Unix tools to parse it.

val logger = org.slf4j.LoggerFactory.getLogger(this.getClass)

.exec { session => logger.warn(session("addComputer").as[String]); session } // used warn to lessen the noise

You'll need a logback.xml:

Or alternatively, post a gist of your logging code and simulation and I will try to get it to work. 
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.

For more options, visit https://groups.google.com/d/optout.

--
You received this message because you are subscribed to the Google Groups "Gatling User Group" group.
To unsubscribe from this group and stop receiving emails from it, send an email to gatling+u...@googlegroups.com.
Reply all
Reply to author
Forward
0 new messages