Skip to content

Commit

Permalink
extracting gatling work load model step to separate class
Browse files Browse the repository at this point in the history
  • Loading branch information
harikrishnan83 committed Aug 25, 2021
1 parent e0feabc commit d7efd6c
Show file tree
Hide file tree
Showing 6 changed files with 76 additions and 36 deletions.
37 changes: 37 additions & 0 deletions src/main/scala/org/znsio/perfiz/GatlingWorkLoadModelStep.scala
Original file line number Diff line number Diff line change
@@ -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"
}
4 changes: 2 additions & 2 deletions src/main/scala/org/znsio/perfiz/KarateFeature.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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)
})
Expand Down
34 changes: 0 additions & 34 deletions src/main/scala/org/znsio/perfiz/PerfizConfiguration.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand All @@ -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"
}
1 change: 1 addition & 0 deletions src/test/resources/perfiz.yaml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
karateFeaturesDir: "karate-features"
gatlingSimulationsDir: "src/gatling"
karateFeatures:
- karateFile: "petstore.feature"
gatlingSimulationName: "AllGet"
Expand Down
32 changes: 32 additions & 0 deletions src/test/scala/org/znsio/perfiz/GatlingWorkLoadModelStepSpec.scala
Original file line number Diff line number Diff line change
@@ -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))
}
}
}
}
4 changes: 4 additions & 0 deletions src/test/scala/org/znsio/perfiz/PerfizConfigurationSpec.scala
Original file line number Diff line number Diff line change
Expand Up @@ -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"))
}
}
}
}

0 comments on commit d7efd6c

Please sign in to comment.