Skip to content

Commit

Permalink
renaming config params
Browse files Browse the repository at this point in the history
  • Loading branch information
harikrishnan83 committed Sep 8, 2021
1 parent b80b3a3 commit f8a3b46
Show file tree
Hide file tree
Showing 7 changed files with 92 additions and 16 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,25 @@ import scala.beans.BeanProperty
import scala.jdk.CollectionConverters._
import scala.language.postfixOps

class KarateFeature {
class GatlingScenario {
@BeanProperty
var karateFile: String = _

@deprecated("Will be removed in upcoming version. Replaced by gatlingScenarioName.")
@BeanProperty
var gatlingSimulationName: String = _

@BeanProperty
var gatlingScenarioName: String = _

@BeanProperty
var loadPattern: List[GatlingWorkLoadModelStep] = new ArrayList[GatlingWorkLoadModelStep]()

@BeanProperty
var uriPatterns: List[String] = new ArrayList[String]()

def name(): String = Option(gatlingScenarioName) filterNot (_.isEmpty) getOrElse gatlingSimulationName

def openWorkloadModelSteps: Seq[GatlingWorkLoadModelStep] = loadPattern.asScala.toList.filter(loadPattern => {
val openModelLoadPatterns = scala.List(NothingFor, AtOnceUsers, RampUsers, ConstantUsersPerSecond, RampUsersPerSecond, HeavisideUsers)
openModelLoadPatterns.contains(loadPattern.patternType)
Expand Down
11 changes: 8 additions & 3 deletions src/main/scala/org/znsio/perfiz/PerfizConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -11,17 +11,22 @@ import scala.jdk.CollectionConverters._
import scala.language.postfixOps

class PerfizConfiguration {
@deprecated("Will be removed in upcoming version. Replaced by gatlingScenarios.")
@BeanProperty
var karateFeatures: List[KarateFeature] = new ArrayList[KarateFeature]()
var karateFeatures: List[GatlingScenario] = new ArrayList[GatlingScenario]()
@BeanProperty
var gatlingScenarios: List[GatlingScenario] = new ArrayList[GatlingScenario]()
@BeanProperty
var karateEnv: String = _
@BeanProperty
var karateFeaturesDir: String = _
@BeanProperty
var gatlingSimulationsDir: String = _
@BeanProperty
var gatlingSimulationClass: String = _

def karateFeaturesAsList = {
karateFeatures.asScala.toList
def gatlingScenariosAsList: scala.List[GatlingScenario] = {
karateFeatures.asScala.toList ++ gatlingScenarios.asScala.toList
}
}

Expand Down
18 changes: 18 additions & 0 deletions src/test/resources/perfiz-deprecated.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
karateFeaturesDir: "karate-features"
gatlingSimulationsDir: "src/gatling"
karateFeatures:
- karateFile: "petstore.feature"
gatlingSimulationName: "AllGet"
loadPattern:
- patternType: "nothingFor"
duration: "15 seconds"
- patternType: "constantUsersPerSec"
userCount: "1"
duration: "30 seconds"
randomised: "false"
- patternType: "constantUsersPerSec"
userCount: "3"
duration: "15 seconds"
randomised: "false"
uriPatterns:
- "/pets/{id}"
3 changes: 3 additions & 0 deletions src/test/resources/perfiz-gatling-scala-simulations.yaml
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
karateFeaturesDir: "karate-features"
gatlingSimulationsDir: "src/gatling"
gatlingSimulationClass: "org.znsio.perfiz.PerfizSimulation"
4 changes: 2 additions & 2 deletions src/test/resources/perfiz.yaml
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
karateFeaturesDir: "karate-features"
gatlingSimulationsDir: "src/gatling"
karateFeatures:
gatlingScenarios:
- karateFile: "petstore.feature"
gatlingSimulationName: "AllGet"
gatlingScenarioName: "AllGet"
loadPattern:
- patternType: "nothingFor"
duration: "15 seconds"
Expand Down
48 changes: 46 additions & 2 deletions src/test/scala/org/znsio/perfiz/PerfizConfigurationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,34 @@ package org.znsio.perfiz
import org.scalatest.freespec.AnyFreeSpec

class PerfizConfigurationSpec extends AnyFreeSpec {
"given deprecated yaml configuration" - {
System.setProperty("PERFIZ", this.getClass.getResource("/perfiz-deprecated.yaml").getPath)

"when we parse it" - {
val configuration = PerfizConfiguration()

"should not be null" in {
assert(configuration != null)
}

"should extract karate features" in {
assert(configuration.gatlingScenariosAsList.size == 1)
}

"should extract karate features dir" in {
assert(configuration.karateFeaturesDir.equals("karate-features"))
}

"should extract gatling simulations dir" in {
assert(configuration.gatlingSimulationsDir.equals("src/gatling"))
}

"should extract gatling simulation name" in {
assert(configuration.gatlingScenariosAsList.head.name().equals("AllGet"))
}
}
}

"given valid yaml configuration" - {
System.setProperty("PERFIZ", this.getClass.getResource("/perfiz.yaml").getPath)

Expand All @@ -13,8 +41,8 @@ class PerfizConfigurationSpec extends AnyFreeSpec {
assert(configuration != null)
}

"should extract karate features" in {
assert(configuration.karateFeaturesAsList.size == 1)
"should extract gatling scenarios" in {
assert(configuration.gatlingScenariosAsList.size == 1)
}

"should extract karate features dir" in {
Expand All @@ -24,6 +52,22 @@ class PerfizConfigurationSpec extends AnyFreeSpec {
"should extract gatling simulations dir" in {
assert(configuration.gatlingSimulationsDir.equals("src/gatling"))
}

"should extract gatling scenario name" in {
assert(configuration.gatlingScenariosAsList.head.name().equals("AllGet"))
}
}
}

"given valid yaml configuration with gatling scala simulation" - {
System.setProperty("PERFIZ", this.getClass.getResource("/perfiz-gatling-scala-simulations.yaml").getPath)

"when we parse it" - {
val configuration = PerfizConfiguration()

"should not be null" in {
assert(configuration != null)
}
}
}
}
16 changes: 8 additions & 8 deletions src/test/scala/org/znsio/perfiz/PerfizSimulation.scala
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ class PerfizSimulation extends Simulation {

private val configuration: PerfizConfiguration = PerfizConfiguration()

private val builders: List[PopulationBuilder] = configuration.karateFeaturesAsList.map(karateFeatureConfig => {
val openInjectionSteps = karateFeatureConfig.openWorkloadModelSteps.map(f = loadPattern => {
private val builders: List[PopulationBuilder] = configuration.gatlingScenariosAsList.map(gatlingScenario => {
val openInjectionSteps = gatlingScenario.openWorkloadModelSteps.map(f = loadPattern => {
val openInjectionStep = loadPattern.getPatternType() match {
case NothingFor => nothingFor(loadPattern.durationAsFiniteDuration)
case AtOnceUsers => atOnceUsers(loadPattern.getUserCount())
Expand All @@ -38,7 +38,7 @@ class PerfizSimulation extends Simulation {
}
} else openInjectionStep
})
val closedInjectionSteps = karateFeatureConfig.closedWorkloadModelSteps.map(f = loadPattern => {
val closedInjectionSteps = gatlingScenario.closedWorkloadModelSteps.map(f = loadPattern => {
loadPattern.getPatternType() match {
case ConstantConcurrentUsers => constantConcurrentUsers(loadPattern.getUserCount()) during
loadPattern.durationAsFiniteDuration
Expand All @@ -48,16 +48,16 @@ class PerfizSimulation extends Simulation {
}
})
val protocol = karateProtocol(
karateFeatureConfig.getUriPatterns().asScala.map { uriPattern => uriPattern -> Nil }.toList: _*
gatlingScenario.getUriPatterns().asScala.map { uriPattern => uriPattern -> Nil }.toList: _*
)
if (!openInjectionSteps.isEmpty) {
scenario(karateFeatureConfig.getGatlingSimulationName()).
exec(karateFeature("classpath:" + karateFeatureConfig.getKarateFile())).
scenario(gatlingScenario.name()).
exec(karateFeature("classpath:" + gatlingScenario.getKarateFile())).
inject(openInjectionSteps).
protocols(protocol)
} else {
scenario(karateFeatureConfig.getGatlingSimulationName()).
exec(karateFeature("classpath:" + karateFeatureConfig.getKarateFile())).
scenario(gatlingScenario.name()).
exec(karateFeature("classpath:" + gatlingScenario.getKarateFile())).
inject(closedInjectionSteps).
protocols(protocol)
}
Expand Down

0 comments on commit f8a3b46

Please sign in to comment.