Isakhelo soVavanyo lweNtsebenzo kunye neGatling neMaven

Yeyiphi indlela ebalaseleyo yokuququzelela kunye nokwakha iprojekthi yeGatling yovavanyo lwentsebenzo?

Xa kuyilwa isakhelo, kuya kufuneka sicinge malunga nokugcinwa kunye nokwandiswa, yiyo loo nto indlela esizicwangcisa ngayo izinto zibaluleke kakhulu.

Kule tutorial, siya kubonisa indlela yokwenza isakhelo sokuvavanya ukusebenza ukususela ekuqaleni usebenzisa iGatling kunye ne-maven.




Isikhokelo sovavanyo lweMat

Izinto ezifuneka kuqala:

Kule khokelo kuya kufuneka ufake oku kulandelayo:


  • IJava 1.8
  • Maven 3.5
  • I-IntelliJ ene-Scala Plugin efakiweyo

Kuqala, senza iprojekthi esisiseko ngokuqhuba i-maven Gatling archetype:

mvn archetype:generate -DarchetypeGroupId=io.gatling.highcharts -DarchetypeArtifactId=gatling-highcharts-maven-archetype

Xa usenza lo myalelo ungasentla, uya kuqala ukukhuphela ukuxhomekeka.

Xa ukhuthazwa, bonelela ngamaxabiso 'eqelaId', 'artifactId', kunye 'nohlobo'.

Ukuseta kwam kujongeka njengoku kulandelayo:


Xa uvula iprojekthi, uya kuqaphela ukuba kukho ezinye iifayile kunye neefolda ezingagqibekanga.

Ngaphantsi kwezixhobo, sinazo


imizimba le phakheji ibambe isicelo sokulayisha umthwalo. Umzekelo, unokufumana izicelo zetemplate zezicelo ezahlukeneyo.

idatha le phakheji ibambe idatha oyifunayo ukondla kwiimvavanyo zakho, ezinje ngee-CSV.

Ukongeza kwezi folda zimbini zingasentla, kukho iGatling.conf, logback.xml kunye nerekhoda.conf iifayile. Asizukuxoxa ngale nto kwesi sifundo.

I-Gatling maven archetype ikwadala izinto ezintathu ezisisiseko zeScala, kodwa asizukuzisebenzisa, ke qhubeka ucime izinto.


Ukongeza, siza kudala iiphakheji ezine, qwalasela , izicelo , iimeko , kunye ukulinganisa :

Qwalasela iPhakheji

Kwiphakheji yokumisela, yenza into yeScala ebizwa ngokuba yiConfig. Oku kuyakubamba uqwalaselo olwahlukeneyo lweprojekthi yethu njengee-URLs zesicelo, abasebenzisi abangagqibekanga, njl.

package io.devqa.config object Config {
val app_url = 'http://example-app.com'
val users = Integer.getInteger('users', 10).toInt
val rampUp = Integer.getInteger('rampup', 1).toInt
val throughput = Integer.getInteger('throughput', 100).toInt }

Izicelo zephakheji

Iphakheji yezicelo inezicelo ezahlukeneyo zokusebenza. Umzekelo, sinokuba nesicelo esifumana ithokheni yokugunyazisa. Esinye isicelo sinokusebenzisa ithokheni kwisicelo sangaphambili ukwenza umsebenzisi njalo njalo.


Ezi zizicelo ezizodwa nezizimeleyo ezithunyelwe kwiindawo ezahlukeneyo zokuphela.

GetTokenRequest

package io.devqa.requests import io.gatling.core.Predef._ import io.gatling.http.Predef._ import io.devqa.config.Config.app_url object GetTokenRequest {
val get_token = http('RequestName').get(app_url + '/token')
.check(status is 200)
.check(jsonPath('$..token').saveAs('token')) }

YenzaUserRequest

package io.devqa.requests import io.devqa.config.Config.app_url import io.gatling.core.Predef._ import io.gatling.http.Predef._ object CreateUserRequest {
val sentHeaders = Map('Authorization' -> 'bearer ${token}')
val create_user = exec(http('Create User Request')
.post(app_url + '/users')
.headers(sentHeaders)
.formParam('name', 'John')
.formParam('password', 'John5P4ss')
.check(status is 201)
.check(regex('Created').exists)) }

Iphakheji yemeko

Iphakheji yemeko ibambe imeko zeshishini. Umzekelo, ukudala umsebenzisi, kufuneka kuqala sifumane ithokheni ye-auth emva koko sithumele ithokheni njengesihloko kunye neefomathi zokwenza umsebenzisi. i.e. sisebenzisa impendulo yesicelo sokuqala ukondla isicelo sesibini. Oku 'kudityaniswa kwezicelo' kuqhelekile kuvavanyo lwe-API.

YakhaUserScenario

package io.devqa.scenarios import io.devqa.requests.{CreateUserRequest, GetTokenRequest} import io.gatling.core.Predef.scenario object CreateUserScenario {
val createUserScenario = scenario('Create User Scenario')
.exec(GetTokenRequest.get_token)
.exec(CreateUserRequest.create_user) }

Iphakheji yokulinganisa

Okokugqibela, sineeSimulations kwiphakheji yokulinganisa. Unokucinga ngokulinganisa njengeeprofayili ezahlukeneyo zomthwalo. Umzekelo, sinokuba nokulinganisa umthwalo oqhelekileyo okanye ukulinganisa kwespike.

Ukulinganisa kufuneka kube ziiklasi zeScala kwaye kufuneka bandise udidi lokulinganisa.

package io.devqa.simulations import io.devqa.scenarios.CreateUserScenario import io.gatling.core.Predef.Simulation import io.gatling.core.Predef._ import io.devqa.config.Config._ class CreateUserSimulation extends Simulation {
private val createUserExec = CreateUserScenario.createUserScenario
.inject(atOnceUsers(users))
setUp(createUserExec) }

Iprojekthi yakho kufuneka ijongeke ngolu hlobo lulandelayo:

Sifuna ukuguqula ifayile yethu ye-pom.xml ukuze sikwazi ukudlulisa iiparameter, ezinje ngabasebenzisi kunye nokufikelela kwiimvavanyo zethu zokusebenza ngexesha lokusebenza.

pom.xml ifayile

Ifayile ye-pom.xml kufuneka ijongeke:


4.0.0
testing-excellence
gatling-framework
1.0-SNAPSHOT

1.8
1.8
UTF-8
2.3.0
2.2.4
1.3.2
CreateUserSimulation



io.gatling.highcharts
gatling-charts-highcharts
${gatling.version}
test


com.typesafe
config
${typesafe-config.version}






io.gatling
gatling-maven-plugin
${gatling-plugin.version}



io.devqa.simulations.${simulation}




-Denv=${env}

-Dusers=${users}

-Drampup=${rampup}

-Dduration=${duration}

-Dthroughput=${throughput}




true





Okokugqibela, ukwenza iklasi yokulinganisa, siqhuba lo myalelo ulandelayo

mvn clean gatling:execute -Dusers=1

Lo myalelo ungasentla uza kuqhuba i-CreateUserSimulation ngomsebenzisi omnye.