Class Timing2

java.lang.Object
org.apache.curator.test.compatibility.Timing2

public class Timing2 extends Object
Utility to get various testing times. Copied from the old Timing class which is now deprecated. Needed this to support ZK 3.4 compatibility
  • Constructor Details

    • Timing2

      public Timing2()
      Use the default base time
    • Timing2

      public Timing2(double multiple)
      Use a multiple of the default base time
      Parameters:
      multiple - the multiple
    • Timing2

      public Timing2(double multiple, int waitingMultiple)
      Use a multiple of the default base time
      Parameters:
      multiple - the multiple
      waitingMultiple - multiple of main timing to use when waiting
    • Timing2

      public Timing2(long value, TimeUnit unit)
      Parameters:
      value - base time
      unit - base time unit
    • Timing2

      public Timing2(long value, TimeUnit unit, int waitingMultiple)
      Parameters:
      value - base time
      unit - base time unit
      waitingMultiple - multiple of main timing to use when waiting
  • Method Details

    • milliseconds

      public int milliseconds()
      Return the base time in milliseconds
      Returns:
      time ms
    • seconds

      public int seconds()
      Return the base time in seconds
      Returns:
      time secs
    • getFuture

      public <T> T getFuture(CompletableFuture<T> future) throws InterruptedException, ExecutionException, TimeoutException
      Throws:
      InterruptedException
      ExecutionException
      TimeoutException
    • awaitLatch

      public boolean awaitLatch(CountDownLatch latch)
      Wait on the given latch
      Parameters:
      latch - latch to wait on
      Returns:
      result of CountDownLatch.await(long, java.util.concurrent.TimeUnit)
    • takeFromQueue

      public <T> T takeFromQueue(BlockingQueue<T> queue) throws Exception
      Try to take an item from the given queue
      Parameters:
      queue - queue
      Returns:
      item
      Throws:
      Exception - interrupted or timed out
    • acquireSemaphore

      public boolean acquireSemaphore(Semaphore semaphore)
      Wait on the given semaphore
      Parameters:
      semaphore - the semaphore
      Returns:
      result of Semaphore.tryAcquire()
    • acquireSemaphore

      public boolean acquireSemaphore(Semaphore semaphore, int n)
      Wait on the given semaphore
      Parameters:
      semaphore - the semaphore
      n - number of permits to acquire
      Returns:
      result of Semaphore.tryAcquire(int, long, java.util.concurrent.TimeUnit)
    • multiple

      public Timing2 multiple(double n)
      Return a new timing that is a multiple of the this timing
      Parameters:
      n - the multiple
      Returns:
      this timing times the multiple
    • multiple

      public Timing2 multiple(double n, int waitingMultiple)
      Return a new timing that is a multiple of the this timing
      Parameters:
      n - the multiple
      waitingMultiple - new waitingMultiple
      Returns:
      this timing times the multiple
    • forWaiting

      public Timing2 forWaiting()
      Return a new timing with the standard multiple for waiting on latches, etc.
      Returns:
      this timing multiplied
    • forSessionSleep

      public Timing2 forSessionSleep()
      Return a new timing with a multiple that ensures a ZK session timeout
      Returns:
      this timing multiplied
    • forSleepingABit

      public Timing2 forSleepingABit()
      Return a new timing with a multiple for sleeping a smaller amount of time
      Returns:
      this timing multiplied
    • sleepABit

      public void sleepABit() throws InterruptedException
      Sleep for a small amount of time
      Throws:
      InterruptedException - if interrupted
    • sleep

      public void sleep() throws InterruptedException
      Sleep for a the full amount of time
      Throws:
      InterruptedException - if interrupted
    • session

      public int session()
      Return the value to use for ZK session timeout
      Returns:
      session timeout
    • connection

      public int connection()
      Return the value to use for ZK connection timeout
      Returns:
      connection timeout
    • tickTime

      public int tickTime()
      Value to use for server "tickTime"
      Returns:
      tick time