Either write a feeder that generates random data: https://github.com/excilys/gatling/wiki/Inject-User-Specific-Data
or instead of passing a String, pass a function: https://github.com/excilys/gatling/wiki/Session#functions
Either write a feeder that generates random data: https://github.com/excilys/gatling/wiki/Inject-User-Specific-Data
or instead of passing a String, pass a function: https://github.com/excilys/gatling/wiki/Session#functions
Thanks, Will this work with gatling 1 also?
Absolutely.
Hi All,
I am calling a java api to get the post pody in my scenario exec method. But when I run it it just picks the value of the body only once. But I would like it to call the exec everytime so that it fetches me a new body.
Code below.
package custom.protocol.test
import com.excilys.ebi.gatling.core.scenario.configuration.Simulation
import com.excilys.ebi.gatling.core.Predef._
import com.excilys.ebi.gatling.http.Predef._
import bootstrap._
import assertions._
import scala.concurrent.duration._
import com.inmobi.crypto.getMessageBody
import com.inmobi.crypto.CarbEncodingWrapper
class GetPromotedAppsSimulation_lh1_postencryption_new extends Simulation {
val httpConf = httpConfig
.baseURL(“http://usignal01.app.vip.lhr1.inmobi.com/carb/v1/app_relevance_get”)
.acceptHeader(“text/javascript, text/html, application/xml, text/xml, /”)
.acceptEncodingHeader(“gzip,deflate,sdch”)
b = new CarbEncodingWrapper
val headers_1 = Map(“Keep-Alive” → “200000”)
val scn = scenario(“Gatling GetPromotedApps”)
.during(43200) {
exec(http(“request_1”)
.post("") .body(b.getEncodedbody(getMessageBody.getRandomBody()))
.check(status.is(200)))
.pause(0)
}
setUp(scn.users(10).ramp(5).protocolConfig(httpConf))
;assertThat(global.responseTime.max.lessThan(100))
}
You hâve
You have to pass a session function or your method will be called only once on start up
I am facing issues in running my simulation where I just want to pass body for a post request to an URL. Please help me resolving this.
My simulation:
package custom.protocol.test
//import com.excilys.ebi.gatling.core.scenario.configuration.Simulation
//import com.excilys.ebi.gatling.core.Predef._
//import com.excilys.ebi.gatling.http.Predef._
//import bootstrap._
//import assertions._
//import scala.concurrent.duration._
import akka.actor.{ ActorRef, Props }
import io.gatling.core.Predef._
import io.gatling.core.action.Chainable
import io.gatling.core.action.builder.ActionBuilder
import io.gatling.core.config.Protocols
import io.gatling.core.result.message.{ KO, OK }
import io.gatling.core.result.writer.{ DataWriter, RequestMessage }
import io.gatling.http.Predef._
import io.gatling.http.request.Body
class PerfCustomProtocolSimulation extends Simulation {
val httpConf = http
.baseURL(“http://config-svc-1002.app.uh1.inmobi.com:8080/config-server/v1/config/secure.cfg”)
.acceptHeader(“application/x-www-form-urlencoded”)
.acceptEncodingHeader(“gzip,deflate,sdch”)
val headers_1 = Map(
“Keep-Alive” → “200000”)
val headers_10 = Map(“Content-Type” → “”“application/x-www-form-urlencoded”"")
val scn = scenario(“Gatling GetConfig”)
.exec(http(“request_1”)
.post("")
.headers(headers_10)
.body(“sm=QAAAAAAAAABWiH61n2_zbRRChYLHhKLSdDjoIegGNuP8VdQo-Xp-KJfBPeaYMefz7IikVkKc-Ls8%0Aj448dImG7axFov1trLcAUAAAAAAAAACwWzbUw7Ws7s0AM-CTI2O4yzOlCg36tG8WqCB8_S_YIxhh%0Azc83oikwpM-7NQCuXUYZFeTTp9vnZyJSVGllmgiYB4Ts3YIfdQilIERAQB0LORQAAAAAAAAAc5Cn%0Ac6quLeHrpaQGwyoM0R_5g5A%3D%0A&sn=1”)
.check(status.is(200)))
.pause(0)
// setUp(scn.users(10).protocolConfig(httpConf))
//;assertThat(global.responseTime.max.lessThan(100))
setUp(
scn.inject(
nothingFor(0 seconds), // 1
atOnceUsers(1000), // 2
rampUsers(300) over (2 seconds), // 3
constantUsersPerSec(1000) during (100 seconds) // 4
)).assertions(global.responseTime.max.lessThan(50), global.successfulRequests.percent.greaterThan(95))
}
I get an error:
17:28:49.773 [ERROR] i.g.a.ZincCompiler$ - /home/shishirchandra/workspace/config-pert-tuning-gatling/gatling-custom-protocol-demo/src/test/scala/custom/protocol/test/PerfCustomProtocolSimulation.scala:41: type mismatch;
found : String(“sm=QAAAAAAAAABWiH61n2_zbRRChYLHhKLSdDjoIegGNuP8VdQo-Xp-KJfBPeaYMefz7IikVkKc-Ls8%0Aj448dImG7axFov1trLcAUAAAAAAAAACwWzbUw7Ws7s0AM-CTI2O4yzOlCg36tG8WqCB8_S_YIxhh%0Azc83oikwpM-7NQCuXUYZFeTTp9vnZyJSVGllmgiYB4Ts3YIfdQilIERAQB0LORQAAAAAAAAAc5Cn%0Ac6quLeHrpaQGwyoM0R_5g5A%3D%0A&sn=1”)
required: io.gatling.http.request.Body
17:28:49.776 [ERROR] i.g.a.ZincCompiler$ - .body(“sm=QAAAAAAAAABWiH61n2_zbRRChYLHhKLSdDjoIegGNuP8VdQo-Xp-KJfBPeaYMefz7IikVkKc-Ls8%0Aj448dImG7axFov1trLcAUAAAAAAAAACwWzbUw7Ws7s0AM-CTI2O4yzOlCg36tG8WqCB8_S_YIxhh%0Azc83oikwpM-7NQCuXUYZFeTTp9vnZyJSVGllmgiYB4Ts3YIfdQilIERAQB0LORQAAAAAAAAAc5Cn%0Ac6quLeHrpaQGwyoM0R_5g5A%3D%0A&sn=1”)
17:28:49.777 [ERROR] i.g.a.ZincCompiler$ - ^
17:28:49.870 [ERROR] i.g.a.ZincCompiler$ - one error found
Gatling 1 is no longer supported. Please upgrade.
I am using gatling 2, But I am not sure how to fix the error in the above sent snippet.
I want to pass the string as a body in a http post call and I am using the below scn: Using gatling 2
val scn = scenario(“Gatling GetConfig”)
.exec(http(“request_1”)
.post("")
.headers(headers_10)
.body(StringBody("""{ “myContent”: “sm=QAAAAAAAAABWiH61n2_zbRRChYLHhKLSdDjoIegGNuP8VdQo-Xp- KJfBPeaYMefz7IikVkKc-Ls8%0Aj448dImG7axFov1trLcAUAAAAAAAAACwWzbUw7Ws7s0AM-CTI2O4yzOlCg36tG8WqCB8_S_YIxhh%0Azc83oikwpM-7NQCuXUYZFeTTp9vnZyJSVGllmgiYB4Ts3YIfdQilIERAQB0LORQAAAAAAAAAc5Cn%0Ac6quLeHrpaQGwyoM0R_5g5A%3D%0A&sn=1” }"""))
.check(status.is(200)))
.pause(0)
But I am not able to produce the correct body, I want the following string in the body:
sm=QAAAAAAAAABWiH61n2_zbRRChYLHhKLSdDjoIegGNuP8VdQo-Xp- KJfBPeaYMefz7IikVkKc-Ls8%0Aj448dImG7axFov1trLcAUAAAAAAAAACwWzbUw7Ws7s0AM-CTI2O4yzOlCg36tG8WqCB8_S_YIxhh%0Azc83oikwpM-7NQCuXUYZFeTTp9vnZyJSVGllmgiYB4Ts3YIfdQilIERAQB0LORQAAAAAAAAAc5Cn%0Ac6quLeHrpaQGwyoM0R_5g5A%3D%0A&sn=1
Thanks,
Shishir