File tree 3 files changed +37
-2
lines changed
src/test/kotlin/no/nav/emottak/utils/kafka
3 files changed +37
-2
lines changed Original file line number Diff line number Diff line change @@ -34,6 +34,9 @@ publishing {
34
34
35
35
dependencies {
36
36
testImplementation(kotlin(" test" ))
37
+ testImplementation(" org.testcontainers:kafka:1.19.0" )
38
+ testImplementation(" org.junit.jupiter:junit-jupiter-api:5.4.0" )
39
+ testImplementation(" org.junit.jupiter:junit-jupiter-engine:5.4.0" )
37
40
implementation(" org.jetbrains.kotlinx:kotlinx-serialization-json:1.8.0" )
38
41
implementation(" io.github.nomisrev:kotlin-kafka:0.4.1" )
39
42
implementation(" com.sksamuel.hoplite:hoplite-core:2.8.2" )
Original file line number Diff line number Diff line change 1
- package no.nav.emottak.ebms.async .kafka
1
+ package no.nav.emottak.utils .kafka
2
2
3
3
import com.sksamuel.hoplite.Masked
4
4
import kotlinx.coroutines.runBlocking
@@ -11,7 +11,6 @@ import no.nav.emottak.utils.config.TruststoreLocation
11
11
import no.nav.emottak.utils.config.TruststoreType
12
12
import no.nav.emottak.utils.events.model.Event
13
13
import no.nav.emottak.utils.events.model.EventType
14
- import no.nav.emottak.utils.kafka.KafkaPublisherClient
15
14
import org.apache.kafka.clients.consumer.ConsumerConfig
16
15
import org.apache.kafka.clients.consumer.ConsumerRecord
17
16
import org.apache.kafka.clients.consumer.KafkaConsumer
Original file line number Diff line number Diff line change
1
+ package no.nav.emottak.utils.kafka
2
+
3
+ import org.apache.kafka.clients.admin.AdminClient
4
+ import org.apache.kafka.clients.admin.AdminClientConfig
5
+ import org.apache.kafka.clients.admin.NewTopic
6
+ import org.testcontainers.containers.KafkaContainer
7
+ import org.testcontainers.utility.DockerImageName
8
+
9
+ object KafkaTestContainer {
10
+ private val kafkaContainer: KafkaContainer = KafkaContainer (DockerImageName .parse(" confluentinc/cp-kafka:7.5.0" ))
11
+
12
+ val bootstrapServers: String
13
+ get() = kafkaContainer.bootstrapServers
14
+
15
+ fun start () {
16
+ kafkaContainer.start()
17
+ }
18
+
19
+ fun stop () {
20
+ kafkaContainer.stop()
21
+ }
22
+
23
+ fun createTopic (topicName : String , partitions : Int = 1, replicationFactor : Short = 1) {
24
+ val config = mapOf (
25
+ AdminClientConfig .BOOTSTRAP_SERVERS_CONFIG to bootstrapServers
26
+ )
27
+
28
+ AdminClient .create(config).use { adminClient ->
29
+ val newTopic = NewTopic (topicName, partitions, replicationFactor)
30
+ adminClient.createTopics(listOf (newTopic)).all().get()
31
+ }
32
+ }
33
+ }
You can’t perform that action at this time.
0 commit comments