Need help with Gatling JDBC feeder

I need to read few parameters from DB and what I did was similar to what is done in ‘Initialising parameters with jdbc feeder’ thread.

E.g : Create a simulation

import io.gatling.core.Predef._
import io.gatling.http.Predef._
import io.gatling.jdbc.Predef._
import scala.concurrent.duration._
import Headers._
import OracleDataFeeder._

class BasicSimulation extends Simulation {

val urlHost = System.getProperty(“URL_HOST”)
val nbUsers:Int = java.lang.Integer.getInteger(“users”, 1)
val myRamp:Long = java.lang.Long.getLong(“ramp”, 0L)

val httpProtocol = http
.baseURL(urlHost)
.acceptHeader("/")
.acceptEncodingHeader(“gzip,deflate,sdch”)
.acceptLanguageHeader(“en-US,en;q=0.8”)
.connection(“keep-alive”)
.userAgentHeader(“Mozilla/5.0 (Windows NT 6.1; WOW64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/33.0.1750.146 Safari/537.36”)

val scn = scenario(“JDBC feeder sample”)
.feed(jdbcFileFeeder)
.exec(http(“Authentication”)
.post("""/authenticator""")
.headers(headers_1)
.header(“userName”, “${userName}”)
.header(“password”,"${userPassword}")
.header(“Origin”, “urlHost”)
.check(jsonPath("$.token").saveAs(“tokenId”))
.check(status.is(200)))

setUp(scn.inject(rampUsers(nbUsers) over (myRamp seconds)).protocols(httpProtocol))

}

Then create a separate class for OracleDataFeeder

`

object OracleDataFeeder {

Class.forName(“oracle.jdbc.driver.OracleDriver”)
val dbStatement = System.getProperty(“dbStatement”, “####################”)
val jdbcFileFeeder = jdbcFeeder(“jdbc:oracle:thin:@host_name:1521:service_name”, “######”, “########”, dbStatement)
}

`

I’m using [Gatling Plugin for Gradle](http://Gatling Plugin for Gradle) and when I run the simulation, I get following error.

`

:compileGatlingJava UP-TO-DATE
:compileGatlingScala UP-TO-DATE
:processGatlingResources
:gatlingClasses
:gatlingRun
Exception in thread “main” java.lang.ExceptionInInitializerError
at numbering.CheckExternalServicesStatusSimulation.(CheckExternalServicesStatusSimulation.scala:16)
at sun.reflect.NativeConstructorAccessorImpl.newInstance0(Native Method)
at sun.reflect.NativeConstructorAccessorImpl.newInstance(NativeConstructorAccessorImpl.java:62)
at sun.reflect.DelegatingConstructorAccessorImpl.newInstance(DelegatingConstructorAccessorImpl.java:45)
at java.lang.reflect.Constructor.newInstance(Constructor.java:422)
at java.lang.Class.newInstance(Class.java:442)
at io.gatling.app.Gatling$.io$gatling$app$Gatling$$$anonfun$1(Gatling.scala:41)
at io.gatling.app.Gatling$lambda$1.apply(Gatling.scala:41)
at io.gatling.app.Gatling$lambda$1.apply(Gatling.scala:41)
at io.gatling.app.Gatling.run(Gatling.scala:92)
at io.gatling.app.Gatling.runIfNecessary(Gatling.scala:75)
at io.gatling.app.Gatling.start(Gatling.scala:65)
at io.gatling.app.Gatling$.start(Gatling.scala:57)
at io.gatling.app.Gatling$.fromArgs(Gatling.scala:49)
at io.gatling.app.Gatling$.main(Gatling.scala:43)
at io.gatling.app.Gatling.main(Gatling.scala)
Caused by: java.lang.ClassNotFoundException: oracle.jdbc.driver.OracleDriver
at java.net.URLClassLoader.findClass(URLClassLoader.java:381)
at java.lang.ClassLoader.loadClass(ClassLoader.java:424)
at sun.misc.Launcher$AppClassLoader.loadClass(Launcher.java:331)
at java.lang.ClassLoader.loadClass(ClassLoader.java:357)
at java.lang.Class.forName0(Native Method)
at java.lang.Class.forName(Class.java:264)
at numbering.OracleDataFeeder$.(OracleDataFeeder.scala:13)
at numbering.OracleDataFeeder$.(OracleDataFeeder.scala)
… 16 more
:gatlingRun FAILED

`

I tried

  • Adding ojdbc6.jar to build path

  • Adding the driver to build.gradle

  • `

    dependencies {

    testCompile files(‘lib/ojdbc6.jar’)
    }

    `

  • Putting it in my local Maven repository and referring to it using its coordinates

`

buildscript {
    repositories {
        mavenCentral()
        mavenLocal()
    }
    dependencies {
        classpath 'com.oracle:ojdbc6:11.2.0.4'
        // Instead of
        // files ('lib/ojdbc6.jar')
    }
}

`

But nothing helped.

looking at this - http://gatling.io/docs/current/session/feeder/
it says, “Only JDBC4 drivers are supported, so that they automatically registers to the DriverManager.”

what i did was i modified this https://www.tutorialspoint.com/jdbc/jdbc-sample-code.htm to return an array of map of strings and use it as a feeder.

i hope this helps.