-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathMatchSimulation.kt
79 lines (69 loc) · 2.58 KB
/
MatchSimulation.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
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
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 ru.tinkoff.gatling.kafka.javaapi.*
import ru.tinkoff.gatling.kafka.javaapi.KafkaDsl.*
import ru.tinkoff.gatling.kafka.request.*
import java.time.Duration
import java.util.concurrent.atomic.AtomicInteger
class MatchSimulation : Simulation() {
private val kafkaProtocolMatchByValue = 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)) // for match by message value
.matchByValue()
private fun matchByOwnVal(message: KafkaProtocolMessage): ByteArray {
// do something with the message and extract the values you are interested in
// method is called:
// - for each message which will be sent out
// - for each message which has been received
return "Custom Message".toByteArray() // just returning something
}
private val kafkaProtocolMatchByMessage = 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))
.matchByMessage { message: KafkaProtocolMessage -> matchByOwnVal(message) }
private val c = AtomicInteger(0)
private val feeder = generateSequence {
mapOf("kekey" to c.incrementAndGet())
}.iterator()
private val scn = scenario("Basic")
.feed(feeder)
.exec(
KafkaDsl.kafka("ReqRep").requestReply()
.requestTopic("test.t")
.replyTopic("test.t")
.send<String, String>(
"#{kekey}",
"""{ "m": "dkf" }""",
String::class.java,
String::class.java
)
)
init
{
setUp(
scn.injectOpen(atOnceUsers(1))
)
.protocols(kafkaProtocolMatchByMessage)
.maxDuration(Duration.ofSeconds(120))
}
}