pkl-doc: Fix/improve Executor handling in DocGenerator (#1590)

run() now creates and closes a default Executor per call. This is fine
because there is no good reason to call this method multiple times.

run(Executor) now lets callers provide their own Executor, which is
customary for a well-behaved library.

Also: Fix IntelliJ warning by calling toSet()

Closes #1583
This commit is contained in:
odenix
2026-05-14 20:02:23 +02:00
committed by GitHub
parent 6171dbde28
commit 1b6e89c971
2 changed files with 48 additions and 37 deletions
@@ -17,22 +17,15 @@ package org.pkl.doc
import org.assertj.core.api.Assertions.assertThat
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.EnabledIf
import org.junit.jupiter.api.condition.EnabledForJreRange
import org.junit.jupiter.api.condition.JRE
class DocGeneratorTest {
companion object {
@JvmStatic
fun isJdk21OrLater(): Boolean {
return Runtime.version().feature() >= 21
}
}
@Test
@EnabledIf("isJdk21OrLater")
fun `uses virtual thread executor on JDK 21`() {
@EnabledForJreRange(min = JRE.JAVA_21)
fun `uses virtual thread executor on JDK 21+`() {
// On older JDKs, we get a ThreadPoolExecutor.
// not sure if there's a better assertion to make here.
assertThat(DocGenerator.executor.javaClass.canonicalName)
assertThat(DocGenerator.createDefaultExecutor().javaClass.canonicalName)
.isEqualTo("java.util.concurrent.ThreadPerTaskExecutor")
}
}