This repository has been archived by the owner on Mar 22, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 75
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support for gatling 2.2 and kafka 0.10
- Loading branch information
Luca Barzè
committed
Feb 10, 2017
1 parent
ae3520e
commit 321e3e5
Showing
9 changed files
with
169 additions
and
106 deletions.
There are no files selected for viewing
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
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,11 +1,15 @@ | ||
package com.github.mnogu.gatling.kafka | ||
|
||
import com.github.mnogu.gatling.kafka.config.KafkaProtocol | ||
import com.github.mnogu.gatling.kafka.protocol.KafkaProtocolBuilder | ||
import com.github.mnogu.gatling.kafka.request.builder.KafkaRequestBuilder | ||
import io.gatling.core.config.GatlingConfiguration | ||
import io.gatling.core.session.Expression | ||
|
||
|
||
object Predef { | ||
def kafka = KafkaProtocol.DefaultKafkaProtocol | ||
|
||
def kafka(implicit configuration: GatlingConfiguration) = KafkaProtocolBuilder(configuration) | ||
|
||
def kafka(requestName: Expression[String]) = new KafkaRequestBuilder(requestName) | ||
|
||
} |
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
37 changes: 22 additions & 15 deletions
37
src/main/scala/com/github/mnogu/gatling/kafka/action/KafkaRequestActionBuilder.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,27 +1,34 @@ | ||
package com.github.mnogu.gatling.kafka.action | ||
|
||
import akka.actor.ActorDSL.actor | ||
import akka.actor.ActorRef | ||
import com.github.mnogu.gatling.kafka.config.KafkaProtocol | ||
import com.github.mnogu.gatling.kafka.protocol.{KafkaComponents, KafkaProtocol} | ||
import com.github.mnogu.gatling.kafka.request.builder.KafkaAttributes | ||
import io.gatling.core.action.Action | ||
import io.gatling.core.action.builder.ActionBuilder | ||
import io.gatling.core.config.Protocols | ||
import io.gatling.core.structure.ScenarioContext | ||
import org.apache.kafka.clients.producer.KafkaProducer | ||
|
||
import scala.collection.JavaConverters._ | ||
|
||
class KafkaRequestActionBuilder[K,V](kafkaAttributes: KafkaAttributes[K,V]) | ||
extends ActionBuilder { | ||
|
||
override def registerDefaultProtocols(protocols: Protocols): Protocols = | ||
protocols + KafkaProtocol.DefaultKafkaProtocol | ||
class KafkaRequestActionBuilder[K,V](kafkaAttributes: KafkaAttributes[K,V]) extends ActionBuilder { | ||
|
||
override def build( ctx: ScenarioContext, next: Action ): Action = { | ||
import ctx.{protocolComponentsRegistry, system, coreComponents} | ||
|
||
val kafkaComponents: KafkaComponents = protocolComponentsRegistry.components(KafkaProtocol.KafkaProtocolKey) | ||
|
||
val producer = new KafkaProducer[K,V]( kafkaComponents.kafkaProtocol.properties.asJava ) | ||
|
||
system.registerOnTermination(producer.close()) | ||
|
||
new KafkaRequestAction( | ||
producer, | ||
kafkaAttributes, | ||
coreComponents, | ||
kafkaComponents.kafkaProtocol, | ||
next | ||
) | ||
|
||
def build(next: ActorRef, protocols: Protocols): ActorRef = { | ||
val kafkaProtocol = protocols.getProtocol[KafkaProtocol].getOrElse( | ||
throw new UnsupportedOperationException("Kafka Protocol wasn't registered")) | ||
val producer = new KafkaProducer[K,V]( | ||
kafkaProtocol.properties.asJava) | ||
actor(actorName("kafkaRequest"))(new KafkaRequestAction( | ||
producer, kafkaAttributes, kafkaProtocol, next)) | ||
} | ||
|
||
} |
17 changes: 0 additions & 17 deletions
17
src/main/scala/com/github/mnogu/gatling/kafka/config/KafkaProtocol.scala
This file was deleted.
Oops, something went wrong.
13 changes: 13 additions & 0 deletions
13
src/main/scala/com/github/mnogu/gatling/kafka/protocol/KafkaComponents.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,13 @@ | ||
package com.github.mnogu.gatling.kafka.protocol | ||
|
||
import io.gatling.core.protocol.ProtocolComponents | ||
import io.gatling.core.session.Session | ||
|
||
|
||
case class KafkaComponents(kafkaProtocol: KafkaProtocol) extends ProtocolComponents { | ||
|
||
override def onStart: Option[(Session) => Session] = None | ||
|
||
override def onExit: Option[(Session) => Unit] = None | ||
|
||
} |
43 changes: 43 additions & 0 deletions
43
src/main/scala/com/github/mnogu/gatling/kafka/protocol/KafkaProtocol.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
package com.github.mnogu.gatling.kafka.protocol | ||
|
||
import akka.actor.ActorSystem | ||
import io.gatling.core.CoreComponents | ||
import io.gatling.core.config.GatlingConfiguration | ||
import io.gatling.core.protocol.{Protocol, ProtocolKey} | ||
|
||
object KafkaProtocol { | ||
|
||
def apply(configuration: GatlingConfiguration): KafkaProtocol = KafkaProtocol ( | ||
topic = "", | ||
properties = Map() | ||
) | ||
|
||
val KafkaProtocolKey = new ProtocolKey { | ||
|
||
type Protocol = KafkaProtocol | ||
type Components = KafkaComponents | ||
|
||
def protocolClass: Class[io.gatling.core.protocol.Protocol] = classOf[KafkaProtocol].asInstanceOf[Class[io.gatling.core.protocol.Protocol]] | ||
|
||
def defaultProtocolValue(configuration: GatlingConfiguration): KafkaProtocol = KafkaProtocol(configuration) | ||
|
||
def newComponents(system: ActorSystem, coreComponents: CoreComponents): KafkaProtocol => KafkaComponents = { | ||
|
||
kafkaProtocol => { | ||
val kafkaComponents = KafkaComponents ( | ||
kafkaProtocol | ||
) | ||
|
||
kafkaComponents | ||
} | ||
} | ||
} | ||
} | ||
|
||
case class KafkaProtocol( | ||
topic: String, | ||
properties: Map[String, Object]) extends Protocol { | ||
|
||
def topic(topic: String): KafkaProtocol = copy(topic = topic) | ||
def properties(properties: Map[String, Object]): KafkaProtocol = copy(properties = properties) | ||
} |
20 changes: 20 additions & 0 deletions
20
src/main/scala/com/github/mnogu/gatling/kafka/protocol/KafkaProtocolBuilder.scala
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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,20 @@ | ||
package com.github.mnogu.gatling.kafka.protocol | ||
|
||
import io.gatling.core.config.GatlingConfiguration | ||
|
||
|
||
object KafkaProtocolBuilder { | ||
|
||
implicit def toKafkaProtocol(builder: KafkaProtocolBuilder): KafkaProtocol = builder.build | ||
|
||
def apply(configuration: GatlingConfiguration) : KafkaProtocolBuilder = | ||
KafkaProtocolBuilder(KafkaProtocol(configuration)) | ||
|
||
} | ||
|
||
|
||
case class KafkaProtocolBuilder(kafkaProtocol: KafkaProtocol) { | ||
|
||
def build = kafkaProtocol | ||
|
||
} |
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