Mahinga Whakamatau Whakamatau me te Gatling me te Maven

He aha te huarahi pai ki te whakarite me te hanga i tetahi kaupapa Gatling mo te whakamatautau mahi?

A, no te hoahoa i tetahi anga, me whakaaro maatau mo te noho mau me te roa, na reira me pehea te whakarite i nga waahanga he mea nui.

I roto i tenei akoranga, ka whakaatuhia me pehea te hanga i tetahi anga whakamatautau hei whakamahi i te Gatling me te maven

Te Anga Whakamatautau Gatling Maven

Tuhinga o mua:

Mo tenei akoranga me whakauru e koe enei e whai ake nei:

  • Java 1.8
  • Maven 3.5
  • Kua whakauruhia a IntelliJ me Scala Plugin

Tuatahi, ka hangahia e maatau he kaupapa ma te whakahaere i te tauira o te miihini Gatling:



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

Ka mahia ana e koe te whakahau i runga ake nei, ka tiimata te tango i nga whakawhirinaki.

Ka akiaki ana, tohaina nga uara mo te 'groupId', 'artifactId', me te 'putanga'.

Ko taku tautuhi he penei:

Ka whakatuwherahia e koe te kaupapa, ka kite koe kei kona etahi konae taunoa me nga kopaki.

I raro i nga rauemi, kei a maatau

tinana kei roto i tenei kohinga nga nama tono. Hei tauira, ka taea e koe he tono tauira mo nga momo tono.

raraunga kei roto i tenei kohinga nga raraunga e hiahia ana koe ki te whangai i o whakamatautau, penei i nga CSV.

Hei taapiri ki nga waahanga e rua i runga ake nei, kei kona ano nga konae Gatling.conf, logback.xml me recorder.conf. Kaore maatau e matapakihia i roto i tenei akoranga.

Ko te Gatling maven archetype e hangaia ana hoki e toru nga taonga Scala turanga, engari kaore e whakamahia e matou, na kia kaha ki te whakakore i nga taonga.

Hei taapiri, ka hanga e wha nga kohinga, config , tono , tauariari , me whaihanga :

Mōkihi Whirihora

I roto i te kohinga config, hangaia he ahanoa Scala ko Config te ingoa. Ma tenei e mau ana nga whirihoranga maha mo ta maatau kaupapa penei i nga URL tono, nga kaiwhakamahi taunoa, me era atu…

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 }

Tono Mōkī

Kei nga kohinga tono nga tono whakahaere rereke. Hei tauira, ka taea pea e taatau te tono kia whiwhi tohu whakamana. Ka taea e tetahi atu tono te whakamahi i te tohu mai i te tono o mua ki te hanga kaiwhakamahi me era atu.

He tono takitahi me te wehe enei ki nga waahi mutunga.

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')) }

Waihangahia te Kaiwhakamahi

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)) }

Kohinga Tauari

Ko te kohinga tauari e pupuri ana i nga ahuatanga pakihi. Hei tauira, ki te hanga i tetahi kaiwhakamahi, tuatahi me tiki he tohu auth ka tuku ai i te tohu hei pane me nga tohu hanga ki te hanga kaiwhakamahi. arā, ka whakamahia e maatau te urupare o te tono tuatahi ki te whangai i te tono tuarua. Ko tenei 'mekameka tono' he mea noa ki te whakamatautau API.

Waihangahia te Kaiwhakamahi

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) }

Mōkihi Whakatika

Hei whakamutunga, kei a maatau nga Whakaaturanga i te kohinga whaihanga. Ka taea e koe te whakaaro i nga whaihanga hei tohu kawenga rereke. Hei tauira, ka taea e taatau he taatai ​​kawenga taatau he taatai ​​taatai ​​ranei.

Ko nga whaihanga he akomanga Scala ana, me whakawhanui ake te akomanga Tauira Gatling.

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) }

Me penei te ahua o to kaupapa:

Me whakarereke hoki i ta maatau konae pom.xml kia taea ai te paahi i nga taapiri, penei i nga kaiwhakamahi me te whakaputa i a maatau whakamatautau mahi i te wa weto.

kōnae pom.xml

Kia penei te ahua o te konae pom.xml:


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





Hei whakamutunga, ki te whakahaere i te karaehe whaihanga, ka whakahaerehia e maatau nga whakahau e whai ake nei

mvn clean gatling:execute -Dusers=1

Ko te whakahau i runga ake nei ka whakahaere i te WaahangaHaiWhakaahua me te 1 kaiwhakamahi.