gotoOla
09/21/2020, 8:31 AMsuspend fun main() {
val server = embeddedServer(Netty, port = 8080) {
routing {
route("/") {
getAndReportMetrics("/hello") {
Thread.sleep(31_000)
it.respondJson(mapOf("hello" to true), HttpStatusCode.OK)
}
}
}
}.start()
var response: HttpResponse? = null
val responseTime = measureTimeMillis {
try {
val precon = OkHttpClient.Builder()
.callTimeout(Duration.ofMillis(30_000))
.readTimeout(Duration.ofMillis(30_000))
.connectTimeout(Duration.ofMillis(30_000))
.writeTimeout(Duration.ofMillis(30_000))
.build()
val lolClient =
HttpClient(OkHttp) {
expectSuccess = false
engine {
config {
preconfigured = precon
}
}
}
response = lolClient.get<HttpResponse>("<http://localhost:8080/hello>")
response!!.isIn200Range()
} catch(e: Exception) {
println("got an exception $e")
}
}
println("hello $responseTime")
}
It seems the default socketTimeout of 10 seconds still applies in this case