2015-08-27 12 views
5

Vorrei ottenere un URL a caso su richiesta HTTP per GatlingCome posso ottenere un URL casuale sulla richiesta http per Gatling?

mio scenario è definito in questo modo:

import io.gatling.core.Predef._ 
import io.gatling.http.Predef._ 
import scala.concurrent.duration._ 
import scala.util.Random 

class testSimulation extends Simulation { 

    val httpConf = http.baseURL("OURURL") 


    val scn = scenario("View HomePages") 
       .exec(
         http("Home page") 
           .get("/" + new Random().nextInt()) 
           .resources(
             http("genericons.css").get("/wp-content/themes/twentyfifteen/genericons/generi$ 
             http("style.css").get("/wp-content/themes/twentyfifteen/style.css?ver=4.2.3"), 
             http("jquery.js").get("/wp-includes/js/jquery/jquery.js?ver=1.11.2"), 
             http("jquery-migrate.min.js").get("/wp-includes/js/jquery/jquery-migrate.min.j$ 
             http("skip-link-focus-fix.js").get("/wp-content/themes/twentyfifteen/js/skip-l$ 
             http("functions.js").get("/wp-content/themes/twentyfifteen/js/functions.js?ver$ 
             http("wp-emoji-release.min.js").get("/wp-includes/js/wp-emoji-release.min.js?v$ 
             http("wp-emoji-release.min.js").get("/wp-includes/js/wp-emoji-release.min.js?v$ 
             http("skip-link-focus-fix.js").get("/wp-content/themes/twentyfifteen/js/skip-l$ 
             http("functions.js").get("/wp-content/themes/twentyfifteen/js/functions.js?ver$ 
          ) 
       ) 

    setUp(
     scn.inject 
     (
     rampUsersPerSec(1) to(300) during(60 seconds), 
     constantUsersPerSec(300) during(600 seconds) 
    ) 
     .protocols(httpConf) 
    ) 
} 

ho solo un numero casuale generato invece di uno per ogni richiesta. Sai come risolverlo? Grazie !

+0

Non ho familiarità con gatling. Guardando solo la scala, sembra che il parametro, inclusa la chiamata Random.nextInt, a 'scenario.exec' venga eseguito immediatamente sulla linea val. Il modo usuale per chiamare il randomizer più di una volta è metterlo in una funzione che viene eseguita più di una volta, il che a sua volta potrebbe dipendere dal fatto che 'scenario.exec()' possa assumere una funzione come parametro o se puoi estendere una classe che prende come parametro in modo appropriato per il tuo caso d'uso. – Paul

risposta

2

Si sta passando un valore, quindi ovviamente new Random().nextInt viene chiamato una sola volta, quando viene creata la simulazione.

È necessario passare un Expression, ovvero una funzione. Solo allora sarà valutato ogni volta.

.get(session => "/" + new Random().nextInt())