2017-01-20 64 views
0

我已經建立了一些我想要針對我們的網絡應用程序運行的使用模式,我想要做的是將模式反覆循環一週。儘管如此,我還是無法找到正確的組合。如何循環加特林注射?

val scn: ScenarioBuilder = scenario("Issue Cert Request") 
    .exec(http("enroll_child_actor").post("/v1/actor/enroll") 
     .body(StringBody(session => createRequestActorBody(getActorId(session.userId)))) 
     .header("Content-Type","text/plain") 
     .header("Authorization", jwt => "ID " + TokenGenerator.get().generateOneTimeUseToken(uberActorSubjectName, Array("ots"), "http://localhost", 
      uberActorPrivateKey, uberActorIdentityCert).getEncoded) 
     .check(jsonPath("$.identityCertificate").saveAs("childIdCert"), 
      jsonPath("$.secureEndpointCertificate").saveAs("childEndpointCert") 
     ) 
    ).exec(http("request_secure_endpoint_certificate").post("/v1/cert/issue") 
    .body(StringBody(createRequestCertBodySecureEndpoint)) 
    .header("Content-Type","text/plain") 
    .header("Authorization", session => "ID " + TokenGenerator.get.generateTokenForActor(s"CN=http://localhost,UID=ots:${getActorId(session.userId)}", actorSecureEndpointKeyPair.getPrivate, CaCryptoUtils.certFromPemText(session.get("childEndpointCert") 
     .as[String])).getEncoded) 
).exec(http("request_identity_certificate").post("/v1/cert/issue") 
    .body(StringBody(createRequestCertBodySecureEndpoint)) 
    .header("Content-Type","text/plain") 
    .header("Authorization", session => "ID " + TokenGenerator.get.generateTokenForActor(s"CN=http://localhost,UID=ots:${getActorId(session.userId)}", actorIdentityKeyPair.getPrivate, CaCryptoUtils.certFromPemText(session.get("childIdCert").as[String])) 
     .getEncoded) 
) 

這是我的測試運行的地方,這些步驟是我想重複的。我曾嘗試在場景本身(上圖)上重複一遍,但看起來像重複會話,以便session.userId重複出現在我測試的應用中(我使用的場必須是唯一的)。

setUp { 
    scn.inject(nothingFor(4 seconds), 
    rampUsersPerSec(2) to usersMax during(durationAtMaxInSecs seconds), 
    constantUsersPerSec(usersConstant) during(durationAtLowerInSecs seconds), 
    nothingFor(3000 seconds) 
).protocols(httpConf) 
} 

缺少複製和粘貼一遍又一遍的注射,我怎麼能得到這些步驟重複指定的次數?

回答

0

神似你正在尋找,希望下面將幫助是什麼,我已刪除了部分信息: -

val vrScn = scenario("Requests").feed(orderRefs).group("Groups") { 
//See this logic how to Short Circuit    
asLongAs(session => jobsQue.length > 0) { 
    exec { session => 
    var requestIdValue = new scala.util.Random().nextInt(Integer.MAX_VALUE).toString(); 
    var length = jobsQue.length 
    try { 
     var reportElement = jobsQue.pop() 
    //Other variables 
    } catch { 
     case e: NoSuchElementException => print("Erorr") 
    } 

    //Set what you want to set 
    session.setAll(
     "reportsRuntimeInfos" -> "FIRST_REQUEST", 
     "xmlRequest" -> xml) 
    } 

    .group("${requestedPageSize} Page Report") { 
     group("${requestIdValue}") { 
     exec(
      http("Request Report") 
      .put(Configuration.URL + "/endpoint1") 
      .header("Content-Type", "application/xml") 
      .body(StringBody("${xmlRequest}")) 
      .check(status.is(200))) 
      .pause(Configuration.THINK_TIME_AFTER_PUT second) 
      //See this logic how to Short Circuit 
      .asLongAs(session => (!ALL_STOP_STATUS.contains(session.attributes("responseStatus")) && session.attributes("statusCode") == 200 && session.attributes("reportsRuntimeInfos") != "")) { 
      exec(
       http("Poll") 
       .get(Configuration.URL + "/endpoint2"))) 
      } 

     } 
    } 
} 

    setUp(scn.inject(atOnceUsers(Configuration.NO_OF_USERS))).maxDuration(Configuration.MAX_DURATION minutes); 
+0

謝謝!我會試試這個。 – drusolis