Skip to content

Commit

Permalink
la på reset av pdl-cache før testmetoder
Browse files Browse the repository at this point in the history
  • Loading branch information
jankroken-nav committed Oct 24, 2024
1 parent c685a1c commit c94fd15
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 37 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,10 +26,14 @@ class PersonIdService(
personId
}

else -> { // noop, but added to make this compile
throw RuntimeException("cache contains unrecognized value $personId")
else -> { // har ingen funksjon, men la til for at det skal kompilere
throw RuntimeException("cache inneholder ukjent verdi $personId")
}
}
}

fun clearCache() {
cache.invalidateAll()
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.domene.kafka.Topics
import no.nav.pensjon.opptjening.omsorgsopptjening.felles.serialize
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.Application
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.domain.PersonIdService
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.kafka.BarnetrygdmottakerKafkaMelding
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.barnetrygd.kafka.BarnetrygdmottakerKafkaTopic
import no.nav.pensjon.opptjening.omsorgsopptjening.start.innlesning.config.KafkaIntegrationTestConfig
Expand Down Expand Up @@ -30,9 +31,13 @@ sealed class SpringContextTest {
const val READINESS_TOPIC = "readiness-topic"
}

@Autowired
private lateinit var personIdService: PersonIdService

@BeforeEach
fun setup() {
PostgresqlTestContainer.instance.removeDataFromDB()
personIdService.clearCache()
resetHjelpestønadSequence()
}

Expand All @@ -56,41 +61,6 @@ sealed class SpringContextTest {
@Autowired
lateinit var kafkaProducer: KafkaTemplate<String, String>

@Autowired
lateinit var kafkaBroker: EmbeddedKafkaBroker

fun ensureKafkaIsReady() {
Thread.sleep(1000)
val future = kafkaProducer.send(READINESS_TOPIC, "key", "msg")
kafkaProducer.flush()
future.get(10, TimeUnit.SECONDS)
println("READINESS_TOPIC.length = ${READINESS_TOPIC.length}")
println("KAFKA BROKER: $kafkaBroker")
}

fun awaitKafkaBroker(timeoutSeconds: Int = 60) {
var attempts = 0
val maxAttempts = timeoutSeconds * 10
val brokerAddress = kafkaBroker.brokersAsString
println("BrokerAddress: $brokerAddress")
val host = brokerAddress.split(":").first()
val port = brokerAddress.substringAfter(":").toInt()

while (attempts < maxAttempts) {
try {
Socket("localhost", port).use {
println("awaitKafkaBroker: Kafka is ready (attempts=$attempts)")
return
}
} catch (e: Exception) {
Thread.sleep(100)
}
attempts++
}
throw RuntimeException("awaitKafkaBroker: Kafka broker did not start without $timeoutSeconds seconds")
}


fun sendStartInnlesingKafka(
requestId: String
) {
Expand Down

0 comments on commit c94fd15

Please sign in to comment.