docs: 补全 src 全部 Kotlin KDoc 与 Java Javadoc,版本升级至 5.5.1
Gitea Actions Build / Build (push) Canceled after 0s

为所有缺失文档的公开声明补充中文 KDoc/Javadoc(含 exception、json、
springboot、tuple 生成类、MediaType 枚举项及测试),仅插入注释不改代码;
gradle.properties VERSIONS 5.4.4 -> 5.5.1。
This commit is contained in:
2026-11-17 21:07:58 +08:00
parent d0887ea1f7
commit 51eb838a36
148 changed files with 16651 additions and 15 deletions
@@ -34,11 +34,15 @@ import tools.jackson.module.kotlin.jsonMapper
import tools.jackson.module.kotlin.kotlinModule
/**
* JSON API 集成测试,覆盖 Jackson3 与 DateTime 转换器的序列化/反序列化
*/
class TestJson {
private val log = Loggers.getLogger<TestJson>()
/** 测试配置 Jackson3 API 后 DateTime 的格式化与解析往返 */
@Test
fun test() {
JSONA.setJsonApi(
@@ -40,6 +40,7 @@ class AsyncTasksTest {
// ---- runParallel ----
/** 测试 runParallel 可变参数形式并行执行并按序返回结果 */
@Test
fun testRunParallelVararg() {
val results = runParallel(
@@ -50,12 +51,14 @@ class AsyncTasksTest {
assertEquals(listOf(1, 2, 3), results)
}
/** 测试 runParallel 集合形式并行执行任务 */
@Test
fun testRunParallelCollection() {
val tasks = listOf<() -> String>({ "a" }, { "b" }, { "c" })
assertEquals(listOf("a", "b", "c"), runParallel(tasks))
}
/** 测试 runParallel 结果顺序与输入顺序一致(慢任务在前) */
@Test
fun testRunParallelKeepsOrder() {
// 慢任务在前,结果仍按输入顺序返回
@@ -66,6 +69,7 @@ class AsyncTasksTest {
assertEquals(listOf("slow", "fast"), results)
}
/** 测试 runParallel 使用自定义线程池执行 */
@Test
fun testRunParallelCustomExecutor() {
val pool = fixedThreadPool(2, "parallel-test")
@@ -77,6 +81,7 @@ class AsyncTasksTest {
}
}
/** 测试 runParallel 中任务失败时向外抛出异常 */
@Test
fun testRunParallelFailure() {
assertThrows(RuntimeException::class.java) {
@@ -87,12 +92,14 @@ class AsyncTasksTest {
}
}
/** 测试 runParallelWithin 在超时时间内正常返回结果 */
@Test
fun testRunParallelWithin() {
val tasks = listOf<() -> Int>({ 1 }, { 2 })
assertEquals(listOf(1, 2), runParallelWithin(5, TimeUnit.SECONDS, tasks = tasks))
}
/** 测试 runParallelWithin 超时抛出 TimeoutException */
@Test
fun testRunParallelWithinTimeout() {
assertThrows(TimeoutException::class.java) {
@@ -106,6 +113,7 @@ class AsyncTasksTest {
// ---- firstCompleted ----
/** 测试 firstCompleted 返回最先完成任务的结果 */
@Test
fun testFirstCompleted() {
val result = firstCompleted(
@@ -117,6 +125,7 @@ class AsyncTasksTest {
// ---- awaitAll / invokeAllAndGet ----
/** 测试 awaitAll 按序等待并收集所有 Future 结果 */
@Test
fun testAwaitAll() {
val pool = fixedThreadPool(2, "await-all-test")
@@ -128,6 +137,7 @@ class AsyncTasksTest {
}
}
/** 测试 invokeAllAndGet 批量提交任务并获取结果 */
@Test
fun testInvokeAllAndGet() {
val pool = fixedThreadPool(2, "invoke-all-test")
@@ -139,6 +149,7 @@ class AsyncTasksTest {
}
}
/** 测试 awaitAllOrNull 对失败任务返回 null 而不抛异常 */
@Test
fun testAwaitAllOrNull() {
val pool = fixedThreadPool(2, "await-ornull-test")
@@ -157,6 +168,7 @@ class AsyncTasksTest {
// ---- callWithRetry ----
/** 测试 callWithRetry 失败后重试直至成功 */
@Test
fun testCallWithRetrySuccess() {
val attempts = AtomicInteger()
@@ -168,6 +180,7 @@ class AsyncTasksTest {
assertEquals("ok", result)
}
/** 测试 callWithRetry 重试次数耗尽后抛出最后一次异常 */
@Test
fun testCallWithRetryExhausted() {
val attempts = AtomicInteger()
@@ -180,6 +193,7 @@ class AsyncTasksTest {
assertEquals(2, attempts.get(), "应恰好尝试 2 次")
}
/** 测试 callAsyncWithRetry 异步重试直至成功 */
@Test
fun testCallAsyncWithRetry() {
val attempts = AtomicInteger()
@@ -193,6 +207,7 @@ class AsyncTasksTest {
// ---- 定时任务 ----
/** 测试 delayRun 延迟指定时间后执行任务 */
@Test
fun testDelayRun() {
val latch = CountDownLatch(1)
@@ -203,6 +218,7 @@ class AsyncTasksTest {
future.cancelQuietly()
}
/** 测试 scheduleWithFixedDelay 固定间隔重复执行任务 */
@Test
fun testScheduleWithFixedDelay() {
val counter = AtomicInteger()
@@ -219,6 +235,7 @@ class AsyncTasksTest {
}
}
/** 测试 scheduleAtFixedRate 固定频率重复执行任务 */
@Test
fun testScheduleAtFixedRate() {
val counter = AtomicInteger()
@@ -237,6 +254,7 @@ class AsyncTasksTest {
// ---- GlobalThreadPool ----
/** 测试 GlobalThreadPool 的 io/cpu/scheduled 全局线程池已正确初始化 */
@Test
fun testGlobalPools() {
assertTrue(GlobalThreadPool.io.corePoolSize > 0)
@@ -244,21 +262,25 @@ class AsyncTasksTest {
assertTrue(GlobalThreadPool.scheduled.corePoolSize > 0)
}
/** 测试 runAsync 异步执行无返回值任务 */
@Test
fun testRunAsync() {
assertNull(runAsync { }.get(5, TimeUnit.SECONDS))
}
/** 测试 callAsync 在 IO 线程池异步执行并返回结果 */
@Test
fun testCallAsync() {
assertEquals("io", callAsync { "io" }.get(5, TimeUnit.SECONDS))
}
/** 测试 computeAsync 在 CPU 线程池异步计算并返回结果 */
@Test
fun testComputeAsync() {
assertEquals(4, computeAsync { 2 + 2 }.get(5, TimeUnit.SECONDS))
}
/** 测试 runAsyncAwait 异步执行并阻塞等待完成 */
@Test
fun testRunAsyncAwait() {
val counter = AtomicInteger()
@@ -266,11 +288,13 @@ class AsyncTasksTest {
assertEquals(1, counter.get())
}
/** 测试 callAsyncAwait 异步执行并阻塞等待返回结果 */
@Test
fun testCallAsyncAwait() {
assertEquals("await", callAsyncAwait { "await" })
}
/** 测试 GlobalThreadPool.execute 提交任务并被执行 */
@Test
fun testGlobalExecute() {
val latch = CountDownLatch(1)
@@ -40,6 +40,7 @@ class ThreadEventTest {
private val event = ThreadEvent.of(0)
private var value: Int by event
/** 测试 await 阻塞等待直到 set 触发并读取新值 */
@Test
fun testAwaitAndSet() {
val event = ThreadEvent.of(0)
@@ -54,6 +55,7 @@ class ThreadEventTest {
assertEquals(42, event.get())
}
/** 测试 awaitAndGet 等待触发后返回新数据 */
@Test
fun testAwaitAndGet() {
val event = ThreadEvent.of(0)
@@ -69,6 +71,7 @@ class ThreadEventTest {
assertEquals(99, result.get())
}
/** 测试 await 超时未触发时返回 false */
@Test
fun testAwaitTimeout() {
val event = ThreadEvent.of(0)
@@ -77,6 +80,7 @@ class ThreadEventTest {
assertTrue(System.nanoTime() - start >= 90_000_000L, "应至少等待 100ms")
}
/** 测试 awaitAndGet 超时未触发时返回旧数据 */
@Test
fun testAwaitAndGetTimeout() {
val event = ThreadEvent.of(10)
@@ -84,12 +88,14 @@ class ThreadEventTest {
assertEquals(10, event.awaitAndGet(50, TimeUnit.MILLISECONDS))
}
/** 测试 awaitAndGetOrNull 超时未触发时返回 null */
@Test
fun testAwaitAndGetOrNullTimeout() {
val event = ThreadEvent.of(10)
assertNull(event.awaitAndGetOrNull(50, TimeUnit.MILLISECONDS), "超时未触发应返回 null")
}
/** 测试 awaitAndGetOrNull 在触发后返回新数据 */
@Test
fun testAwaitAndGetOrNullTriggered() {
val event = ThreadEvent.of(0)
@@ -101,6 +107,7 @@ class ThreadEventTest {
thread.joinQuietly(2000)
}
/** 测试 isSet 在 set/reset 前后的状态变化 */
@Test
fun testIsSet() {
val event = ThreadEvent.of(0)
@@ -111,6 +118,7 @@ class ThreadEventTest {
assertFalse(event.isSet())
}
/** 测试 setAndReset 设置数据后立即复位事件状态 */
@Test
fun testSetAndReset() {
val event = ThreadEvent.of(0)
@@ -119,6 +127,7 @@ class ThreadEventTest {
assertFalse(event.isSet(), "reset 后事件应处于未设置状态")
}
/** 测试 invoke 操作符的读取与设置语义 */
@Test
fun testOperatorInvoke() {
val event = ThreadEvent.of("a")
@@ -135,6 +144,7 @@ class ThreadEventTest {
assertEquals("b", event())
}
/** 测试 ThreadEvent 作为属性委托的读写行为 */
@Test
fun testPropertyDelegate() {
assertEquals(0, value)
@@ -143,6 +153,7 @@ class ThreadEventTest {
assertEquals(7, value)
}
/** 测试 of 工厂方法以初始数据创建事件 */
@Test
fun testFactoryOf() {
val event = ThreadEvent.of("data")
@@ -42,6 +42,7 @@ import java.util.concurrent.TimeUnit
*/
class ThreadPoolBuilderTest {
/** 测试 threadPool DSL 各项配置(核心/最大线程数、有界队列、超时回收)生效 */
@Test
fun testDslBuild() {
val pool = threadPool("dsl-test") {
@@ -62,6 +63,7 @@ class ThreadPoolBuilderTest {
}
}
/** 测试默认队列为无界队列 */
@Test
fun testDefaultQueueIsUnbounded() {
val pool = threadPool("unbounded-test")
@@ -72,6 +74,7 @@ class ThreadPoolBuilderTest {
}
}
/** 测试 fixedThreadPool 创建固定大小线程池 */
@Test
fun testFixedPool() {
val pool = fixedThreadPool(4, "fixed-test")
@@ -83,6 +86,7 @@ class ThreadPoolBuilderTest {
}
}
/** 测试 singleThreadPool 创建单线程线程池 */
@Test
fun testSinglePool() {
val pool = singleThreadPool("single-test")
@@ -94,6 +98,7 @@ class ThreadPoolBuilderTest {
}
}
/** 测试 cachedThreadPool 创建缓存线程池(SynchronousQueue、无上限) */
@Test
fun testCachedPool() {
val pool = cachedThreadPool("cached-test")
@@ -106,6 +111,7 @@ class ThreadPoolBuilderTest {
}
}
/** 测试 ioThreadPool 按 CPU 核数配置 IO 型线程池参数 */
@Test
fun testIoPool() {
val pool = ioThreadPool("io-test")
@@ -118,6 +124,7 @@ class ThreadPoolBuilderTest {
}
}
/** 测试 cpuThreadPool 按 CPU 核数配置计算型线程池参数 */
@Test
fun testCpuPool() {
val pool = cpuThreadPool("cpu-test")
@@ -129,6 +136,7 @@ class ThreadPoolBuilderTest {
}
}
/** 测试 daemon=true 时工作线程为守护线程 */
@Test
fun testDaemonThread() {
val pool = threadPool("daemon-test") {
@@ -144,6 +152,7 @@ class ThreadPoolBuilderTest {
}
}
/** 测试 daemon=false 时工作线程为用户线程 */
@Test
fun testNonDaemonThread() {
val pool = threadPool("non-daemon-test") {
@@ -159,6 +168,7 @@ class ThreadPoolBuilderTest {
}
}
/** 测试线程命名包含指定前缀 */
@Test
fun testThreadNaming() {
val pool = threadPool("naming-test") {
@@ -175,6 +185,7 @@ class ThreadPoolBuilderTest {
}
}
/** 测试线程与队列占满后按 AbortPolicy 抛出拒绝异常 */
@Test
fun testRejectedPolicy() {
val pool = threadPool("reject-test") {
@@ -199,6 +210,7 @@ class ThreadPoolBuilderTest {
}
}
/** 测试 scheduledThreadPool 创建定时线程池并延迟执行任务 */
@Test
fun testScheduledPool() {
val pool = scheduledThreadPool(2, "scheduled-test")
@@ -40,6 +40,7 @@ class ThreadPoolExtTest {
// ---- shutdownGracefully ----
/** 测试 shutdownGracefully 等待任务完成后正常终止线程池 */
@Test
fun testShutdownGracefully() {
val pool = fixedThreadPool(2, "shutdown-test")
@@ -48,6 +49,7 @@ class ThreadPoolExtTest {
assertTrue(pool.isTerminated)
}
/** 测试 shutdownAndAwait 关闭并等待线程池终止 */
@Test
fun testShutdownAndAwait() {
val pool = fixedThreadPool(1, "shutdown-await-test")
@@ -56,6 +58,7 @@ class ThreadPoolExtTest {
assertTrue(pool.isTerminated)
}
/** 测试 shutdownAndAwait 超时未终止时抛出 IllegalStateException */
@Test
fun testShutdownAndAwaitTimeout() {
val pool = singleThreadPool("shutdown-timeout-test")
@@ -74,6 +77,7 @@ class ThreadPoolExtTest {
// ---- Future 扩展 ----
/** 测试 Future.await 阻塞获取结果 */
@Test
fun testFutureAwait() {
val pool = singleThreadPool("await-test")
@@ -85,6 +89,7 @@ class ThreadPoolExtTest {
}
}
/** 测试 Future.await 解包 ExecutionException 抛出原始异常 */
@Test
fun testFutureAwaitUnwrapException() {
val pool = singleThreadPool("unwrap-test")
@@ -98,6 +103,7 @@ class ThreadPoolExtTest {
}
}
/** 测试 Future.await 带超时版本超时抛出 TimeoutException 且任务仍可完成 */
@Test
fun testFutureAwaitWithTimeout() {
val pool = singleThreadPool("await-timeout-test")
@@ -116,6 +122,7 @@ class ThreadPoolExtTest {
}
}
/** 测试 getOrNull 超时返回 null 且不影响任务最终完成 */
@Test
fun testGetOrNullTimeout() {
val pool = singleThreadPool("getornull-test")
@@ -131,6 +138,7 @@ class ThreadPoolExtTest {
}
}
/** 测试 getOrNull 任务失败时返回 null */
@Test
fun testGetOrNullFailure() {
val pool = singleThreadPool("getornull-fail-test")
@@ -142,6 +150,7 @@ class ThreadPoolExtTest {
}
}
/** 测试 getOrDefault 失败返回默认值、成功返回实际结果 */
@Test
fun testGetOrDefault() {
val pool = singleThreadPool("getordefault-test")
@@ -157,6 +166,7 @@ class ThreadPoolExtTest {
}
}
/** 测试 cancelQuietly 静默取消任务并置为已取消状态 */
@Test
fun testCancelQuietly() {
val pool = singleThreadPool("cancel-test")
@@ -174,12 +184,14 @@ class ThreadPoolExtTest {
// ---- CompletableFuture ----
/** 测试 completableFuture 异步计算并返回结果 */
@Test
fun testCompletableFuture() {
val future = completableFuture { 1 + 1 }
assertEquals(2, future.get(3, TimeUnit.SECONDS))
}
/** 测试 completableFuture 使用指定线程池执行 */
@Test
fun testCompletableFutureWithExecutor() {
val pool = fixedThreadPool(2, "cf-test")
@@ -191,6 +203,7 @@ class ThreadPoolExtTest {
}
}
/** 测试 runCompletableFuture 异步执行无返回值任务 */
@Test
fun testRunCompletableFuture() {
val latch = CountDownLatch(1)
@@ -201,6 +214,7 @@ class ThreadPoolExtTest {
// ---- ThreadPoolMonitor ----
/** 测试 snapshot 采集线程池各项运行指标 */
@Test
fun testSnapshot() {
val pool = fixedThreadPool(2, "snapshot-test")
@@ -221,6 +235,7 @@ class ThreadPoolExtTest {
}
}
/** 测试快照 toString 输出格式包含关键字段 */
@Test
fun testSnapshotToString() {
val pool = fixedThreadPool(1, "snapshot-string-test")
@@ -234,6 +249,7 @@ class ThreadPoolExtTest {
}
}
/** 测试 report 生成线程池快照报告文本 */
@Test
fun testReport() {
val pool = fixedThreadPool(1, "report-test")
@@ -245,6 +261,7 @@ class ThreadPoolExtTest {
}
}
/** 测试 monitor 周期性回调监控快照 */
@Test
fun testMonitorPeriodic() {
val pool = fixedThreadPool(2, "monitor-test")
@@ -49,6 +49,7 @@ class ThreadToolsTest {
// ---- ThreadUtils ----
/** 测试 sleepQuietly 毫秒重载的休眠时长 */
@Test
fun testSleepQuietlyMillis() {
val start = System.nanoTime()
@@ -56,6 +57,7 @@ class ThreadToolsTest {
assertTrue(System.nanoTime() - start >= 90_000_000L, "应至少休眠 100ms")
}
/** 测试 sleepQuietly 时间单位重载的休眠时长 */
@Test
fun testSleepQuietlyTimeUnit() {
val start = System.nanoTime()
@@ -63,6 +65,7 @@ class ThreadToolsTest {
assertTrue(System.nanoTime() - start >= 40_000_000L, "应至少休眠 50ms")
}
/** 测试 currentThreadName 属性的读写 */
@Test
fun testCurrentThreadNameProperty() {
assertEquals(Thread.currentThread().name, ThreadUtils.currentThreadName)
@@ -75,6 +78,7 @@ class ThreadToolsTest {
}
}
/** 测试当前线程优先级、守护状态、主线程判断、堆栈与线程组等信息获取 */
@Test
fun testCurrentThreadInfo() {
assertEquals(Thread.currentThread().priority, ThreadUtils.currentThreadPriority)
@@ -85,18 +89,21 @@ class ThreadToolsTest {
assertTrue(ThreadUtils.activeThreadCount() >= 1)
}
/** 测试 activeThreads 返回的活跃线程包含当前线程 */
@Test
fun testActiveThreads() {
val threads = ThreadUtils.activeThreads()
assertTrue(threads.any { it === Thread.currentThread() }, "活跃线程应包含当前线程")
}
/** 测试 allThreadsDump 全线程转储包含当前线程名 */
@Test
fun testAllThreadsDump() {
val dump = ThreadUtils.allThreadsDump()
assertTrue(dump.contains(Thread.currentThread().name), "全线程转储应包含当前线程名")
}
/** 测试 currentThreadDump 当前线程转储包含测试方法名 */
@Test
fun testCurrentThreadDump() {
val dump = ThreadUtils.currentThreadDump()
@@ -105,6 +112,7 @@ class ThreadToolsTest {
// ---- ThreadExt ----
/** 测试 Runnable.startThread 创建并启动指定名称的守护线程 */
@Test
fun testStartThread() {
val latch = CountDownLatch(1)
@@ -115,6 +123,7 @@ class ThreadToolsTest {
thread.joinQuietly(2000)
}
/** 测试 asThread 仅创建线程而不启动 */
@Test
fun testAsThreadNotStarted() {
val thread = Runnable { }.asThread("no-start")
@@ -123,6 +132,7 @@ class ThreadToolsTest {
assertEquals("no-start", thread.name)
}
/** 测试 daemonThread 与 userThread 的守护属性差异 */
@Test
fun testDaemonAndUserThread() {
val latch = CountDownLatch(2)
@@ -135,6 +145,7 @@ class ThreadToolsTest {
user.joinQuietly(2000)
}
/** 测试 daemonThread start=false 时不启动线程 */
@Test
fun testDaemonThreadNotStarted() {
val thread = daemonThread("no-start-daemon", start = false) { }
@@ -142,6 +153,7 @@ class ThreadToolsTest {
assertTrue(thread.isDaemon)
}
/** 测试 uncaughtExceptionHandler 捕获线程未处理异常 */
@Test
fun testOnUncaughtHandler() {
val latch = CountDownLatch(1)
@@ -158,6 +170,7 @@ class ThreadToolsTest {
assertEquals("boom", captured.get()!!.message)
}
/** 测试 startIfNotStarted 幂等启动且对已终止线程不抛异常 */
@Test
fun testStartIfNotStarted() {
val thread = Runnable { }.asThread("idempotent-start")
@@ -169,6 +182,7 @@ class ThreadToolsTest {
assertSame(thread, thread.startIfNotStarted())
}
/** 测试 Thread.sleepQuietly 扩展函数的休眠时长 */
@Test
fun testSleepQuietlyExt() {
val start = System.nanoTime()
@@ -176,6 +190,7 @@ class ThreadToolsTest {
assertTrue(System.nanoTime() - start >= 40_000_000L, "应至少休眠 50ms")
}
/** 测试 Thread.dumpStackTrace 扩展输出包含线程名与方法名 */
@Test
fun testDumpStackTrace() {
val dump = Thread.currentThread().dumpStackTrace()
@@ -183,6 +198,7 @@ class ThreadToolsTest {
assertTrue(dump.contains("testDumpStackTrace"))
}
/** 测试顶层 currentThread() 返回当前线程 */
@Test
fun testCurrentThreadTopLevel() {
assertSame(Thread.currentThread(), currentThread())
@@ -190,6 +206,7 @@ class ThreadToolsTest {
// ---- ThreadLocalDelegates ----
/** 测试 ThreadLocal 属性委托在同线程内的初始值与读写 */
@Test
fun testThreadLocalSameThread() {
assertNull(nullableValue)
@@ -201,6 +218,7 @@ class ThreadToolsTest {
assertEquals(42L, userValue)
}
/** 测试 ThreadLocal 属性委托的线程间隔离性 */
@Test
fun testThreadLocalIsolation() {
val latch = CountDownLatch(1)
@@ -219,6 +237,7 @@ class ThreadToolsTest {
assertEquals(listOf(7L), threadValues.toList())
}
/** 测试 asDelegate 将已有 ThreadLocal 包装为属性委托后的读写 */
@Test
fun testAsDelegateProperty() {
assertNull(delegatedValue)