Не подтверждена Коммит 544372d9 создал по автору Leonid Stashevsky's avatar Leonid Stashevsky Зафиксировано автором GitHub
Просмотр файлов

KTOR-2586 Fix module start twice; Fix starting exception (#2502)

владелец f7aa31b5
......@@ -34,3 +34,5 @@ class CIOSustainabilityTest : SustainabilityTestSuite<CIOApplicationEngine, CIOA
enableSsl = false
}
}
class CIOConfigTest : ConfigTestSuite(CIO)
......@@ -302,7 +302,7 @@ public class ApplicationEngineEnvironmentReloading(
try {
launchModuleByName(name, currentClassLoader, newInstance)
} catch (_: Throwable) {
} catch (_: ReloadingException) {
module(newInstance)
}
}
......
......@@ -41,8 +41,9 @@ internal fun ApplicationEnvironment.executeModuleFunction(
if (Function1::class.java.isAssignableFrom(clazz)) {
val constructor = clazz.declaredConstructors.single()
if (constructor.parameterCount != 0) {
throw RuntimeException("Module function with captured variables cannot be instantiated '$fqName'")
throw ReloadingException("Module function with captured variables cannot be instantiated '$fqName'")
}
constructor.isAccessible = true
@Suppress("UNCHECKED_CAST")
val function = constructor.newInstance() as Function1<Application, Unit>
......@@ -85,8 +86,8 @@ private fun <R> ApplicationEnvironment.callFunctionWithInjection(
instance: Any?,
entryPoint: KFunction<R>,
application: Application
): R = entryPoint.callBy(
entryPoint.parameters.filterNot { it.isOptional }.associateBy(
): R {
val args = entryPoint.parameters.filterNot { it.isOptional }.associateBy(
{ it },
{ parameter ->
when {
......@@ -109,4 +110,12 @@ private fun <R> ApplicationEnvironment.callFunctionWithInjection(
}
}
)
)
try {
return entryPoint.callBy(args)
} catch (cause: InvocationTargetException) {
throw cause.cause ?: cause
}
}
internal class ReloadingException(message: String) : RuntimeException(message)
......@@ -72,3 +72,5 @@ class JettyHttpServerTest : HttpServerTestSuite<JettyApplicationEngine, JettyApp
class JettySustainabilityTest :
SustainabilityTestSuite<JettyApplicationEngine, JettyApplicationEngineBase.Configuration>(Jetty)
class JettyConfigTest : ConfigTestSuite(Jetty)
......@@ -50,9 +50,9 @@ class NettyHttp2ServerTest : HttpServerTestSuite<NettyApplicationEngine, NettyAp
}
}
class NettySustainabilityTest :
SustainabilityTestSuite<NettyApplicationEngine, NettyApplicationEngine.Configuration>(Netty) {
class NettySustainabilityTest : SustainabilityTestSuite<NettyApplicationEngine, NettyApplicationEngine.Configuration>(
Netty
) {
init {
enableSsl = true
}
......@@ -61,3 +61,5 @@ class NettySustainabilityTest :
configuration.shareWorkGroup = true
}
}
class NettyConfigTest : ConfigTestSuite(Netty)
......@@ -21,12 +21,11 @@ import java.io.*
import java.util.zip.*
import kotlin.test.*
public abstract class CompressionTestSuite<TEngine : ApplicationEngine,
TConfiguration : ApplicationEngine.Configuration>(hostFactory: ApplicationEngineFactory<TEngine, TConfiguration>) :
EngineTestBase<TEngine, TConfiguration>(hostFactory) {
abstract class CompressionTestSuite<TEngine : ApplicationEngine, TConfiguration : ApplicationEngine.Configuration>(
hostFactory: ApplicationEngineFactory<TEngine, TConfiguration>
) : EngineTestBase<TEngine, TConfiguration>(hostFactory) {
@Test
public fun testLocalFileContentWithCompression() {
fun testLocalFileContentWithCompression() {
val file = loadTestFile()
testLog.trace("test file is $file")
......@@ -45,7 +44,7 @@ public abstract class CompressionTestSuite<TEngine : ApplicationEngine,
}
@Test
public fun testStreamingContentWithCompression() {
fun testStreamingContentWithCompression() {
val file = loadTestFile()
testLog.trace("test file is $file")
......@@ -70,7 +69,7 @@ public abstract class CompressionTestSuite<TEngine : ApplicationEngine,
}
@Test
public fun testLocalFileContentRangeWithCompression() {
fun testLocalFileContentRangeWithCompression() {
val file = loadTestFile()
testLog.trace("test file is $file")
......@@ -103,7 +102,7 @@ public abstract class CompressionTestSuite<TEngine : ApplicationEngine,
}
@Test
public fun testCompressionWriteToLarge() {
fun testCompressionWriteToLarge() {
val count = 655350
fun Appendable.produceText() {
for (i in 1..count) {
......
/*
* Copyright 2014-2021 JetBrains s.r.o and contributors. Use of this source code is governed by the Apache 2.0 license.
*/
package io.ktor.server.testing.suites
import io.ktor.server.engine.*
import java.util.concurrent.*
import kotlin.test.*
var count = 0
abstract class ConfigTestSuite(val engine: ApplicationEngineFactory<*, *>) {
@Test
fun testStartOnceWhenException() {
// Please note that it's critical to not capture any variables inside the scope
// It will disable autoreload and change behaviour
val server = embeddedServer(engine) {
count++
error("Foo")
}
assertFailsWith<IllegalStateException> {
server.start()
}
assertEquals(1, count)
server.stop(1, 1, TimeUnit.SECONDS)
}
@Test
fun testStartsOnceWithCapture() {
var counter = 0
val server = embeddedServer(engine) {
counter++
error("Foo")
}
assertFailsWith<IllegalStateException> {
server.start()
}
assertEquals(1, counter)
server.stop(1, 1, TimeUnit.SECONDS)
}
}
......@@ -135,3 +135,5 @@ class TomcatSustainabilityTestSuite :
super.testBlockingConcurrency()
}
}
class TomcatConfigTest : ConfigTestSuite(Tomcat)
Поддерживает Markdown
0% или .
You are about to add 0 people to the discussion. Proceed with caution.
Сначала завершите редактирование этого сообщения!
Пожалуйста, зарегистрируйтесь или чтобы прокомментировать