Class TimingAssert
java.lang.Object
cloud.opencode.base.test.assertion.TimingAssert
Timing Assert - Performance timing assertions
计时断言 - 性能计时断言
Provides assertion methods for verifying that operations complete within specified time limits.
提供用于验证操作在指定时间限制内完成的断言方法。
Features | 主要功能:
- Assert Runnable completes within duration - 断言 Runnable 在指定时间内完成
- Assert Callable completes within duration and return result - 断言 Callable 在指定时间内完成并返回结果
- Nanosecond precision timing - 纳秒精度计时
Usage Examples | 使用示例:
// Assert a Runnable completes within 100ms
TimingAssert.assertCompletesWithin(Duration.ofMillis(100), () -> {
doSomeWork();
});
// Assert a Callable completes within 200ms and get result
String result = TimingAssert.assertCompletesWithin(Duration.ofMillis(200), () -> {
return computeValue();
});
Security | 安全性:
- Thread-safe: Yes (stateless utility) - 线程安全: 是(无状态工具类)
- Since:
- JDK 25, opencode-base-test V1.0.3
- Author:
- Leon Soo www.LeonSoo.com
- See Also:
-
Method Summary
Modifier and TypeMethodDescriptionstatic voidassertCompletesWithin(Duration timeout, Runnable runnable) Asserts that the given runnable completes within the specified duration.static <T> TassertCompletesWithin(Duration timeout, Callable<T> callable) Asserts that the given callable completes within the specified duration and returns its result.
-
Method Details
-
assertCompletesWithin
Asserts that the given runnable completes within the specified duration. If the operation both exceeds the timeout and throws an exception, the timeout violation is reported (since it is likely the root cause). 断言给定的Runnable在指定时间内完成。 如果操作既超时又抛出异常,将报告超时违规(因为它可能是根本原因)。- Parameters:
timeout- the maximum allowed duration | 最大允许时间runnable- the operation to execute | 要执行的操作- Throws:
AssertionException- if the operation exceeds the timeout | 如果操作超过超时时间TestException- if the operation throws an exception within the timeout | 如果操作在超时内抛出异常- Since:
- V1.0.3
-
assertCompletesWithin
Asserts that the given callable completes within the specified duration and returns its result. If the operation both exceeds the timeout and throws an exception, the timeout violation is reported (since it is likely the root cause). 断言给定的Callable在指定时间内完成并返回结果。 如果操作既超时又抛出异常,将报告超时违规(因为它可能是根本原因)。- Type Parameters:
T- the result type | 结果类型- Parameters:
timeout- the maximum allowed duration | 最大允许时间callable- the operation to execute | 要执行的操作- Returns:
- the result of the callable | Callable的结果
- Throws:
AssertionException- if the operation exceeds the timeout | 如果操作超过超时时间TestException- if the operation throws an exception within the timeout | 如果操作在超时内抛出异常- Since:
- V1.0.3
-