From d7efd6cd550366cc016e76d4b98522ca8fb97710 Mon Sep 17 00:00:00 2001 From: Hari Krishnan Date: Wed, 25 Aug 2021 15:04:52 +0530 Subject: [PATCH] extracting gatling work load model step to separate class --- .../perfiz/GatlingWorkLoadModelStep.scala | 37 +++++++++++++++++++ .../org/znsio/perfiz/KarateFeature.scala | 4 +- .../znsio/perfiz/PerfizConfiguration.scala | 34 ----------------- src/test/resources/perfiz.yaml | 1 + .../perfiz/GatlingWorkLoadModelStepSpec.scala | 32 ++++++++++++++++ .../perfiz/PerfizConfigurationSpec.scala | 4 ++ 6 files changed, 76 insertions(+), 36 deletions(-) create mode 100644 src/main/scala/org/znsio/perfiz/GatlingWorkLoadModelStep.scala create mode 100644 src/test/scala/org/znsio/perfiz/GatlingWorkLoadModelStepSpec.scala diff --git a/src/main/scala/org/znsio/perfiz/GatlingWorkLoadModelStep.scala b/src/main/scala/org/znsio/perfiz/GatlingWorkLoadModelStep.scala new file mode 100644 index 0000000..6ba73a2 --- /dev/null +++ b/src/main/scala/org/znsio/perfiz/GatlingWorkLoadModelStep.scala @@ -0,0 +1,37 @@ +package org.znsio.perfiz + +import scala.beans.BeanProperty +import scala.concurrent.duration.{Duration, FiniteDuration} + +class GatlingWorkLoadModelStep { + @BeanProperty + var patternType: String = _ + + @BeanProperty + var userCount: Int = _ + + @BeanProperty + var duration: String = _ + + @BeanProperty + var randomised: Boolean = _ + + @BeanProperty + var targetUserCount: Int = _ + + def durationAsFiniteDuration = Duration(duration).asInstanceOf[FiniteDuration] +} + +object OpenWorkloadModel { + val NothingFor = "nothingFor" + val AtOnceUsers = "atOnceUsers" + val RampUsers = "rampUsers" + val ConstantUsersPerSecond = "constantUsersPerSec" + val RampUsersPerSecond = "rampUsersPerSec" + val HeavisideUsers = "heavisideUsers" +} + +object ClosedWorkloadModel { + val ConstantConcurrentUsers = "constantConcurrentUsers" + val RampConcurrentUsers = "rampConcurrentUsers" +} \ No newline at end of file diff --git a/src/main/scala/org/znsio/perfiz/KarateFeature.scala b/src/main/scala/org/znsio/perfiz/KarateFeature.scala index d47088b..52fbb1a 100644 --- a/src/main/scala/org/znsio/perfiz/KarateFeature.scala +++ b/src/main/scala/org/znsio/perfiz/KarateFeature.scala @@ -22,12 +22,12 @@ class KarateFeature { @BeanProperty var uriPatterns: List[String] = new ArrayList[String]() - def openWorkloadModelSteps = loadPattern.asScala.toList.filter(loadPattern => { + def openWorkloadModelSteps: Seq[GatlingWorkLoadModelStep] = loadPattern.asScala.toList.filter(loadPattern => { val openModelLoadPatterns = scala.List(NothingFor, AtOnceUsers, RampUsers, ConstantUsersPerSecond, RampUsersPerSecond, HeavisideUsers) openModelLoadPatterns.contains(loadPattern.patternType) }) - def closedWorkloadModelSteps = loadPattern.asScala.toList.filter(loadPattern => { + def closedWorkloadModelSteps: Seq[GatlingWorkLoadModelStep] = loadPattern.asScala.toList.filter(loadPattern => { val closedModelLoadPatterns = scala.List(ConstantConcurrentUsers, RampConcurrentUsers) closedModelLoadPatterns.contains(loadPattern.patternType) }) diff --git a/src/main/scala/org/znsio/perfiz/PerfizConfiguration.scala b/src/main/scala/org/znsio/perfiz/PerfizConfiguration.scala index 98aa856..f5464ee 100644 --- a/src/main/scala/org/znsio/perfiz/PerfizConfiguration.scala +++ b/src/main/scala/org/znsio/perfiz/PerfizConfiguration.scala @@ -7,7 +7,6 @@ import org.yaml.snakeyaml.Yaml import org.yaml.snakeyaml.constructor.Constructor import scala.beans.BeanProperty -import scala.concurrent.duration.{Duration, FiniteDuration} import scala.jdk.CollectionConverters._ import scala.language.postfixOps @@ -30,37 +29,4 @@ object PerfizConfiguration { def apply(): PerfizConfiguration = new Yaml(new Constructor(classOf[PerfizConfiguration])).load( new FileInputStream(new File(System.getProperty("PERFIZ"))) ) -} - -class GatlingWorkLoadModelStep { - @BeanProperty - var patternType: String = _ - - @BeanProperty - var userCount: Int = _ - - @BeanProperty - var duration: String = _ - - @BeanProperty - var randomised: Boolean = _ - - @BeanProperty - var targetUserCount: Int = _ - - def durationAsFiniteDuration = Duration(duration).asInstanceOf[FiniteDuration] -} - -object OpenWorkloadModel { - val NothingFor = "nothingFor" - val AtOnceUsers = "atOnceUsers" - val RampUsers = "rampUsers" - val ConstantUsersPerSecond = "constantUsersPerSec" - val RampUsersPerSecond = "rampUsersPerSec" - val HeavisideUsers = "heavisideUsers" -} - -object ClosedWorkloadModel { - val ConstantConcurrentUsers = "constantConcurrentUsers" - val RampConcurrentUsers = "rampConcurrentUsers" } \ No newline at end of file diff --git a/src/test/resources/perfiz.yaml b/src/test/resources/perfiz.yaml index a391485..d910035 100644 --- a/src/test/resources/perfiz.yaml +++ b/src/test/resources/perfiz.yaml @@ -1,4 +1,5 @@ karateFeaturesDir: "karate-features" +gatlingSimulationsDir: "src/gatling" karateFeatures: - karateFile: "petstore.feature" gatlingSimulationName: "AllGet" diff --git a/src/test/scala/org/znsio/perfiz/GatlingWorkLoadModelStepSpec.scala b/src/test/scala/org/znsio/perfiz/GatlingWorkLoadModelStepSpec.scala new file mode 100644 index 0000000..2e7af95 --- /dev/null +++ b/src/test/scala/org/znsio/perfiz/GatlingWorkLoadModelStepSpec.scala @@ -0,0 +1,32 @@ +package org.znsio.perfiz + +import org.scalatest.freespec.AnyFreeSpec + +import scala.concurrent.duration.{Duration, FiniteDuration} + +class GatlingWorkLoadModelStepSpec extends AnyFreeSpec { + "given a gatling workload model step" - { + + "when duration is set in minutes" - { + val gatlingWorkLoadModelStep = new GatlingWorkLoadModelStep + val twoMinutesString = "2 minutes" + gatlingWorkLoadModelStep.duration = twoMinutesString + + "should convert to Finite Duration" in { + val twoMinutes = Duration(twoMinutesString).asInstanceOf[FiniteDuration] + assert(gatlingWorkLoadModelStep.durationAsFiniteDuration.equals(twoMinutes)) + } + } + + "when duration is set in seconds" - { + val gatlingWorkLoadModelStep = new GatlingWorkLoadModelStep + val oneSecondString = "1 second" + gatlingWorkLoadModelStep.duration = oneSecondString + + "should convert to Finite Duration" in { + val oneSecond = Duration(oneSecondString).asInstanceOf[FiniteDuration] + assert(gatlingWorkLoadModelStep.durationAsFiniteDuration.equals(oneSecond)) + } + } + } +} diff --git a/src/test/scala/org/znsio/perfiz/PerfizConfigurationSpec.scala b/src/test/scala/org/znsio/perfiz/PerfizConfigurationSpec.scala index 0062eb7..6c7d57a 100644 --- a/src/test/scala/org/znsio/perfiz/PerfizConfigurationSpec.scala +++ b/src/test/scala/org/znsio/perfiz/PerfizConfigurationSpec.scala @@ -20,6 +20,10 @@ class PerfizConfigurationSpec extends AnyFreeSpec { "should extract karate features dir" in { assert(configuration.karateFeaturesDir.equals("karate-features")) } + + "should extract gatling simulations dir" in { + assert(configuration.gatlingSimulationsDir.equals("src/gatling")) + } } } }