Skip to content

Commit d66ffbc

Browse files
authored
Task/update dependencies second try (#111)
* Oppdatere 3.parts biblioteker * BUG: Using blocking primitives on this dispatcher is not allowed. Consider using async channel instead or use blocking primitives in withContext(Dispatchers.IO) instead. Ser ut til at vi treffer samme bug som i https://youtrack.jetbrains.com/issue/KTOR-1286 Workaround: Pakke call.receive inn i coroutine IO kontekst
1 parent 6898362 commit d66ffbc

File tree

18 files changed

+214
-183
lines changed

18 files changed

+214
-183
lines changed

buildSrc/src/main/kotlin/Constants.kt

Lines changed: 19 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ object Cucumber {
2424
object Dagpenger {
2525

2626
object Biblioteker {
27-
const val version = "2020.07.30-12.21.8857eb1469bf"
27+
const val version = "2020.11.24-08.15.86482b2eead8"
2828
const val stsKlient = "com.github.navikt.dp-biblioteker:sts-klient:$version"
2929
const val grunnbeløp = "com.github.navikt.dp-biblioteker:grunnbelop:$version"
3030
const val ktorUtils = "com.github.navikt.dp-biblioteker:ktor-utils:$version"
@@ -45,8 +45,8 @@ object Dagpenger {
4545
}
4646
}
4747

48-
const val Streams = "com.github.navikt:dagpenger-streams:2020.05.15-23.03.e0ab571caee4"
49-
const val Events = "com.github.navikt:dagpenger-events:2020.05.15-21.57.e4685fc2a371"
48+
const val Streams = "com.github.navikt:dagpenger-streams:2020.08.19-13.32.0fd360f3ef11"
49+
const val Events = "com.github.navikt:dagpenger-events:2020.08.19-10.57.d2fe892352eb"
5050
}
5151

5252
object Database {
@@ -69,18 +69,19 @@ object GradleWrapper {
6969
}
7070

7171
object Jackson {
72-
const val version = "2.10.3"
72+
const val version = "2.12.1"
7373
const val core = "com.fasterxml.jackson.core:jackson-core:$version"
7474
const val kotlin = "com.fasterxml.jackson.module:jackson-module-kotlin:$version"
7575
const val jsr310 = "com.fasterxml.jackson.datatype:jackson-datatype-jsr310:$version"
7676
}
7777

7878
object Junit5 {
79-
const val version = "5.6.1"
79+
const val version = "5.7.1"
8080
const val api = "org.junit.jupiter:junit-jupiter-api:$version"
8181
const val params = "org.junit.jupiter:junit-jupiter-params:$version"
8282
const val engine = "org.junit.jupiter:junit-jupiter-engine:$version"
8383
const val vintageEngine = "org.junit.vintage:junit-vintage-engine:$version"
84+
const val kotlinRunner = "io.kotlintest:kotlintest-runner-junit5:3.4.2"
8485
fun library(name: String) = "org.junit.jupiter:junit-jupiter-$name:$version"
8586
}
8687

@@ -121,22 +122,22 @@ object Konfig {
121122
}
122123

123124
object Kotlin {
124-
const val version = "1.3.72"
125+
const val version = "1.4.30"
125126
const val stdlib = "org.jetbrains.kotlin:kotlin-stdlib:$version"
126127

127128
object Coroutines {
128-
const val version = "1.3.7"
129+
const val version = "1.4.2"
129130
fun module(name: String) = "org.jetbrains.kotlinx:kotlinx-coroutines-$name:$version"
130131
}
131132

132133
object Logging {
133-
const val version = "1.7.9"
134+
const val version = "2.0.4"
134135
const val kotlinLogging = "io.github.microutils:kotlin-logging:$version"
135136
}
136137
}
137138

138139
object KoTest {
139-
const val version = "4.0.3"
140+
const val version = "4.4.1"
140141

141142
// for kotest framework
142143
const val runner = "io.kotest:kotest-runner-junit5-jvm:$version"
@@ -156,7 +157,7 @@ object Kotlinx {
156157
}
157158

158159
object Ktor {
159-
const val version = "1.3.2"
160+
const val version = "1.5.1"
160161
const val server = "io.ktor:ktor-server:$version"
161162
const val serverNetty = "io.ktor:ktor-server-netty:$version"
162163
const val auth = "io.ktor:ktor-auth:$version"
@@ -168,15 +169,15 @@ object Ktor {
168169
}
169170

170171
object Log4j2 {
171-
const val version = "2.13.1"
172+
const val version = "2.14.0"
172173
const val api = "org.apache.logging.log4j:log4j-api:$version"
173174
const val core = "org.apache.logging.log4j:log4j-core:$version"
174175
const val slf4j = "org.apache.logging.log4j:log4j-slf4j-impl:$version"
175176

176177
fun library(name: String) = "org.apache.logging.log4j:log4j-$name:$version"
177178

178179
object Logstash {
179-
private const val version = "1.0.2"
180+
private const val version = "1.0.5"
180181
const val logstashLayout = "com.vlkan.log4j2:log4j2-logstash-layout:$version"
181182
}
182183
}
@@ -198,7 +199,7 @@ object Moshi {
198199
}
199200

200201
object Mockk {
201-
const val version = "1.10.0"
202+
const val version = "1.10.6"
202203
const val mockk = "io.mockk:mockk:$version"
203204
}
204205

@@ -220,19 +221,19 @@ object Prometheus {
220221
}
221222
}
222223

223-
const val RapidAndRivers = "com.github.navikt:rapids-and-rivers:1.74ae9cb"
224+
const val RapidAndRivers = "com.github.navikt:rapids-and-rivers:1.6d6256d"
224225

225226
object Slf4j {
226227
const val version = "1.7.25"
227228
const val api = "org.slf4j:slf4j-api:$version"
228229
}
229230

230231
object Ktlint {
231-
const val version = "0.37.2"
232+
const val version = "0.38.1"
232233
}
233234

234235
object Spotless {
235-
const val version = "5.1.0"
236+
const val version = "5.10.1"
236237
const val spotless = "com.diffplug.spotless"
237238
}
238239

@@ -257,12 +258,12 @@ object Vault {
257258
}
258259

259260
object Wiremock {
260-
const val version = "2.21.0"
261+
const val version = "2.27.2"
261262
const val standalone = "com.github.tomakehurst:wiremock-standalone:$version"
262263
}
263264

264265
object Graphql {
265-
const val version = "3.1.1"
266+
const val version = "4.0.0-alpha.12"
266267
const val graphql = "com.expediagroup.graphql"
267268
val client = library("client")
268269
fun library(name: String) = "com.expediagroup:graphql-kotlin-$name:$version"

dp-inntekt-api/build.gradle.kts

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ buildscript {
1212
}
1313

1414
repositories {
15+
mavenCentral()
1516
maven("https://packages.confluent.io/maven/")
1617
}
1718

@@ -20,7 +21,7 @@ application {
2021
mainClassName = "no.nav.dagpenger.inntekt.ApplicationKt"
2122
}
2223

23-
val grpcVersion = "1.29.0"
24+
val grpcVersion = "1.35.0"
2425

2526
dependencies {
2627
implementation(project(":dp-inntekt-grpc"))
@@ -36,6 +37,7 @@ dependencies {
3637
implementation(Micrometer.prometheusRegistry)
3738

3839
implementation(Graphql.client)
40+
implementation(Graphql.library("ktor-client"))
3941
implementation(Ktor.library("client-logging-jvm"))
4042
implementation(Ktor.library("client-apache"))
4143

@@ -90,10 +92,10 @@ dependencies {
9092

9193
testImplementation(kotlin("test"))
9294
testImplementation(Ktor.ktorTest)
95+
testImplementation(Ktor.library("client-mock"))
9396
testImplementation(Junit5.api)
9497
testImplementation(Junit5.params)
9598
testRuntimeOnly(Junit5.engine)
96-
testRuntimeOnly(Junit5.vintageEngine)
9799
testImplementation(Wiremock.standalone)
98100
testImplementation(KoTest.assertions)
99101
testImplementation(KoTest.runner)

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/Application.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ fun main() {
5050
val pdlPersonOppslag = PdlGraphQLRepository(
5151
client = PdlGraphQLClientFactory(
5252
url = config.pdl.url,
53-
oidcProvider = { stsOidcClient.oidcToken().access_token }
53+
oidcProvider = { runBlocking { stsOidcClient.oidcToken().access_token } }
5454
)
5555
)
5656
val enhetsregisterClient = EnhetsregisterClient(

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/db/PostgresInntektStore.kt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,8 @@ internal class PostgresInntektStore(private val dataSource: DataSource) : Inntek
100100
return using(sessionOf(dataSource)) { session ->
101101
session.run(
102102
queryOf(
103-
statement, mapOf("inntektId" to inntektId.id)
103+
statement,
104+
mapOf("inntektId" to inntektId.id)
104105
).map { row ->
105106
row.localDateOrNull("beregningsdato")
106107
}.asSingle

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/oppslag/enhetsregister/EnhetsregisterClient.kt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ class EnhetsregisterClient(
2323
suspend fun hentEnhet(orgnummer: String): String {
2424
return withContext(Dispatchers.IO) {
2525
try {
26-
httpClient.get<String>("$baseUrl/api/enheter/$orgnummer")
26+
httpClient.get("$baseUrl/api/enheter/$orgnummer")
2727
} catch (e: ClientRequestException) {
2828
when (e.response.status.value) {
2929
404 -> httpClient.get<String>("$baseUrl/api/underenheter/$orgnummer")

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/oppslag/pdl/PdlGraphQLRepository.kt

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package no.nav.dagpenger.inntekt.oppslag.pdl
22

33
import com.expediagroup.graphql.client.GraphQLClient
4+
import com.expediagroup.graphql.client.ktor.GraphQLKtorClient
45
import com.expediagroup.graphql.types.GraphQLResponse
56
import io.ktor.client.features.defaultRequest
67
import io.ktor.client.features.logging.LogLevel
@@ -21,7 +22,7 @@ private val sikkerlogg = KotlinLogging.logger("tjenestekall")
2122

2223
@KtorExperimentalAPI
2324
class PdlGraphQLRepository constructor(
24-
client: GraphQLClient<*>
25+
client: GraphQLClient
2526
) : PersonOppslag {
2627

2728
private val query = HentPerson(client)
@@ -56,7 +57,7 @@ class PdlGraphQLRepository constructor(
5657
fun PdlGraphQLClientFactory(
5758
url: String,
5859
oidcProvider: () -> String
59-
) = GraphQLClient(url = URL(url)) {
60+
) = GraphQLKtorClient(url = URL(url)) {
6061
install(Logging) {
6162
logger = object : Logger {
6263
override fun log(message: String) = sikkerlogg.info { message }

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/v1/EnhetsregistrerRoute.kt

Lines changed: 15 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -11,23 +11,28 @@ import io.ktor.response.respondText
1111
import io.ktor.routing.Route
1212
import io.ktor.routing.get
1313
import io.ktor.routing.route
14+
import kotlinx.coroutines.Dispatchers
15+
import kotlinx.coroutines.withContext
1416
import no.nav.dagpenger.inntekt.oppslag.enhetsregister.EnhetsregisterClient
1517

1618
private const val CACHE_SECONDS = 86400
1719

1820
fun Route.enhetsregisteret(client: EnhetsregisterClient) {
1921
route("enhetsregisteret") {
2022
get("enhet/{orgnummer}") {
21-
val orgnummer = call.parameters["orgnummer"] ?: throw BadRequestException("Orgnummer ikke spesifisert")
22-
try {
23-
val result = client.hentEnhet(orgnummer)
24-
call.response.cacheControl(CacheControl.MaxAge(CACHE_SECONDS))
25-
call.respondText(result, ContentType.Application.Json)
26-
} catch (e: Exception) {
27-
when (e) {
28-
is ClientRequestException -> when (e.response.status.value) {
29-
in 400..499 -> call.response.status(e.response.status)
30-
} else -> call.response.status(HttpStatusCode.BadGateway)
23+
withContext(Dispatchers.IO) {
24+
val orgnummer = call.parameters["orgnummer"] ?: throw BadRequestException("Orgnummer ikke spesifisert")
25+
try {
26+
val result = client.hentEnhet(orgnummer)
27+
call.response.cacheControl(CacheControl.MaxAge(CACHE_SECONDS))
28+
call.respondText(result, ContentType.Application.Json)
29+
} catch (e: Exception) {
30+
when (e) {
31+
is ClientRequestException -> when (e.response?.status?.value) {
32+
in 400..499 -> call.response.status(e.response!!.status)
33+
}
34+
else -> call.response.status(HttpStatusCode.BadGateway)
35+
}
3136
}
3237
}
3338
}

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/v1/InntektRoute.kt

Lines changed: 25 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,51 +8,48 @@ import io.ktor.response.respond
88
import io.ktor.routing.Route
99
import io.ktor.routing.post
1010
import io.ktor.routing.route
11-
import kotlinx.coroutines.asCoroutineDispatcher
11+
import kotlinx.coroutines.Dispatchers.IO
1212
import kotlinx.coroutines.withContext
1313
import no.nav.dagpenger.inntekt.BehandlingsInntektsGetter
1414
import no.nav.dagpenger.inntekt.db.Inntektparametre
1515
import java.time.LocalDate
16-
import java.util.concurrent.Executors
17-
18-
val api = Executors.newFixedThreadPool(4).asCoroutineDispatcher()
1916

2017
fun Route.inntekt(behandlingsInntektsGetter: BehandlingsInntektsGetter) {
2118
authenticate {
2219
route("spesifisert") {
2320
post {
24-
val request = call.receive<InntektRequestMedFnr>()
25-
26-
val spesifisertInntekt = withContext(api) {
27-
behandlingsInntektsGetter.getSpesifisertInntekt(
28-
Inntektparametre(
29-
aktørId = request.aktørId,
30-
vedtakId = request.vedtakId,
31-
beregningsdato = request.beregningsDato,
32-
fødselnummer = request.fødselsnummer
21+
withContext(IO) {
22+
val request = call.receive<InntektRequestMedFnr>()
23+
24+
val spesifisertInntekt =
25+
behandlingsInntektsGetter.getSpesifisertInntekt(
26+
Inntektparametre(
27+
aktørId = request.aktørId,
28+
vedtakId = request.vedtakId,
29+
beregningsdato = request.beregningsDato,
30+
fødselnummer = request.fødselsnummer
31+
)
3332
)
34-
)
35-
}
3633

37-
call.respond(HttpStatusCode.OK, spesifisertInntekt)
34+
call.respond(HttpStatusCode.OK, spesifisertInntekt)
35+
}
3836
}
3937
}
4038
route("klassifisert") {
4139
post {
42-
val request = call.receive<InntektRequestMedFnr>()
43-
44-
val klassifisertInntekt = withContext(api) {
45-
behandlingsInntektsGetter.getKlassifisertInntekt(
46-
Inntektparametre(
47-
aktørId = request.aktørId,
48-
vedtakId = request.vedtakId,
49-
beregningsdato = request.beregningsDato,
50-
fødselnummer = request.fødselsnummer
40+
withContext(IO) {
41+
val request = call.receive<InntektRequestMedFnr>()
42+
val klassifisertInntekt =
43+
behandlingsInntektsGetter.getKlassifisertInntekt(
44+
Inntektparametre(
45+
aktørId = request.aktørId,
46+
vedtakId = request.vedtakId,
47+
beregningsdato = request.beregningsDato,
48+
fødselnummer = request.fødselsnummer
49+
)
5150
)
52-
)
51+
call.respond(HttpStatusCode.OK, klassifisertInntekt)
5352
}
54-
55-
call.respond(HttpStatusCode.OK, klassifisertInntekt)
5653
}
5754
}
5855
}

dp-inntekt-api/src/main/kotlin/no/nav/dagpenger/inntekt/v1/InntjeningsperiodeRoute.kt

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ import io.ktor.response.respond
77
import io.ktor.routing.Route
88
import io.ktor.routing.post
99
import io.ktor.routing.route
10+
import kotlinx.coroutines.Dispatchers
11+
import kotlinx.coroutines.withContext
1012
import no.nav.dagpenger.inntekt.db.InntektId
1113
import no.nav.dagpenger.inntekt.db.InntektStore
1214
import no.nav.dagpenger.inntekt.opptjeningsperiode.Opptjeningsperiode
@@ -18,19 +20,21 @@ fun Route.opptjeningsperiodeApi(inntektStore: InntektStore) {
1820

1921
route("is-samme-inntjeningsperiode") {
2022
post {
21-
val parametere = call.receive<InntjeningsperiodeParametre>()
23+
withContext(Dispatchers.IO) {
24+
val parametere = call.receive<InntjeningsperiodeParametre>()
2225

23-
val gammelBeregningsdato = inntektStore.getBeregningsdato(InntektId(parametere.inntektsId))
26+
val gammelBeregningsdato = inntektStore.getBeregningsdato(InntektId(parametere.inntektsId))
2427

25-
val resultat = Opptjeningsperiode(gammelBeregningsdato).sammeOpptjeningsPeriode(
26-
Opptjeningsperiode(
27-
LocalDate.parse(parametere.beregningsdato)
28+
val resultat = Opptjeningsperiode(gammelBeregningsdato).sammeOpptjeningsPeriode(
29+
Opptjeningsperiode(
30+
LocalDate.parse(parametere.beregningsdato)
31+
)
2832
)
29-
)
3033

31-
val response = InntjeningsperiodeResultat(resultat, parametere)
34+
val response = InntjeningsperiodeResultat(resultat, parametere)
3235

33-
call.respond(HttpStatusCode.OK, response)
36+
call.respond(HttpStatusCode.OK, response)
37+
}
3438
}
3539
}
3640
}

0 commit comments

Comments
 (0)