Skip to content

Commit

Permalink
Add support for negative date ranges in feeders
Browse files Browse the repository at this point in the history
Refactored `RandomDateRangeFeeder` to handle negative offset dates, added `negativeDateRange` feeder example, and updated related utilities and tests. This improves flexibility in generating dynamic date ranges.
  • Loading branch information
jigarkhwar committed Dec 11, 2024
1 parent 91048e6 commit b1d2903
Show file tree
Hide file tree
Showing 6 changed files with 263 additions and 209 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
package org.galaxio.performance.example

import io.gatling.app.Gatling
import io.gatling.shared.cli.GatlingCliOptions

object GatlingRunner {

def main(args: Array[String]): Unit = {

// this is where you specify the class you want to run
val simulationClass = classOf[SampleSimulation].getName

Gatling.main(
args ++
Array(
GatlingCliOptions.Simulation.shortOption,
simulationClass,
GatlingCliOptions.ResultsFolder.shortOption,
"results",
GatlingCliOptions.Launcher.shortOption,
"sbt",
),
)
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ import org.galaxio.gatling.utils.phone._

import java.time.format.DateTimeFormatter
import java.time.temporal.ChronoUnit
import java.time.{LocalDateTime, ZoneId}
import java.time.{LocalDateTime, ZoneId, ZoneOffset, ZonedDateTime}

object Feeders {

Expand Down Expand Up @@ -42,6 +42,17 @@ object Feeders {
val vacationDate: Feeder[String] =
RandomDateRangeFeeder("startOfVacation", "endOfVacation", 14, "yyyy-MM-dd", LocalDateTime.now(), ChronoUnit.DAYS)

val negativeDateRange: Feeder[String] = {
RandomDateRangeFeeder(
"from",
"to",
-1,
"YYYY-MM-dd",
ZonedDateTime.now(ZoneOffset.UTC).toLocalDateTime,
ChronoUnit.MONTHS,
)
}

// random Int
val randomDigit: Feeder[Int] = RandomDigitFeeder("randomDigit")
val randomRangeInt: Feeder[Int] = CustomFeeder[Int]("randomRangeInt", RandomDataGenerators.randomValue(1, 50))
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ class SampleScenario {
.feed(randomDigit)
.feed(randomPhone)
.feed(randomRangeString)
.feed(negativeDateRange)
.feed(randomString)
.feed(randomUsaPhone)
.feed(randomUuid)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,25 @@ import java.time.temporal.{ChronoUnit, TemporalUnit}
import io.gatling.core.feeder.Feeder
import org.galaxio.gatling.utils.RandomDataGenerators


object RandomDateRangeFeeder {

def apply(
paramNameFrom: String,
paramNameTo: String,
offsetDate: Long,
datePattern: String = "yyyy-MM-dd",
dateFrom: LocalDateTime = LocalDateTime.now(),
unit: TemporalUnit = ChronoUnit.DAYS,
timezone: ZoneId = ZoneId.systemDefault(),
): Feeder[String] =
feeder[String](paramNameFrom)(dateFrom.format(DateTimeFormatter.ofPattern(datePattern)))
.map(m => m + (paramNameTo -> RandomDataGenerators.randomDate(offsetDate, datePattern, dateFrom, unit, timezone)))
paramNameFrom: String,
paramNameTo: String,
offsetDate: Long,
datePattern: String = "yyyy-MM-dd",
dateFrom: LocalDateTime = LocalDateTime.now(),
unit: TemporalUnit = ChronoUnit.DAYS,
timezone: ZoneId = ZoneId.systemDefault(),
): Feeder[String] = {
val dateFormatter = DateTimeFormatter.ofPattern(datePattern)

def addRandomDateToMap(originalMap: Map[String, String]): Map[String, String] =
originalMap + (paramNameTo -> RandomDataGenerators.randomDate(offsetDate, datePattern, dateFrom, unit, timezone))

feeder[String](paramNameFrom)(dateFrom.format(dateFormatter)).map(addRandomDateToMap)
}


}
Loading

0 comments on commit b1d2903

Please sign in to comment.