Skip to content

Commit

Permalink
Use loadtest4j 0.8.0 (#13)
Browse files Browse the repository at this point in the history
  • Loading branch information
themasterchef authored Jun 2, 2018
1 parent 209c5cf commit 2a4ee6c
Show file tree
Hide file tree
Showing 4 changed files with 28 additions and 9 deletions.
2 changes: 1 addition & 1 deletion pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@
<dependency>
<groupId>com.github.loadtest4j</groupId>
<artifactId>loadtest4j</artifactId>
<version>0.7.0</version>
<version>0.8.0</version>
</dependency>
<dependency>
<groupId>io.gatling</groupId>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package com.github.loadtest4j.drivers.gatling

import java.util.Optional

import com.github.loadtest4j.loadtest4j.DriverResult

class GatlingResult(ok: Long, ko: Long, reportUrl: String) extends DriverResult {
override def getKo: Long = ko

override def getOk: Long = ok

override def getReportUrl: Optional[String] = Optional.of(reportUrl)
}
16 changes: 8 additions & 8 deletions src/main/scala/io/gatling/RunResultProcessorFacade.scala
Original file line number Diff line number Diff line change
@@ -1,14 +1,16 @@
package io.gatling

import com.github.loadtest4j.drivers.gatling.GatlingResult
import com.github.loadtest4j.loadtest4j.DriverResult
import io.gatling.app.RunResult
import io.gatling.charts.stats.LogFileReader
import io.gatling.commons.stats.{GeneralStats, KO, OK}
import io.gatling.core.config.GatlingConfiguration
import io.gatling.core.config.GatlingFiles.simulationLogDirectory

class RunResultProcessorFacade(implicit configuration: GatlingConfiguration) {
def processRunResult(runResult: RunResult): DriverResult = {
val logFileReader = initLogFileReader(runResult)
val logFileReader = new LogFileReader(runResult.runId)

// We don't use these result filters in loadtest4j
val requestName = None
Expand Down Expand Up @@ -36,11 +38,8 @@ class RunResultProcessorFacade(implicit configuration: GatlingConfiguration) {
case (rangeName, count) => GroupedCount(rangeName, count, total.count)
}

toDriverResult(numberOfRequestsStatistics)
}

private def initLogFileReader(runResult: RunResult) = {
new LogFileReader(runResult.runId)
val reportUrl = simulationLogDirectory(runResult.runId, create = false).toUri.toString
toDriverResult(numberOfRequestsStatistics, reportUrl)
}

private case class Statistics[T: Numeric](total: T, success: T, failure: T) {
Expand All @@ -54,9 +53,10 @@ class RunResultProcessorFacade(implicit configuration: GatlingConfiguration) {
val percentage: Int = if (total == 0) 0 else (count.toDouble / total * 100).round.toInt
}

private def toDriverResult(numberOfRequestsStatistics: Statistics[Long]) = {
private def toDriverResult(numberOfRequestsStatistics: Statistics[Long], reportUrl: String) = {
val ok = numberOfRequestsStatistics.success
val ko = numberOfRequestsStatistics.failure
new DriverResult(ok, ko)

new GatlingResult(ok, ko, reportUrl)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,7 @@ class GatlingTest {
// Then
assertEquals(0, result.getKo)
assertGreaterThanOrEqualTo(1, result.getOk)
assertStartsWith("file://", result.getReportUrl.get())
// And
verifyHttp(httpServer).atLeast(1, method(Method.GET), uri("/"))
}
Expand Down Expand Up @@ -108,6 +109,11 @@ class GatlingTest {
}
}

private def assertStartsWith(prefix: String, actual: String): Unit = {
val msg = "'%s' did not start with the substring '%s'.".format(actual, prefix)
assertTrue(msg, actual.startsWith(prefix))
}

private def assertGreaterThanOrEqualTo(expected: Long, actual: Long): Unit ={
val msg = "Expected %d to be >= %d, but it was not.".format(actual, expected)
assertTrue(msg, actual >= expected)
Expand Down

0 comments on commit 2a4ee6c

Please sign in to comment.