Class MonotonicFakeClock

java.lang.Object
org.eclipse.jgit.junit.time.MonotonicFakeClock
All Implemented Interfaces:
MonotonicClock

public class MonotonicFakeClock extends Object implements MonotonicClock
Fake MonotonicClock for testing code that uses Clock.
Since:
4.6
  • Field Details

    • now

      private long now
  • Constructor Details

    • MonotonicFakeClock

      public MonotonicFakeClock()
  • Method Details

    • tick

      public void tick(long add, TimeUnit unit)
      Advance the time returned by future calls to propose().
      Parameters:
      add - amount of time to add; must be > 0.
      unit - unit of add.
    • propose

      public ProposedTimestamp propose()
      Obtain a timestamp close to "now".

      Proposed times are close to "now", but may not yet be certainly in the past. This allows the calling thread to interleave other useful work while waiting for the clock instance to create an assurance it will never in the future propose a time earlier than the returned time.

      A hypothetical implementation could read the local system clock (managed by NTP) and return that proposal, concurrently sending network messages to closely collaborating peers in the same cluster to also ensure their system clocks are ahead of this time. In such an implementation the ProposedTimestamp.blockUntil(Duration) method would wait for replies from the peers indicating their own system clocks have moved past the proposed time.

      Specified by:
      propose in interface MonotonicClock
      Returns:
      a ProposedTimestamp object.