diff --git a/cffu-core/src/test/java/io/foldright/aspect_test/CheckMinStageRuntimeTypeTests.kt b/cffu-core/src/test/java/io/foldright/aspect_test/CheckMinStageRuntimeTypeTests.kt index 4594ed67..6dcf55bf 100644 --- a/cffu-core/src/test/java/io/foldright/aspect_test/CheckMinStageRuntimeTypeTests.kt +++ b/cffu-core/src/test/java/io/foldright/aspect_test/CheckMinStageRuntimeTypeTests.kt @@ -1,10 +1,11 @@ package io.foldright.aspect_test import io.foldright.cffu.Cffu +import io.foldright.cffu.CffuFactory import io.foldright.cffu.CompletableFutureUtils import io.foldright.test_utils.* +import io.kotest.core.spec.style.AnnotationSpec import io.kotest.inspectors.forAll -import org.junit.jupiter.api.Test import java.util.concurrent.CompletableFuture import java.util.concurrent.CompletableFuture.completedFuture import java.util.concurrent.CompletionStage @@ -16,7 +17,10 @@ import java.util.function.Supplier * Check the runtime type of return value of all method that returned CompletableFuture/Cffu. */ @Suppress("MoveLambdaOutsideParentheses") -private class CheckMinStageRuntimeTypeTests { +class CheckMinStageRuntimeTypeTests : AnnotationSpec() { + private val testExecutor = createThreadPool("CheckMinStageRuntimeTypeTests", queueCapacity = 1000_000) + private val testCffuFac = CffuFactory.builder(testExecutor).build(); + private val cfThis: CompletableFuture = completedFuture("cf this") private val csThis: CompletionStage = CompletableFutureUtils.completedStage("cs this") private val cffuThis: Cffu = testCffuFac.completedFuture("cffu this") @@ -946,4 +950,11 @@ private class CheckMinStageRuntimeTypeTests { // Casting CompletionStage instances to Cffu is not normal/public API usage!! minCffuThis.newIncompleteFuture().shouldNotBeMinimalStage() } + + @AfterEach + fun afterEach() { + println("executor info of CheckMinStageRuntimeTypeTests:") + println("testExecutor: $testExecutor") + println("testFjExecutor: $testFjExecutor") + } } diff --git a/cffu-core/src/test/java/io/foldright/test_utils/TestingExecutorUtils.kt b/cffu-core/src/test/java/io/foldright/test_utils/TestingExecutorUtils.kt index c755b8dd..cd65a3fa 100644 --- a/cffu-core/src/test/java/io/foldright/test_utils/TestingExecutorUtils.kt +++ b/cffu-core/src/test/java/io/foldright/test_utils/TestingExecutorUtils.kt @@ -5,6 +5,7 @@ package io.foldright.test_utils import io.foldright.cffu.CffuFactory import io.kotest.assertions.fail import io.kotest.core.config.AbstractProjectConfig +import io.kotest.core.listeners.AfterProjectListener import io.kotest.core.listeners.BeforeProjectListener import io.kotest.matchers.booleans.shouldBeFalse import io.kotest.matchers.booleans.shouldBeTrue @@ -19,7 +20,7 @@ import kotlin.random.nextULong //////////////////////////////////////////////////////////////////////////////// @JvmField -val THREAD_COUNT_OF_POOL: Int = (Runtime.getRuntime().availableProcessors() * 3).coerceAtLeast(8).coerceAtMost(20) +val THREAD_COUNT_OF_POOL: Int = (Runtime.getRuntime().availableProcessors() * 4).coerceAtLeast(8).coerceAtMost(30) @JvmField val testExecutor = createThreadPool("ThreadPoolForCffuTesting") @@ -31,15 +32,21 @@ val testCffuFac: CffuFactory = CffuFactory.builder(testExecutor).build() val testFjExecutor = createThreadPool("ForkJoinPoolForCffuTesting", true) @JvmOverloads -fun createThreadPool(threadNamePrefix: String, isForkJoin: Boolean = false): ExecutorService { +fun createThreadPool( + threadNamePrefix: String, + isForkJoin: Boolean = false, + queueCapacity: Int? = null +): ExecutorService { val counter = AtomicLong() val prefix = "${threadNamePrefix}_${Random.nextULong()}_" + val qc = queueCapacity ?: (THREAD_COUNT_OF_POOL * 500).coerceAtLeast(5000); + val executorService = if (!isForkJoin) ThreadPoolExecutor( /* corePoolSize = */ THREAD_COUNT_OF_POOL, /* maximumPoolSize = */ THREAD_COUNT_OF_POOL, - /* keepAliveTime = */ 2, TimeUnit.MINUTES, - /* workQueue = */ ArrayBlockingQueue((THREAD_COUNT_OF_POOL * 500).coerceAtLeast(5000)) + /* keepAliveTime = */ 1, TimeUnit.MINUTES, + /* workQueue = */ ArrayBlockingQueue(qc) ) { r -> Thread(r).apply { name = "${prefix}${counter.getAndIncrement()}" @@ -61,7 +68,7 @@ fun createThreadPool(threadNamePrefix: String, isForkJoin: Boolean = false): Exe override fun unwrap(): ExecutorService = executorService override fun toString(): String = - "test ${if (isForkJoin) "ForkJoinPool" else "ThreadPoolExecutor"} with thread name prefix `$prefix`" + "test ${if (isForkJoin) "ForkJoinPool" else "ThreadPoolExecutor"} with thread name prefix `$prefix`, $executorService" } } @@ -147,7 +154,7 @@ fun shutdownExecutorService(vararg executors: ExecutorService) { /** * https://kotest.io/docs/framework/project-config.html */ -object CffuKotestProjectConfig : AbstractProjectConfig(), BeforeProjectListener { +object CffuKotestProjectConfig : AbstractProjectConfig(), BeforeProjectListener, AfterProjectListener { override suspend fun beforeProject() { println(">>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>") println("call beforeProject") @@ -161,4 +168,10 @@ object CffuKotestProjectConfig : AbstractProjectConfig(), BeforeProjectListener warmupExecutorService(testExecutor, testFjExecutor) } + + override suspend fun afterProject() { + println("executor info afterProject:") + println("testExecutor: $testExecutor") + println("testFjExecutor: $testFjExecutor") + } }