From c94fd1513157854c1f4f875ae697810c567d5c59 Mon Sep 17 00:00:00 2001 From: Jan Kroken Date: Thu, 24 Oct 2024 14:26:59 +0200 Subject: [PATCH] =?UTF-8?q?la=20p=C3=A5=20reset=20av=20pdl-cache=20f=C3=B8?= =?UTF-8?q?r=20testmetoder?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../barnetrygd/domain/PersonIdService.kt | 8 +++- .../barnetrygd/SpringContextTest.kt | 40 +++---------------- 2 files changed, 11 insertions(+), 37 deletions(-) diff --git a/src/main/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/domain/PersonIdService.kt b/src/main/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/domain/PersonIdService.kt index 21b5f11d..91252743 100644 --- a/src/main/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/domain/PersonIdService.kt +++ b/src/main/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/domain/PersonIdService.kt @@ -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() + } + } \ No newline at end of file diff --git a/src/test/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/SpringContextTest.kt b/src/test/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/SpringContextTest.kt index 9c5ae541..05b0957a 100644 --- a/src/test/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/SpringContextTest.kt +++ b/src/test/kotlin/no/nav/pensjon/opptjening/omsorgsopptjening/start/innlesning/barnetrygd/SpringContextTest.kt @@ -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 @@ -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() } @@ -56,41 +61,6 @@ sealed class SpringContextTest { @Autowired lateinit var kafkaProducer: KafkaTemplate - @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 ) {