-
Notifications
You must be signed in to change notification settings - Fork 25
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* fix: simulation examples now work * fix: message with null may not be tracked * feat: kafka tests * feat: CI config * feat: CI config * feat: CI config * feat: CI config * feat: CI config * fix: topic test.t everywhere * feat: readme test badge * feat: readme badge * fix: fix dependencies and add assertion * fix: scala fmt * fix: separate provided and test dependencies --------- Co-authored-by: a.ugodnikov <[email protected]>
- Loading branch information
Showing
9 changed files
with
269 additions
and
46 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
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -11,6 +11,39 @@ jobs: | |
test: | ||
name: Test Release | ||
runs-on: ubuntu-20.04 | ||
services: | ||
zookeeper: | ||
image: wurstmeister/zookeeper | ||
env: | ||
ZOO_MY_ID: "1" | ||
ZOO_PORT: "2181" | ||
ZOO_SERVERS: server.1=zoo1:2888:3888 | ||
ports: | ||
- '2181:2181' | ||
kafka: | ||
image: wurstmeister/kafka:2.13-2.6.3 | ||
env: | ||
KAFKA_ZOOKEEPER_CONNECT: zookeeper:2181 | ||
KAFKA_ADVERTISED_HOST_NAME: kafka | ||
KAFKA_LISTENERS: BROKER://:9092,EXTERNAL://:9093 | ||
KAFKA_ADVERTISED_LISTENERS: BROKER://kafka:9092,EXTERNAL://localhost:9093 | ||
KAFKA_LISTENER_SECURITY_PROTOCOL_MAP: BROKER:PLAINTEXT,EXTERNAL:PLAINTEXT | ||
KAFKA_INTER_BROKER_LISTENER_NAME: BROKER | ||
KAFKA_BROKER_ID: "1" | ||
KAFKA_OFFSETS_TOPIC_REPLICATION_FACTOR: "1" | ||
KAFKA_CREATE_TOPICS: "myTopic:1:1, test.t:1:1" | ||
ports: | ||
- '9092:9092' | ||
- '9093:9093' | ||
schema-registry: | ||
image: confluentinc/cp-schema-registry:7.2.1 | ||
env: | ||
SCHEMA_REGISTRY_HOST_NAME: schema-registry | ||
SCHEMA_REGISTRY_KAFKASTORE_BOOTSTRAP_SERVERS: 'kafka:9092,localhost:9093' | ||
SCHEMA_REGISTRY_LISTENERS: http://0.0.0.0:9094 | ||
ports: | ||
- '9094:9094' | ||
|
||
steps: | ||
- name: Checkout | ||
uses: actions/[email protected] | ||
|
@@ -24,6 +57,12 @@ jobs: | |
|
||
- name: Test Release | ||
run: sbt clean scalafmtCheckAll scalafmtSbtCheck compile test | ||
|
||
- name: Tests | ||
run: sbt coverage "Gatling / testOnly ru.tinkoff.gatling.kafka.examples.KafkaGatlingTest" coverageReport | ||
|
||
- name: Upload coverage reports to Codecov | ||
uses: codecov/codecov-action@v3 | ||
|
||
publish: | ||
name: Publish Release | ||
|
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
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
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
178 changes: 178 additions & 0 deletions
178
src/test/scala/ru/tinkoff/gatling/kafka/examples/KafkaGatlingTest.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,178 @@ | ||
package ru.tinkoff.gatling.kafka.examples | ||
|
||
import com.sksamuel.avro4s._ | ||
import io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient | ||
import io.confluent.kafka.serializers.{KafkaAvroDeserializer, KafkaAvroSerializer} | ||
import io.gatling.core.Predef._ | ||
import io.gatling.core.structure.ScenarioBuilder | ||
import org.apache.kafka.clients.producer.ProducerConfig | ||
import ru.tinkoff.gatling.kafka.Predef._ | ||
import ru.tinkoff.gatling.kafka.protocol.KafkaProtocol | ||
import org.apache.kafka.common.header.Headers | ||
import org.apache.kafka.common.header.internals.RecordHeaders | ||
import org.apache.kafka.common.serialization.{Deserializer, Serde, Serializer} | ||
import ru.tinkoff.gatling.kafka.request.KafkaProtocolMessage | ||
|
||
import scala.concurrent.duration.DurationInt | ||
|
||
class KafkaGatlingTest extends Simulation { | ||
|
||
case class Ingredient(name: String, sugar: Double, fat: Double) | ||
|
||
implicit val ingridientToRecord: ToRecord[Ingredient] = ToRecord.apply | ||
implicit val ingridientFromRecord: FromRecord[Ingredient] = FromRecord.apply | ||
implicit val ingridientSchemaFor: SchemaFor[Ingredient] = SchemaFor.apply | ||
implicit val ingridientFormat: RecordFormat[Ingredient] = RecordFormat.apply | ||
implicit val ingredientHeaders: Headers = new RecordHeaders() | ||
|
||
val kafkaConf: KafkaProtocol = kafka | ||
.topic("test.t") | ||
.properties( | ||
Map( | ||
ProducerConfig.ACKS_CONFIG -> "1", | ||
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG -> "localhost:9093", | ||
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG -> "org.apache.kafka.common.serialization.StringSerializer", | ||
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG -> "org.apache.kafka.common.serialization.StringSerializer", | ||
), | ||
) | ||
|
||
val kafkaConfBytes: KafkaProtocol = kafka | ||
.topic("test.t") | ||
.properties( | ||
Map( | ||
ProducerConfig.ACKS_CONFIG -> "1", | ||
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG -> "localhost:9093", | ||
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG -> "org.apache.kafka.common.serialization.ByteArraySerializer", | ||
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG -> "org.apache.kafka.common.serialization.ByteArraySerializer", | ||
), | ||
) | ||
|
||
val kafkaProtocolRRString: KafkaProtocol = kafka.requestReply | ||
.producerSettings( | ||
Map( | ||
ProducerConfig.ACKS_CONFIG -> "1", | ||
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG -> "localhost:9093", | ||
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG -> "org.apache.kafka.common.serialization.StringSerializer", | ||
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG -> "org.apache.kafka.common.serialization.StringSerializer", | ||
), | ||
) | ||
.consumeSettings( | ||
Map( | ||
"bootstrap.servers" -> "localhost:9093", | ||
), | ||
) | ||
.withDefaultTimeout | ||
|
||
val kafkaProtocolRRBytes: KafkaProtocol = kafka.requestReply | ||
.producerSettings( | ||
Map( | ||
ProducerConfig.ACKS_CONFIG -> "1", | ||
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG -> "localhost:9093", | ||
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG -> "org.apache.kafka.common.serialization.ByteArraySerializer", | ||
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG -> "org.apache.kafka.common.serialization.ByteArraySerializer", | ||
), | ||
) | ||
.consumeSettings( | ||
Map( | ||
"bootstrap.servers" -> "localhost:9093", | ||
), | ||
) | ||
.timeout(5.seconds) | ||
.matchByValue | ||
|
||
val kafkaAvro4sConf: KafkaProtocol = kafka | ||
.topic("test.t") | ||
.properties( | ||
Map( | ||
ProducerConfig.ACKS_CONFIG -> "1", | ||
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG -> "localhost:9093", | ||
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG -> "org.apache.kafka.common.serialization.StringSerializer", | ||
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG -> "io.confluent.kafka.serializers.KafkaAvroSerializer", | ||
"value.subject.name.strategy" -> "io.confluent.kafka.serializers.subject.RecordNameStrategy", | ||
"schema.registry.url" -> "http://localhost:9094", | ||
), | ||
) | ||
|
||
def matchByOwnVal(message: KafkaProtocolMessage): Array[Byte] = { | ||
message.key | ||
} | ||
|
||
val kafkaProtocolRRAvro: KafkaProtocol = kafka.requestReply | ||
.producerSettings( | ||
Map( | ||
ProducerConfig.ACKS_CONFIG -> "1", | ||
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG -> "localhost:9093", | ||
ProducerConfig.KEY_SERIALIZER_CLASS_CONFIG -> "org.apache.kafka.common.serialization.StringSerializer", | ||
ProducerConfig.VALUE_SERIALIZER_CLASS_CONFIG -> "io.confluent.kafka.serializers.KafkaAvroSerializer", | ||
"value.subject.name.strategy" -> "io.confluent.kafka.serializers.subject.RecordNameStrategy", | ||
"schema.registry.url" -> "http://localhost:9094", | ||
), | ||
) | ||
.consumeSettings( | ||
Map( | ||
"bootstrap.servers" -> "localhost:9093", | ||
), | ||
) | ||
.timeout(5.seconds) | ||
.matchByMessage(matchByOwnVal) | ||
|
||
val scnRR: ScenarioBuilder = scenario("RequestReply String") | ||
.exec( | ||
kafka("Request Reply String").requestReply | ||
.requestTopic("myTopic") | ||
.replyTopic("test.t") | ||
.send[String, String]("testCheckJson", """{ "m": "dkf" }""") | ||
.check(jsonPath("$.m").is("dkf")), | ||
) | ||
|
||
val scn: ScenarioBuilder = scenario("Request String") | ||
.exec( | ||
kafka("Request String") | ||
.send[String]("foo"), | ||
) | ||
.exec(kafka("Request String 2").send[String, String]("testCheckJson", """{ "m": "dkf" }""")) | ||
|
||
val scn2: ScenarioBuilder = scenario("Request Byte") | ||
.exec( | ||
kafka("Request Byte") | ||
.send[Array[Byte], Array[Byte]]("key".getBytes(), "tstBytes".getBytes()), | ||
) | ||
|
||
val scnRR2: ScenarioBuilder = scenario("RequestReply Bytes") | ||
.exec( | ||
kafka("Request Reply Bytes").requestReply | ||
.requestTopic("myTopic") | ||
.replyTopic("test.t") | ||
.send[Array[Byte], Array[Byte]]("test".getBytes(), "tstBytes".getBytes()), | ||
) | ||
|
||
val scnAvro4s: ScenarioBuilder = scenario("Request Avro4s") | ||
.exec( | ||
kafka("Request Simple Avro4s") | ||
.send(Ingredient("Cheese", 1d, 50d)), | ||
) | ||
.exec( | ||
kafka("Request Avro4s") | ||
.send[String, Ingredient]("key4s", Ingredient("Cheese", 0d, 70d)), | ||
) | ||
|
||
val scnRRwo: ScenarioBuilder = scenario("RequestReply w/o answer") | ||
.exec( | ||
kafka("Request Reply Bytes").requestReply | ||
.requestTopic("myTopic") | ||
.replyTopic("test.t") | ||
.send[Array[Byte], Array[Byte]]("testWO".getBytes(), "tstBytesWO".getBytes()), | ||
) | ||
|
||
setUp( | ||
scnRR.inject(atOnceUsers(1)).protocols(kafkaProtocolRRString), | ||
scn.inject(nothingFor(1), atOnceUsers(1)).protocols(kafkaConf), | ||
scnRR2.inject(atOnceUsers(1)).protocols(kafkaProtocolRRBytes), | ||
scn2.inject(nothingFor(1), atOnceUsers(1)).protocols(kafkaConfBytes), | ||
scnAvro4s.inject(atOnceUsers(1)).protocols(kafkaAvro4sConf), | ||
scnRRwo.inject(atOnceUsers(1)).protocols(kafkaProtocolRRBytes), | ||
).assertions( | ||
global.failedRequests.percent.lt(15.0), | ||
) | ||
|
||
} |
Oops, something went wrong.