Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: update gatling 3.11 #4

Merged
merged 3 commits into from
Jun 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
10 changes: 5 additions & 5 deletions project/Dependencies.scala
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ object Dependencies {
"io.gatling" % "gatling-redis",
"io.gatling" % "gatling-core-java",
"io.gatling" % "gatling-redis-java",
).map(_ % "3.10.5" % Provided)
).map(_ % "3.11.4" % Provided)

lazy val fastUUID: Seq[ModuleID] = Seq(
"com.eatthepath" % "fast-uuid" % "0.2.0" % Provided,
Expand All @@ -18,16 +18,16 @@ object Dependencies {
lazy val gatling: Seq[ModuleID] = Seq(
"io.gatling.highcharts" % "gatling-charts-highcharts",
"io.gatling" % "gatling-test-framework",
).map(_ % "3.10.5" % Test)
).map(_ % "3.11.4" % Test)

lazy val json4s: Seq[ModuleID] = Seq(
"org.json4s" %% "json4s-native" % "4.1.0-M5",
"org.json4s" %% "json4s-jackson" % "4.1.0-M5",
)

lazy val pureConfig: Seq[ModuleID] = Seq(
"com.github.pureconfig" %% "pureconfig" % "0.17.6",
"com.github.pureconfig" %% "pureconfig-yaml" % "0.17.6",
"com.github.pureconfig" %% "pureconfig" % "0.17.7",
"com.github.pureconfig" %% "pureconfig-yaml" % "0.17.7",
)

lazy val jackson: Seq[ModuleID] = Seq(
Expand Down Expand Up @@ -63,7 +63,7 @@ object Dependencies {
"io.circe" %% "circe-core" % "0.15.0-M1",
"io.circe" %% "circe-generic" % "0.15.0-M1",
"io.circe" %% "circe-parser" % "0.15.0-M1",
"io.circe" %% "circe-yaml" % "0.15.0-RC1",
"io.circe" %% "circe-yaml" % "1.15.0",
)

lazy val scalaTesting: Seq[ModuleID] = scalaCheck ++ scalaTest ++ scalaMock ++ scalaTestPlus
Expand Down
2 changes: 1 addition & 1 deletion project/build.properties
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
# suppress inspection "UnusedProperty"
sbt.version=1.9.9
sbt.version=1.10.0
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.redis.RedisClientPool
import io.gatling.commons.validation.{Failure, Success, SuccessWrapper}
import io.gatling.core.action.{Action, ChainableAction}
import io.gatling.core.session.{Expression, Session}
import io.gatling.core.stats.StatsEngine
import io.gatling.core.structure.ScenarioContext
import io.gatling.core.util.NameGen

Expand Down Expand Up @@ -38,7 +39,7 @@ case class RedisDelAction(
next ! session
} catch {
case e: Exception =>
ctx.coreComponents.statsEngine.logCrash(
ctx.coreComponents.statsEngine.logRequestCrash(
session.scenario,
session.groups,
requestName = name,
Expand All @@ -47,4 +48,5 @@ case class RedisDelAction(
next ! session
}

override def statsEngine: StatsEngine = ctx.coreComponents.statsEngine
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.redis.RedisClientPool
import io.gatling.commons.validation.{Failure, Success, SuccessWrapper}
import io.gatling.core.action.{Action, ChainableAction}
import io.gatling.core.session.{Expression, Session}
import io.gatling.core.stats.StatsEngine
import io.gatling.core.structure.ScenarioContext
import io.gatling.core.util.NameGen

Expand Down Expand Up @@ -40,7 +41,7 @@ case class RedisSaddAction(
next ! session
} catch {
case e: Exception =>
ctx.coreComponents.statsEngine.logCrash(
ctx.coreComponents.statsEngine.logRequestCrash(
session.scenario,
session.groups,
requestName = name,
Expand All @@ -49,4 +50,5 @@ case class RedisSaddAction(
next ! session
}

override def statsEngine: StatsEngine = ctx.coreComponents.statsEngine
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.redis.RedisClientPool
import io.gatling.commons.validation.{Failure, Success, SuccessWrapper}
import io.gatling.core.action.{Action, ChainableAction}
import io.gatling.core.session.{Expression, Session}
import io.gatling.core.stats.StatsEngine
import io.gatling.core.structure.ScenarioContext
import io.gatling.core.util.NameGen

Expand Down Expand Up @@ -40,7 +41,7 @@ case class RedisSremAction(
next ! session
} catch {
case e: Exception =>
ctx.coreComponents.statsEngine.logCrash(
ctx.coreComponents.statsEngine.logRequestCrash(
session.scenario,
session.groups,
requestName = name,
Expand All @@ -49,4 +50,5 @@ case class RedisSremAction(
next ! session
}

override def statsEngine: StatsEngine = ctx.coreComponents.statsEngine
}
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class TransactionsActor(statsEngine: StatsEngine) extends Actor with LazyLogging
}

private def crash(prefix: String, errorMsg: String, session: Session, next: Action): Unit = {
statsEngine.logCrash(session.scenario, session.groups, prefix, errorMsg)
statsEngine.logRequestCrash(session.scenario, session.groups, prefix, errorMsg)
next ! session.markAsFailed
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package org.galaxio.gatling.transactions.actions
import io.gatling.core.action.{Action, ChainableAction}
import io.gatling.core.controller.throttle.Throttler
import io.gatling.core.session.{Expression, Session}
import io.gatling.core.stats.StatsEngine
import io.gatling.core.structure.ScenarioContext
import io.gatling.core.util.NameGen
import org.galaxio.gatling.transactions.TransactionsProtocol
Expand Down Expand Up @@ -30,4 +31,6 @@ class EndTransactionAction(
},
),
)

override def statsEngine: StatsEngine = ctx.coreComponents.statsEngine
}
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import io.gatling.commons.validation._
import io.gatling.core.action.{Action, ChainableAction}
import io.gatling.core.controller.throttle.Throttler
import io.gatling.core.session.{Expression, Session}
import io.gatling.core.stats.StatsEngine
import io.gatling.core.structure.ScenarioContext
import io.gatling.core.util.NameGen
import org.galaxio.gatling.transactions.TransactionsProtocol
Expand Down Expand Up @@ -32,4 +33,6 @@ class StartTransactionAction(transactionName: Expression[String], ctx: ScenarioC
},
),
)

override def statsEngine: StatsEngine = ctx.coreComponents.statsEngine
}
30 changes: 21 additions & 9 deletions src/test/scala/org/galaxio/gatling/transactions/Mocks.scala
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
package org.galaxio.gatling.transactions
import akka.actor.{ActorRef, ActorSystem}
import akka.actor.{ActorRef, ActorSystem, Terminated}
import io.gatling.commons.util.DefaultClock
import io.gatling.core.CoreComponents
import io.gatling.core.pause.Disabled
import io.gatling.core.protocol.{ProtocolComponentsRegistry, ProtocolKey}
import io.gatling.core.protocol.{Protocol, ProtocolComponents, ProtocolComponentsRegistry, ProtocolKey}
import io.gatling.core.stats.StatsEngine
import io.gatling.core.structure.ScenarioContext
import org.scalamock.scalatest.MockFactory
Expand All @@ -24,11 +24,17 @@ trait Mocks extends MockFactory with BeforeAndAfterAll {

def getEvents: List[Evt] = this.events.asScala.toList

val statsEngine = stub[StatsEngine]
private val componentsCache = mutable.Map.empty[ProtocolKey[_, _], ProtocolComponents]
private val componentsFactoryCache = mutable.Map.empty[ProtocolKey[_, _], Protocol => ProtocolComponents]
private val defaultProtocolValueCache = mutable.Map.empty[ProtocolKey[_, _], Protocol]

val statsEngine: StatsEngine = stub[StatsEngine]

val testTransactionsActor: ActorRef = testActorSystem.actorOf(TransactionsActor.props(statsEngine))

private val protoComponents = new TransactionsComponents(new TransactionTracker(testTransactionsActor))
private val protoComponents: TransactionsComponents = new TransactionsComponents(
new TransactionTracker(testTransactionsActor),
)

private val testCoreComponents = new CoreComponents(
testActorSystem,
Expand All @@ -41,10 +47,16 @@ trait Mocks extends MockFactory with BeforeAndAfterAll {
null,
)

val ProtocolComponentsRegistryMock: ProtocolComponentsRegistry =
new ProtocolComponentsRegistry(testCoreComponents, Map.empty, mutable.Map.empty) {
override def components[P, C](key: ProtocolKey[P, C]): C = protoComponents.asInstanceOf[C]
}
val ProtocolComponentsRegistryMock: ProtocolComponentsRegistry = new ProtocolComponentsRegistry(
testCoreComponents,
Map.empty,
componentsFactoryCache,
defaultProtocolValueCache,
)

// new ProtocolComponentsRegistry(testCoreComponents, Map.empty, mutable.Map.empty, mutable.Map.empty) {
// override def components[P, C](key: ProtocolKey[P, C]): C = protoComponents.asInstanceOf[C]
// }

val testContext = new ScenarioContext(
testCoreComponents,
Expand All @@ -53,7 +65,7 @@ trait Mocks extends MockFactory with BeforeAndAfterAll {
false,
)

def stop = Await.result(testActorSystem.terminate(), 10.seconds)
def stop: Terminated = Await.result(testActorSystem.terminate(), 10.seconds)
}

override protected def afterAll(): Unit = {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ class TransactionsSpec extends AnyFlatSpec with Matchers with Mocks {
}

"Scenario with not opened transactions after run" should "fail with transaction close error" in new MockedGatlingCtx {
(statsEngine.logCrash _)
(statsEngine.logRequestCrash _)
.when(*, *, *, *)
.onCall { (_, _, c, d) =>
events.add(Evt("ERROR", c, System.currentTimeMillis(), System.currentTimeMillis(), "KO", Some(d)))
Expand All @@ -105,7 +105,7 @@ class TransactionsSpec extends AnyFlatSpec with Matchers with Mocks {
}

"Scenario with a transaction that ended before it started after run" should "fail with illegal state error" in new MockedGatlingCtx {
(statsEngine.logCrash _)
(statsEngine.logRequestCrash _)
.when(*, *, *, *)
.onCall { (_, _, c, d) =>
events.add(Evt("ERROR", c, System.currentTimeMillis(), System.currentTimeMillis(), "KO", Some(d)))
Expand All @@ -128,7 +128,7 @@ class TransactionsSpec extends AnyFlatSpec with Matchers with Mocks {
}

"Scenario with incorrect transaction sequence after run" should "fail with transaction close error" in new MockedGatlingCtx {
(statsEngine.logCrash _)
(statsEngine.logRequestCrash _)
.when(*, *, *, *)
.onCall { (_, _, c, d) =>
events.add(Evt("ERROR", c, System.currentTimeMillis(), System.currentTimeMillis(), "KO", Some(d)))
Expand Down
30 changes: 29 additions & 1 deletion src/test/scala/org/galaxio/gatling/transactions/fixtures.scala
Original file line number Diff line number Diff line change
@@ -1,7 +1,10 @@
package org.galaxio.gatling.transactions

import akka.actor.ActorRef
import io.gatling.commons.stats.Status
import io.gatling.core.action.{Action, ChainableAction}
import io.gatling.core.session.Session
import io.gatling.core.session.{GroupBlock, Session}
import io.gatling.core.stats.StatsEngine

object fixtures {
val noAction: Action = new ChainableAction {
Expand All @@ -10,6 +13,31 @@ object fixtures {
override def name: String = "noop"

override protected def execute(session: Session): Unit = ()

override def statsEngine: StatsEngine = new StatsEngine {
override def start(): Unit = {}

override def stop(controller: ActorRef, exception: Option[Exception]): Unit = {}

override def logUserStart(scenario: String): Unit = {}

override def logUserEnd(scenario: String): Unit = {}

override def logResponse(
scenario: String,
groups: List[String],
requestName: String,
startTimestamp: Long,
endTimestamp: Long,
status: Status,
responseCode: Option[String],
message: Option[String],
): Unit = {}

override def logGroupEnd(scenario: String, groupBlock: GroupBlock, exitTimestamp: Long): Unit = {}

override def logRequestCrash(scenario: String, groups: List[String], requestName: String, error: String): Unit = {}
}
}

val fakeEventLoop = new FakeEventLoop
Expand Down
Loading