Skip to content

Commit

Permalink
Sørg for at testene funker på M1 mac
Browse files Browse the repository at this point in the history
  • Loading branch information
androa committed Apr 12, 2022
1 parent fb11e98 commit 26d835e
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 20 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import com.zaxxer.hikari.HikariDataSource
import no.nav.dagpenger.inntekt.db.clean
import no.nav.dagpenger.inntekt.db.migrate
import org.testcontainers.containers.PostgreSQLContainer
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy

fun withCleanDb(test: () -> Unit) = DataSource.instance.also { clean(it) }.run { test() }

Expand All @@ -13,6 +14,7 @@ fun withMigratedDb(test: () -> Unit) =
object PostgresContainer {
val instance by lazy {
PostgreSQLContainer<Nothing>("postgres:11.2").apply {
this.waitingFor(HostPortWaitStrategy())
start()
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import org.apache.kafka.clients.producer.ProducerRecord
import org.apache.kafka.common.serialization.StringSerializer
import org.junit.jupiter.api.Test
import org.testcontainers.containers.KafkaContainer
import org.testcontainers.containers.wait.strategy.HostPortWaitStrategy
import org.testcontainers.utility.DockerImageName
import java.sql.SQLTransientConnectionException
import java.time.Duration
Expand All @@ -28,14 +29,18 @@ import java.time.ZonedDateTime
import java.util.concurrent.TimeUnit

private val LOGGER = KotlinLogging.logger { }

internal class KafkaSubsumsjonBruktDataConsumerTest {
private object Kafka {
val instance by lazy {
KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka").withTag("5.3.1")).apply { this.start() }
KafkaContainer(DockerImageName.parse("confluentinc/cp-kafka").withTag("5.3.1")).apply {
this.waitingFor(HostPortWaitStrategy())
this.start()
}
}
}
val inntektId = InntektId(ULID().nextULID())

val inntektId = InntektId(ULID().nextULID())
private val bruktInntektMelding = mapOf(
"@event_name" to "brukt_inntekt",
"inntektsId" to inntektId.id,
Expand All @@ -53,7 +58,6 @@ internal class KafkaSubsumsjonBruktDataConsumerTest {
"type" to "vedtak"
)
)

private val producer by lazy {
KafkaProducer<String, String>(
producerConfig(
Expand All @@ -66,6 +70,7 @@ internal class KafkaSubsumsjonBruktDataConsumerTest {
)
}
private val adapter = moshiInstance.adapter<Map<String, Any?>>(Map::class.java).lenient()

@Test
fun `Should mark inntekt id as used`() {
runBlocking {
Expand All @@ -74,16 +79,15 @@ internal class KafkaSubsumsjonBruktDataConsumerTest {
val config = Config.config.inntektApiConfig.run {
copy(application = application.copy(brokers = Kafka.instance.bootstrapServers, credential = null))
}

val consumer = KafkaSubsumsjonBruktDataConsumer(config, storeMock).apply {
listen()
}

val metaData = producer.send(ProducerRecord(config.inntektBruktDataTopic, "test", adapter.toJson(bruktInntektMelding)))
.get(5, TimeUnit.SECONDS)
val metaData =
producer.send(ProducerRecord(config.inntektBruktDataTopic, "test", adapter.toJson(bruktInntektMelding)))
.get(5, TimeUnit.SECONDS)
LOGGER.info("Producer produced $bruktInntektMelding with meta $metaData")

TimeUnit.MILLISECONDS.sleep(500)
TimeUnit.MILLISECONDS.sleep(800)

verify(exactly = 1) {
storeMock.markerInntektBrukt(inntektId)
Expand All @@ -100,14 +104,17 @@ internal class KafkaSubsumsjonBruktDataConsumerTest {
val config = Config.config.inntektApiConfig.run {
copy(application = application.copy(brokers = Kafka.instance.bootstrapServers, credential = null))
}

val consumer = KafkaSubsumsjonBruktDataConsumer(config, storeMock).apply {
listen()
}

val bruktSubsumsjonData = mapOf("faktum" to mapOf("manueltGrunnlag" to "122212"))

val metaData = producer.send(ProducerRecord(config.inntektBruktDataTopic, "test", adapter.toJson(bruktInntektMeldingManueltGrunnlag)))
val metaData = producer.send(
ProducerRecord(
config.inntektBruktDataTopic,
"test",
adapter.toJson(bruktInntektMeldingManueltGrunnlag)
)
)
.get(5, TimeUnit.SECONDS)
LOGGER.info("Producer produced $bruktSubsumsjonData with meta $metaData")

Expand All @@ -131,13 +138,16 @@ internal class KafkaSubsumsjonBruktDataConsumerTest {
val config = Config.config.inntektApiConfig.run {
copy(application = application.copy(brokers = Kafka.instance.bootstrapServers, credential = null))
}

val consumer = KafkaSubsumsjonBruktDataConsumer(config = config, inntektStore = storeMock, graceDuration = Duration.ofMillis(1)).apply {
val consumer = KafkaSubsumsjonBruktDataConsumer(
config = config,
inntektStore = storeMock,
graceDuration = Duration.ofMillis(1)
).apply {
listen()
}

val metaData = producer.send(ProducerRecord(config.inntektBruktDataTopic, "test", adapter.toJson(bruktInntektMelding)))
.get(5, TimeUnit.SECONDS)
val metaData =
producer.send(ProducerRecord(config.inntektBruktDataTopic, "test", adapter.toJson(bruktInntektMelding)))
.get(5, TimeUnit.SECONDS)
LOGGER.info("Producer produced $bruktInntektMelding with meta $metaData + should fail")

TimeUnit.MILLISECONDS.sleep(1500)
Expand All @@ -148,9 +158,11 @@ internal class KafkaSubsumsjonBruktDataConsumerTest {

@Test
fun `Grace period is over`() {
val graceperiod1 = KafkaSubsumsjonBruktDataConsumer.Grace(from = ZonedDateTime.now(ZoneOffset.UTC).minusHours(1))
val graceperiod1 =
KafkaSubsumsjonBruktDataConsumer.Grace(from = ZonedDateTime.now(ZoneOffset.UTC).minusHours(1))
graceperiod1.expired() shouldBe false
val graceperiod2 = KafkaSubsumsjonBruktDataConsumer.Grace(from = ZonedDateTime.now(ZoneOffset.UTC).minusHours(4))
val graceperiod2 =
KafkaSubsumsjonBruktDataConsumer.Grace(from = ZonedDateTime.now(ZoneOffset.UTC).minusHours(4))
graceperiod2.expired() shouldBe true
}
}
2 changes: 1 addition & 1 deletion dp-inntekt-grpc/build.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import com.google.protobuf.gradle.* // ktlint-disable no-wildcard-imports

val grpcVersion = "1.38.1"
val grpcVersion = "1.43.0"
val grpcKotlinVersion = "1.1.0"
val protbufVersion = "3.17.3"
val protobufGradleVersion = "0.8.16"
Expand Down

0 comments on commit 26d835e

Please sign in to comment.