Hi - I am attempting to use a jdbcFeeder to seed data for my simulation. I have this
….exec(jdbcFeeder(…, “select co1, col2, col3 from table”))
…
.exec(http(“request_1”)
.post(…)
.param(“user”, “${col1}”)
…
however, I am not able to get the value of col1 or any of the other selected columns.
Am I doing something wrong? How can I get the value of the selected columns?
I am still digesting scala, so I apologize in advance if this is obvious.
Thanks
Hi,
Like any other feeder, you need to use the feed(…) DSL construct to get values from your feeder into the session (which makes them available through the Gatling EL).
Replace exec(jdbcFeeder(…)) by feed(JdbcFeeder(…)) and it should work.
The Feeders documentation should help mastering Feeders
Cheers,
Pierre
Sorry Pierre - I had a typo in my original post. I am already sending it through a .feed().
It is still not working.
So this is what I intended to post
…
.exec(feed(jdbcFeeder(…, “select co1, col2, col3 from table”)))
…
.exec(http(“request_1”)
.post(…)
.param(“user”, “${col1}”)
…
The problem is slightly different, but the conclusion is the same : using feed(…) is enough, you don’t need to put it inside an exec.
Drop the exec surrounding the feed(…) and it should work.
hmmm, ok here is what i have…
val dataFeed = jdbcFeeder(…, “select col1, col2, col3 from table”)
val scn = scenario(“Scenario Name”)
.feed(dataFeed)
.repeat(loop) {
group(“Login”) {
exec(login_chain)
}
.pause(1)
.group(“Home”) {
exec(home_chain)
}
.pause(2)
.group(“Logout”) {
exec(logout_chain)
}
} //end repeat
Using “${col1}” or any of the other columns is not being evaluated within the groups. At minimum, I tried this…
val scn = scenario(“Scenario Name”)
.repeat(loop) {
exec(session => {
println("${col1}")
session
})
The println() just prints ${col1}, not the value of the column.
Can you see anything wrong. Still not working for me. I am on oracle database.
Of course
val scn = scenario(“Scenario Name”)
.feed(dataFeed) << data feeder is here as well…
.repeat(loop) {
exec(session => {
println("${col1}")
session
})
It’s perfectly normal that println() prints “${col1}” and not the value in session : EL is not specific to Gatling and is resolved only in specific places, and println() isn’t one of those.
If you wan to see what is in your session, you cant either
-
print the whole session ( ex : (session => { println(session);session }) )
-
get a specific attribute and print it (ex : (session => { println(session.getAttribute(“col1”); session }) )
As an example, this works perfectly fine for me : I’m getting only the columns I want in session and they’re perfectly accessible through either EL or Session function :
val scn = scenario(“Scenario name”)
.feed(jdbcFeeder(“jdbc:postgresql:gatling-db”,“gatling”,“gatling”,“SELECT firstname,lastname FROM Person LIMIT 20”))
.exec(http("${firstname}").get(“http://google.com”).check(status.is(301)))
.exec((s:Session) => {println(s.getAttribute(“firstname”));s})
My bad : I meant that the EL is specific to Gatling
Thanks Pierre. Finally it works!
Dumping the session helped. I should have thought of that
It happens the values were stored in the session in uppercase, and I was trying to retrieve them in lower case. That is why it appeared it wasn’t working.
Thanks.
Also, just related but might as well tag on to this, whenever I attempt to use the logger instead of println, i don’t see the results get printed. I modified logback.xml to log the packages under which my simulations live, but still no luck.
Does anything need to be done specially to get that to work?
eg.
val logger = org.slf4j.LoggerFactory.getLogger(“myDebugLogger”)
in logback.xml
with my simulations under samples package.
I think the problem resides in the same of your logger.
Basically, when you create a new logger, you use the class name as the logger name (to get the nice package-specific logger configuration)
Replace “myDebugLogger” by MySimulation.getClass (if your simulation class is MySimulation) and it will work (you should of course use the corresponding logging methods, eg : logger.debug(…) )
You can also make use of a grizzled-slf4j, a library we’re using to simplify logger setup and usage in Scala, if you like.
To do so :
-
add a new import : import grizzled.slf4j.Logging
-
Modify your class declaration so that it should look like this : class MySimulation extends Simulation with Logging
-
Logger is automatically setup (eg : you don’t need the val logger = … line) and you can directly call debug(…) instead of logger.debug(…)
Cheers,
Pierre
Ok. I’ll try that. Thanks!
grizzled-slf4j works like a charm. Thank you