Skip to content

Instantly share code, notes, and snippets.

@infomaven
Last active February 14, 2020 17:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save infomaven/8de56a25d6cc164b06df to your computer and use it in GitHub Desktop.
Save infomaven/8de56a25d6cc164b06df to your computer and use it in GitHub Desktop.
Gatling payload generation using multiple rows from a Feeder file
package performance.simulations.scenarios
import io.gatling.core.Predef._
import io.gatling.http.Predef._
import performance.simulations.lib.JenkinsParam._
import performance.simulations.lib.RandomFeeder._
import performance.simulations.lib.SharedHeaders._
/**
* Created by nwhit8 on 9/21/15.
*/
class CommandService extends Simulation {
// feeder file with ReceiverId column
val receiverFeeder = csv("temp_pal_receivers.csv").random
// list builder
def buildListFromSession( session: Session ) : String= {
// get all keys that match the pattern for this variable
val kitchenSink = session.attributes.toMap
val filtered = kitchenSink.filter(( x) => x._1 startsWith("ReceiverId"))
// prefix=" delimiter="," suffix="
val myUsers = filtered.values.mkString("\"", "\",\"", "\"")
myUsers
}
// generates JSON payload
def genGargantuanPayload(payloadType: String, recipientApp: String, userIds: String ): String = {
val gargantuan = """
{
"payload_type": "category:${Type3}",
"locale_language": "en",
"locale_country": "US",
"recipients": [
${MyList}
] ,
"content": {
"template": "design8"
}
}
"""
gargantuan
}
// request that uses the payload and userId list
val scnPostHugePayloads = scenario("POST-HUGE-PAYLOADS")
/// grab 1000 rows from feeder file
.feed( receiverFeeder,1000 )
.feed( timestampXB3Feeder )
// set up session attributes that will be used to build the payload
.exec( session => {
session.set("LaunchType", "foo:promo:Holiday")
.set("RecipientApp", "com.foursquare")
.set( "MyList", buildListFromSession( session))
})
// adjust baseURL and resource path to match application being tested
.exec({
val resource = baseURL + "/resource/path/requests"
http("POST-HUGE-PAYLOADS")
.post(resource)
.body( StringBody(
genCampaignPayload( "${LaunchType}", "${RecipientApp}", "${MyList}"))).asJSON
.check( status.is(202))
})
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment