I am very new to Gatling and Scala.
I need to use Gatling jdbc feeder and pull the test data from a table and store them on a session or any variable so that I can use them to populate multiple template file. Also how can I loop through this process to do the same steps for all the rows I get from the database?
`
import io.gatling.core.Predef._
import io.gatling.core.feeder.RecordSeqFeederBuilder
import io.gatling.core.structure.ScenarioBuilder
import io.gatling.http.Predef._
import io.gatling.http.protocol.HttpProtocolBuilder
import io.gatling.jdbc.Predef._
class GatlingTest extends Simulation {
private val dbConnectionString = “jdbc:mariadb://localhost:3306/BlazeDemo”
private val sqlQuery = “SELECT data FROM TestTable”
private val sqlUserName = “username”
private val sqlPassword = “password”
private val baseUrl = “http://baseurl.com”
private val contentType = “application/json”
val sqlQueryFeeder: RecordSeqFeederBuilder[Any] = jdbcFeeder(dbConnectionString,
sqlUserName,
sqlPassword,
sqlQuery
)
val httpProtocol: HttpProtocolBuilder = http
.baseURL(baseUrl)
.acceptHeader("/")
.contentTypeHeader(contentType)
val scn: ScenarioBuilder = scenario(“Test Scenario”)
.feed(sqlQueryFeeder)
.exec(http(“first post call”)
.post(endpoint1)
.body(ELFileBody(“Template1.txt”))
.check(status.is(200)))
.exec(http(“second post call”)
.post(endpoint2)
.body(ELFileBody(“Template2.txt”))
.check(status.is(200)))
// and so on and repeat the same process for all the rows return
setUp(scn.inject(atOnceUsers(1))).protocols(httpProtocol)
}
`