Gatling - Cara Kirim Panyuwunan Kirim ing StringBody () Kanthi Data Acak

Ing tutorial Gatling iki, kita nuduhake carane ora ngirim panjaluk kiriman sing ngemot data acak ing StringBody().

Ing skenario uji coba kinerja sing paling akeh, sampeyan pengin ngacak data sing dikirim minangka panjaluk kirim kanggo simulasi macem-macem sesi. Kanggo iki, kita bisa nggunakake feeder sing maca data saka file CSV utawa teks biasa.

Yen durung nyetel Gatling ing mesin, sampeyan bisa maca kiriman sing nerangake carane nyiyapake Gatling minangka proyek Maven.


Scala Random String Generator

Kaping pisanan, kita butuh cara kanggo ngasilake string acak ing Scala:

object randomStringGenerator { def randomString(length: Int) = scala.util.Random.alphanumeric.filter(_.isLetter).take(length).mkString
}

Panyuwunan XML minangka Post Post

Ing conto iki, kita ngirim panjaluk kirim XML. Iki ngemot parameter log_session_id sing kudu beda ing saben panjaluk:


val req = ' ' + ' ' +
'3 ' +
'MY_APP ' +
'0000000000 ' +
'b02edd23,ClientIP=10.211.55.3 ' +
'ACTIVATION ' + ''

Kita kudu duwe cara ngirim panjaluk XML ing ndhuwur minangka kiriman ing StringBody() ing Gatling, nanging ing saben panjaluk, log_session_id regane kudu senar acak.



Kanggo iki, kita kudu nggunakake feeder.

Feeder ing StringBody ()

var randomSession = Iterator.continually(Map('randsession' -> ( req.replace('0000000000', randomStringGenerator.randomString(10))))) val scn = scenario('Activate')
.feed(randomSession)
.exec(http('activate request')
.post('/login/activate')
.body(StringBody('''${randsession}'''))

Skrip lengkap kanggo ngirim panjaluk kiriman acak ing StringBody() ing Gatling:

import io.gatling.core.Predef._ import io.gatling.http.Predef._ import io.gatling.http.config.HttpProtocolBuilder.toHttpProtocol import io.gatling.http.request.builder.HttpRequestBuilder.toActionBuilder class Activate extends Simulation { object randomStringGenerator {
def randomString(length: Int) = scala.util.Random.alphanumeric.filter(_.isLetter).take(length).mkString } val req = ' ' +
' ' +
'3 ' +
'MY_APP ' +
'0000000000 ' +
'b02edd23,ClientIP=10.211.55.3 ' +
'ACTIVATION ' +
'' var randomSession = Iterator.continually(Map('randsession' -> ( req.replace('0000000000', randomStringGenerator.randomString(10))))) val httpConf = http
.baseURL('http://localhost:5000')
.acceptHeader('text/html,application/xhtml+xml,application/xml;q=0.9,*/*;q=0.8')
.userAgentHeader('Mozilla/4.0(compatible;IE;GACv10. 0. 0. 1)') val scn = scenario('Activate')
.feed(randomSession)
.exec(http('activate request')
.post('/login/activate')
.body(StringBody('''${randsession}'''))
.check(status.is(200)))
.pause(5) setUp(
scn.inject(atOnceUsers(5)) ).protocols(httpConf) }