Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Fix pauses computation, close #780

  • Loading branch information...
commit 58fc6f104840f451240a56ff152a9a4c499089fc 1 parent 5713b9b
@slandelle slandelle authored
View
2  gatling-recorder/src/main/resources/templates/simulation.ssp
@@ -18,7 +18,7 @@ class <%= simulationClassName %> extends Simulation {
def apply = {
val httpConf = httpConfig
- <%= protocolConfig %>
+<%= protocolConfig %>
<% for( header <- headers ) { %>
val headers_<%= header._1 %> = Map(
View
82 ...order/src/main/scala/com/excilys/ebi/gatling/recorder/controller/RecorderController.scala
@@ -20,12 +20,12 @@ import java.util.Date
import scala.math.round
import scala.tools.nsc.io.{ Directory, File }
-import scala.tools.nsc.io.Path.string2path
import org.codehaus.plexus.util.SelectorUtils
import org.jboss.netty.handler.codec.http.{ HttpMethod, HttpRequest, HttpResponse }
import org.jboss.netty.handler.codec.http.HttpHeaders.Names.PROXY_AUTHORIZATION
+import com.excilys.ebi.gatling.http.ahc.GatlingAsyncHandlerActor.REDIRECT_STATUS_CODES
import com.excilys.ebi.gatling.recorder.config.Configuration
import com.excilys.ebi.gatling.recorder.config.Configuration.configuration
import com.excilys.ebi.gatling.recorder.config.RecorderOptions
@@ -100,30 +100,46 @@ class RecorderController extends Logging {
}
def receiveResponse(request: HttpRequest, response: HttpResponse) {
- synchronized {
- if (isRequestToBeAdded(request)) {
- processRequest(request, response)
-
- // Pause calculation
- if (lastRequestDate != null) {
- val newRequestDate = new Date
- val diff = newRequestDate.getTime - lastRequestDate.getTime
- if (diff > 10) {
- val (pauseValue, pauseUnit) =
- if (diff > 1000)
- (round(diff / 1000).toLong, PauseUnit.SECONDS)
- else
- (diff, PauseUnit.MILLISECONDS)
-
- lastRequestDate = newRequestDate
- useUIThread {
- runningFrame.receiveEventInfo(new PauseInfo(pauseValue, pauseUnit))
- }
-
- scenarioElements = new PauseElement(pauseValue, pauseUnit) :: scenarioElements
+
+ def processPause {
+ // Pause calculation
+ if (lastRequestDate != null) {
+ val newRequestDate = new Date
+ val diff = newRequestDate.getTime - lastRequestDate.getTime
+ if (diff > 10) {
+ val (pauseValue, pauseUnit) =
+ if (diff > 1000)
+ (round(diff / 1000).toLong, PauseUnit.SECONDS)
+ else
+ (diff, PauseUnit.MILLISECONDS)
+
+ lastRequestDate = newRequestDate
+ useUIThread {
+ runningFrame.receiveEventInfo(new PauseInfo(pauseValue, pauseUnit))
}
- } else
- lastRequestDate = new Date
+
+ scenarioElements = new PauseElement(pauseValue, pauseUnit) :: scenarioElements
+ }
+ } else
+ lastRequestDate = new Date
+ }
+
+ def processRequest {
+
+ // Store request in scenario elements
+ scenarioElements = new RequestElement(request, response.getStatus.getCode, None) :: scenarioElements
+
+ // Send request information to view
+ useUIThread {
+ runningFrame.receiveEventInfo(new RequestInfo(request, response))
+ }
+ }
+
+ synchronized {
+ if (isRequestToBeAdded(request, response)) {
+ processPause
+ processRequest
+
}
}
}
@@ -156,9 +172,12 @@ class RecorderController extends Logging {
lastRequestDate = null
}
- private def isRequestToBeAdded(request: HttpRequest): Boolean = {
+ private def isRequestToBeAdded(request: HttpRequest, response: HttpResponse): Boolean = {
val uri = new URI(request.getUri)
- if (supportedHttpMethods.contains(request.getMethod)) {
+ val responseCode = response.getStatus.getCode
+ val skipBecauseOfRedirect = configuration.followRedirect && REDIRECT_STATUS_CODES.contains(responseCode)
+
+ if (!skipBecauseOfRedirect && supportedHttpMethods.contains(request.getMethod)) {
if (configuration.filterStrategy != FilterStrategy.NONE) {
val uriMatched = (for (configPattern <- configuration.patterns) yield {
@@ -183,15 +202,4 @@ class RecorderController extends Logging {
private def getFolder(folderName: String, folderPath: String): Directory = Directory(folderPath).createDirectory()
private def getOutputFolder = getFolder("output", configuration.outputFolder)
-
- private def processRequest(request: HttpRequest, response: HttpResponse) {
-
- // Store request in scenario elements
- scenarioElements = new RequestElement(request, response.getStatus.getCode, None) :: scenarioElements
-
- // Send request information to view
- useUIThread {
- runningFrame.receiveEventInfo(new RequestInfo(request, response))
- }
- }
}
View
25 ...rder/src/main/scala/com/excilys/ebi/gatling/recorder/scenario/ProtocolConfigElement.scala
@@ -15,7 +15,7 @@
*/
package com.excilys.ebi.gatling.recorder.scenario
-import com.excilys.ebi.gatling.core.util.StringHelper.END_OF_LINE
+import com.excilys.ebi.gatling.core.util.StringHelper.{ EMPTY, END_OF_LINE }
import com.excilys.ebi.gatling.http.Headers
import com.excilys.ebi.gatling.recorder.config.ProxyConfig
@@ -24,36 +24,39 @@ import grizzled.slf4j.Logging
class ProtocolConfigElement(baseUrl: String, proxy: ProxyConfig, followRedirect: Boolean, automaticReferer: Boolean, baseHeaders: Map[String, String]) extends ScenarioElement with Logging {
override def toString = {
+ val indent = "\t\t\t"
+
val sb = new StringBuilder
- sb.append(".baseURL(\"").append(baseUrl).append("\")").append(END_OF_LINE)
+ def appendLine(line: String) {
+ sb.append(indent).append(line).append(END_OF_LINE)
+ }
+
+ appendLine(".baseURL(\"" + baseUrl + "\")")
for {
proxyHost <- proxy.host
proxyPort <- proxy.port
} {
- sb.append(".proxy(\"").append(proxyHost).append("\", ").append(proxyPort).append(")")
- proxy.sslPort.map(proxySslPort => sb.append(".httpsPort(").append(proxySslPort).append(")"))
- sb.append(END_OF_LINE)
+ val sslPort = proxy.sslPort.map(proxySslPort => ".httpsPort(" + proxySslPort + ")").getOrElse(EMPTY)
+ appendLine(".proxy(\"" + proxyHost + "\", " + proxyPort + ")" + sslPort)
}
for {
proxyUsername <- proxy.username
proxyPassword <- proxy.password
} {
- sb.append(".credentials(\"").append(proxyUsername).append("\", ").append(proxyPassword).append("\")").append(END_OF_LINE)
+ appendLine(".credentials(\"" + proxyUsername + "\", " + proxyPassword + "\")")
}
if (!followRedirect)
- sb.append(".disableFollowRedirect").append(END_OF_LINE)
+ appendLine(".disableFollowRedirect")
if (!automaticReferer)
- sb.append(".disableAutomaticReferer").append(END_OF_LINE)
-
- val indent = "\t\t\t"
+ appendLine(".disableAutomaticReferer")
def appendHeader(methodName: String, headerValue: String) {
- sb.append(indent).append(".").append(methodName).append("(\"").append(headerValue).append("\")").append(END_OF_LINE)
+ appendLine("." + methodName + "(\"" + headerValue + "\")")
}
baseHeaders.foreach {
View
39 ...-recorder/src/main/scala/com/excilys/ebi/gatling/recorder/scenario/ScenarioExporter.scala
@@ -20,7 +20,6 @@ import java.util.Date
import scala.annotation.tailrec
import scala.collection.immutable.SortedMap
-import scala.math.min
import scala.tools.nsc.io.{ Directory, File }
import org.fusesource.scalate.TemplateEngine
@@ -28,7 +27,6 @@ import org.fusesource.scalate.TemplateEngine
import com.excilys.ebi.gatling.core.util.IOHelper.use
import com.excilys.ebi.gatling.core.util.StringHelper.EMPTY
import com.excilys.ebi.gatling.http.Headers
-import com.excilys.ebi.gatling.http.ahc.GatlingAsyncHandlerActor.REDIRECT_STATUS_CODES
import com.excilys.ebi.gatling.recorder.config.Configuration.configuration
import grizzled.slf4j.Logging
@@ -62,43 +60,8 @@ object ScenarioExporter extends Logging {
val protocolConfigElement = new ProtocolConfigElement(baseUrl, configuration.proxy, configuration.followRedirect, configuration.automaticReferer, baseHeaders)
- // If follow redirect, discard some recorded elements
- def getStatusCode(se: ScenarioElement) = se match {
- case r: RequestElement => r.statusCode
- case _ => 0
- }
-
- def filterRedirectsAndNonAuthorized(l: List[(ScenarioElement, Int)], e: ScenarioElement) = {
- if (l.isEmpty)
- e match {
- case r: RequestElement => List((r, r.statusCode))
- case x => List((x, 0))
- }
- else
- l.head match {
- case (lastRequestElement: RequestElement, lastStatusCode: Int) =>
- if (REDIRECT_STATUS_CODES.contains(lastStatusCode))
- e match {
- case r: RequestElement => (RequestElement(lastRequestElement, r.statusCode), r.statusCode) :: l.tail
- case _ => l
- }
- else
- (e, getStatusCode(e)) :: l
- case _ => (e, getStatusCode(e)) :: l
- }
- }
-
- val filteredElements =
- if (configuration.followRedirect)
- scenarioElements
- .foldLeft(List[(ScenarioElement, Int)]())(filterRedirectsAndNonAuthorized)
- .map { case (element, _) => element }
- .reverse
- else
- scenarioElements
-
// Add simulationClass to request elements
- val elementsList: List[ScenarioElement] = filteredElements.map {
+ val elementsList: List[ScenarioElement] = scenarioElements.map {
case e: RequestElement => RequestElement(e, configuration.simulationClassName)
case e => e
}
Please sign in to comment.
Something went wrong with that request. Please try again.