-
Notifications
You must be signed in to change notification settings - Fork 25
/
BasicSimulation.kt
55 lines (46 loc) · 1.78 KB
/
BasicSimulation.kt
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
package ru.tinkoff.gatling.kafka.javaapi.examples
import io.gatling.javaapi.core.CoreDsl.*
import io.gatling.javaapi.core.Simulation
import org.apache.kafka.clients.producer.ProducerConfig
import org.apache.kafka.common.header.internals.RecordHeaders
import ru.tinkoff.gatling.kafka.javaapi.KafkaDsl.*
import java.time.Duration
import java.util.concurrent.atomic.AtomicInteger
class BasicSimulation : Simulation() {
private val kafkaConf = kafka()
.topic("test.topic")
.properties(mapOf<String, Any>(ProducerConfig.ACKS_CONFIG to "1"))
private val kafkaProtocolC = kafka().requestReply()
.producerSettings(
mapOf<String, Any>(
ProducerConfig.ACKS_CONFIG to "1",
ProducerConfig.BOOTSTRAP_SERVERS_CONFIG to "localhost:9092",
)
)
.consumeSettings(
mapOf<String, Any>("bootstrap.servers" to "localhost:9092")
).timeout(Duration.ofSeconds(5))
private val c = AtomicInteger(0)
private val feeder = generateSequence {
mapOf("kekey" to c.incrementAndGet())
}.iterator()
private val headers = RecordHeaders().add("test-header", "test_value".toByteArray())
private val scn = scenario("Basic")
.feed(feeder)
.exec(
kafka("ReqRep").requestReply()
.requestTopic("test.t")
.replyTopic("test.t")
.send(
"#{kekey}",
"""{ "m": "dkf" }""",
headers,
String::class.java,
String::class.java
)
.check(jsonPath("$.m").`is`("dkf"))
)
init {
setUp(scn.injectOpen(atOnceUsers(5))).protocols(kafkaProtocolC).maxDuration(Duration.ofSeconds(120))
}
}