Joakim Taule Kartveit
10/22/2024, 10:23 AMpackage com.example.plugins
import io.ktor.server.application.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
fun Application.configureRouting() {
routing {
get("/") {
val byteArray = ByteArray(400000000)
call.respondBytes(byteArray)
}
}
}
This works fine, but when i try to create a unit test based on this like so:
package com.example.plugins
import io.ktor.client.request.*
import io.ktor.http.*
import io.ktor.server.response.*
import io.ktor.server.routing.*
import io.ktor.server.testing.*
import org.junit.jupiter.api.Assertions.assertEquals
import org.junit.jupiter.api.Test
internal class RoutingTest {
@Test
internal fun `Returns ok on big bytearray`() {
testApplication {
application {
routing {
get("/") {
val byteArray = ByteArray(400000000)
call.respondBytes(byteArray)
}
}
}
val response = client.get("/")
assertEquals(HttpStatusCode.OK, response.status)
}
}
}
Then i get this exception:
Exception: java.lang.OutOfMemoryError thrown from the UncaughtExceptionHandler in thread "DefaultDispatcher-worker-1"
Is it my test that are incorrect?gpopides
10/22/2024, 10:49 AMJoakim Taule Kartveit
10/22/2024, 11:00 AMval byteArray = ByteArray(400000000)
to
val byteArray = ByteArray(100000000)
it works fine.gpopides
10/22/2024, 11:11 AMJoakim Taule Kartveit
10/22/2024, 11:12 AMJoakim Taule Kartveit
10/22/2024, 11:12 AMgpopides
10/22/2024, 11:13 AMJoakim Taule Kartveit
10/22/2024, 11:21 AMkotlin.daemon.jvmargs=-Xms4096m -Xmx6048m
gpopides
10/22/2024, 11:23 AMJoakim Taule Kartveit
10/22/2024, 11:48 AMJoakim Taule Kartveit
10/23/2024, 6:29 AMtasks {
test {
minHeapSize = "1048m"
maxHeapSize = "2096m"
useJUnitPlatform {}
testLogging.showStandardStreams = true
}
}
gpopides
10/23/2024, 8:25 AMtasks.withType<Test> {}
which is how its done in latest versions