Class CacheTestSupport.TestClock

java.lang.Object
cloud.opencode.base.cache.testing.CacheTestSupport.TestClock
Enclosing class:
CacheTestSupport

public static class CacheTestSupport.TestClock extends Object
Controllable clock for testing time-dependent cache behavior 用于测试时间相关缓存行为的可控时钟
Since:
JDK 25, opencode-base-cache V1.0.0
Author:
Leon Soo www.LeonSoo.com
  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a TestClock at the current time | 创建当前时间的测试时钟
    TestClock(Instant initialTime)
    Creates a TestClock at the specified time | 创建指定时间的测试时钟
  • Method Summary

    Modifier and Type
    Method
    Description
    void
    advance(Duration duration)
    Advance time by duration 按时长推进时间
    long
    Get current time in milliseconds 获取当前时间(毫秒)
    void
    setTime(long millis)
    Set time in milliseconds 设置时间(毫秒)
    void
    setTime(Instant instant)
    Set time to specific instant 设置为特定时刻

    Methods inherited from class Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

    • TestClock

      public TestClock()
      Creates a TestClock at the current time | 创建当前时间的测试时钟
    • TestClock

      public TestClock(Instant initialTime)
      Creates a TestClock at the specified time | 创建指定时间的测试时钟
      Parameters:
      initialTime - the initial time | 初始时间
  • Method Details

    • millis

      public long millis()
      Get current time in milliseconds 获取当前时间(毫秒)
      Returns:
      current time | 当前时间
    • advance

      public void advance(Duration duration)
      Advance time by duration 按时长推进时间
      Parameters:
      duration - duration to advance | 推进时长
    • setTime

      public void setTime(Instant instant)
      Set time to specific instant 设置为特定时刻
      Parameters:
      instant - the instant | 时刻
    • setTime

      public void setTime(long millis)
      Set time in milliseconds 设置时间(毫秒)
      Parameters:
      millis - time in milliseconds | 毫秒时间