it seams exec is waiting for a chain / scenario builder (or a validation
object).
Yep, exactly. And here, you don't return anything (you use the deprecated
procedure style).
procedure style:
def myAction() { //do some stuff }
equivalent to (proper method style, return Unit, ie nothing):
def myAction(): Unit = { //do some stuff }
What you should be doing:
def myAction(): ChainBuilder = { //do some stuff }
or (letting compiler infer return type)
def myAction() = { //do some stuff }
It seems you're trying to write some Scala code without any Scala very
basics. if so, you really should have a look at the first chapters from
Twitter's Scala school: Scala School
In adding ChainBuilder return type I have a type mismatch error on “<-” operator.
It seems you’re trying to write some Scala code without any Scala very basics. if so, you really should have a look at the first chapters from Twitter’s Scala school: https://twitter.github.io/scala_school/
You’re right, I read first lines of this tutorial but it seems it’s not enough Sorry for asking beginners questions, I’ll try to read more carefully this guide !
No offense, but you’re really trying to jump right into the code while you don’t know some basics about the language. So you’re trying to write some random Java stuff and crossing fingers that it might somehow work.
Hold your horses, read some Scala tutorial and Gatling advanced documentation for a few hours and you’ll be set!
Perhaps my approach is too Java-oriented but I imagine that exec is waiting for a specific method to call and that ChainBuilder is a kind of interface. I read scala school first chapters and no idea comes to me… is there a way to encapsulate scala code into ChainBuilder or I have to use exclusively gatling stuff ?
What I want to do is simple : I have two csv files. For each row of the first file, I want to call a method that parses second file and execute some code, knowing first file row value.
“notifyAllCompanies” parses first file and calls “notifyCompanyEntries” with row value. I don’t think this it is possible to encapsulate both treatments into gatling builder… am I wrong ? In addition, I thought this could be too spaghetti code.
No. Your approach is imperative programming oriented, based on mutability, and your problem lies here. It has nothing to do with the language but with the way your using it.
My class seems like that (I removed useless data for your comprehension) :
`
class MyClass extends Simulation {
val machine = “machineName”
val baseUri = “http://”+machine+"/baseUri";
val uri="/wsdlPort"
val httpProtocol = http
.baseURL(baseUri)
.disableWarmUp
/**
CSV File record vectors
*/
object FeederUtils {
val socEntries = csv(“entries.csv”).records
val activeCompanies = csv(“companies.csv”).records
var companiesIterator = 0;
}
object Actions {
/**
For each company, calls notifyCompanyEntries
*/
def notifyAllCompanies() {
var i = 0;
for(i ← 0 to FeederUtils.companiesIterator - 1) {
var currentCompany = FeederUtils.activeCompanies(FeederUtils.companiesIterator)
class MyClass extends Simulation {
val machine = “machineName”
val baseUri = “http://” + machine + “/baseUri”;
val uri = “/wsdlPort”
val httpProtocol = http
.baseURL(baseUri)
.disableWarmUp
/**
CSV File record vectors
*/
object FeederUtils {
val socEntries = csv(“entries.csv”).records
val activeCompanies = csv(“companies.csv”).records
}
object Actions {
/**
For each company, calls notifyCompanyEntries
*/
val notifyAllCompanies =
for (activeCompany ← FeederUtils.activeCompanies)
yield Actions.notifyCompanyEntries(activeCompany(“activeCompanyName”)).pause(2000)
/**
Notifies all entries for a company (reads entries vector)
*/
def notifyCompanyEntries(companyName: String) = {
foreach(FeederUtils.socEntries, “record”) {
exec(flattenMapIntoAttributes("${record}"))
.exec({ session => session.set(“codeSociete”, companyName) })
.exec(http(“Notify ${codeEntree}”)
.post(uri)
.body(StringBody(""“content”""))
.header(“Content-Type”, “text/xml;charset=UTF-8”)
.header(“SOAPAction”, “DCInterfaceRecherchePrix_ws_v1_rechercherPrix_Binder_rechercherPrix”)
.basicAuth(“Administrator”, “manage”))
}
}
}
/**
Scenario : one user first…
*/
val scn = scenario(“Soc test”).exec(Actions.notifyAllCompanies)
Thanks for helping, script is not still working but you gave me some clues.
I have a stack overflow error because loop doesn’t break, I don’t know why. I’m working on it.
I don’t understand return type inference : adding “=” lets compiler infer return type, it seems kind of magic because I’m never using ChainBuilder ! So at execution time, what object is returned and how exec uses it ?
Anyway, one again thanks for helping. I really appreciate. I thought it will be easier to understand scala basics and to use it with gatling.