-
-
Save rookieInTraining/9261ec8c708abdd94da21e18c4aa5e02 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class AcdActionBuilder(requestName: String) extends ActionBuilder { | |
private def components(protocolComponentsRegistry: ProtocolComponentsRegistry): AcdComponent = { | |
protocolComponentsRegistry.components(AcdProtocol.customProtocolKey) | |
} | |
override def build(ctx: ScenarioContext, next: Action): Action = { | |
import ctx._ | |
val statsEngine = coreComponents.statsEngine | |
val customComponent = components(protocolComponentsRegistry) | |
new AcdAction(customComponent.protocol, coreComponents, statsEngine, next) | |
} | |
} | |
class AcdAction( | |
protocol: AcdProtocol, | |
val coreComponents: CoreComponents, | |
val statsEngine: StatsEngine, | |
val next: Action | |
) extends ExitableAction with NameGen { | |
val randomList: List[Long] = List(System.currentTimeMillis()) | |
override def name: String = genName("httpRequest") | |
override def clock: Clock = coreComponents.clock | |
override protected def execute(session: Session): Unit = { | |
val start = System.currentTimeMillis | |
Thread.sleep((Math.random * 1000).toLong) | |
val end = System.currentTimeMillis | |
statsEngine.logResponse("Scenario-" + name, List(), name, start, end, OK, None, None) | |
next ! session | |
} | |
} | |
case class AcdComponent(protocol: AcdProtocol) extends ProtocolComponents { | |
override def onStart: Session => Session = Session.Identity | |
override def onExit: Session => Unit = ProtocolComponents.NoopOnExit | |
} | |
object AcdProtocol { | |
val customProtocolKey: ProtocolKey[AcdProtocol, AcdComponent] = new ProtocolKey[AcdProtocol, AcdComponent] { | |
override def protocolClass: Class[Protocol] = classOf[AcdComponent].asInstanceOf[Class[Protocol]] | |
override def defaultProtocolValue(configuration: GatlingConfiguration): AcdProtocol = | |
throw new IllegalStateException("Can't provide a default value for AcdProtocol") | |
override def newComponents(coreComponents: CoreComponents): AcdProtocol => AcdComponent = { | |
acdProtocol => AcdComponent(acdProtocol) | |
} | |
} | |
} | |
final case class AcdProtocol(address: String, port: Int) extends Protocol { | |
type Components = AcdComponent | |
} | |
object AcdProtocolBuilderBase { | |
def endpoint(address: String, port: Int) = AcdProtocolBuilder(address, port) | |
} | |
case class AcdProtocolBuilder(address: String, port: Int) { | |
def build = AcdProtocol(address,port) | |
} | |
trait AcdDsl { | |
val acd: AcdProtocolBuilderBase.type = AcdProtocolBuilderBase | |
implicit def customBuilderToProtocol(builder: AcdProtocolBuilder): AcdProtocol = builder.build | |
def acd(name: String) = new AcdActionBuilder(name) | |
} | |
object Predef extends AcdDsl { | |
} | |
class AcdPerformanceTest extends Simulation { | |
val acdProtocol: AcdProtocolBuilder = acd.endpoint("127.0.0.1",8888) | |
//Scenario | |
val acdScenario: ScenarioBuilder = scenario("Random Connection") | |
.exec(acd("Check")) | |
setUp( | |
acdScenario.inject(atOnceUsers(2)) | |
).protocols(acdProtocol) // <--- getting the error at this line | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment