Package org.mockserver.time
Class TimeService
java.lang.Object
org.mockserver.time.TimeService
-
Field Summary
Fields -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionstatic voidAdvance the frozen clock by the given duration.static longReturns current time in epoch milliseconds, consistent withnow().static booleanstatic voidfixedTime(boolean fixed) Test-only: pin (or unpin)now()toFIXED_INSTANT_FOR_TESTSfor the CURRENT thread only, so parallel test classes do not observe each other's fixed clock.static voidfixedTimeGlobally(boolean fixed) Test-only: pin (or unpin)now()for ALL threads.static voidFreeze the clock at the given instant.static booleanisFrozen()Returns true if the clock is currently frozen, either via the controllable clock (freeze(Instant)) or because a test has pinned time.static Instantnow()Returns the current instant: the controllable-clock frozen instant if set, thenFIXED_INSTANT_FOR_TESTSif a test has pinned time (per-thread or globally), otherwise the real wall-clock time.static OffsetDateTimestatic voidreset()Reset the controllable clock to real time (unfrozen).
-
Field Details
-
FIXED_INSTANT_FOR_TESTS
-
-
Constructor Details
-
TimeService
public TimeService()
-
-
Method Details
-
now
Returns the current instant: the controllable-clock frozen instant if set, thenFIXED_INSTANT_FOR_TESTSif a test has pinned time (per-thread or globally), otherwise the real wall-clock time. -
currentTimeMillis
public static long currentTimeMillis()Returns current time in epoch milliseconds, consistent withnow(). -
offsetNow
-
freeze
Freeze the clock at the given instant. Ifinstantis null, freezes at the current real time. Part of the controllable-clock API used by chaos time-outage features; JVM-global. -
advance
Advance the frozen clock by the given duration. If the clock is not currently frozen, it is first frozen at the current real time (or the test-fixed instant if a test has pinned time), then advanced. -
reset
public static void reset()Reset the controllable clock to real time (unfrozen). Does not affect test-only time pinning. -
isFrozen
public static boolean isFrozen()Returns true if the clock is currently frozen, either via the controllable clock (freeze(Instant)) or because a test has pinned time. -
fixedTime
public static void fixedTime(boolean fixed) Test-only: pin (or unpin)now()toFIXED_INSTANT_FOR_TESTSfor the CURRENT thread only, so parallel test classes do not observe each other's fixed clock. Prefer theorg.mockserver.time.FixedTimeJUnit rule, which guarantees the reset. -
fixedTimeGlobally
public static void fixedTimeGlobally(boolean fixed) Test-only: pin (or unpin)now()for ALL threads. JVM-global and therefore NOT parallel-safe - use only from tests in the sequential Surefire phase. Prefer theorg.mockserver.time.GlobalFixedTimeJUnit rule. -
fixedTime
public static boolean fixedTime()
-