Class Timing2
java.lang.Object
org.apache.curator.test.compatibility.Timing2
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 Summary
-
Method Summary
Modifier and TypeMethodDescriptionboolean
acquireSemaphore
(Semaphore semaphore) Wait on the given semaphoreboolean
acquireSemaphore
(Semaphore semaphore, int n) Wait on the given semaphoreboolean
awaitLatch
(CountDownLatch latch) Wait on the given latchint
Return the value to use for ZK connection timeoutReturn a new timing with a multiple that ensures a ZK session timeoutReturn a new timing with a multiple for sleeping a smaller amount of timeReturn a new timing with the standard multiple for waiting on latches, etc.<T> T
getFuture
(CompletableFuture<T> future) int
Return the base time in millisecondsmultiple
(double n) Return a new timing that is a multiple of the this timingmultiple
(double n, int waitingMultiple) Return a new timing that is a multiple of the this timingint
seconds()
Return the base time in secondsint
session()
Return the value to use for ZK session timeoutvoid
sleep()
Sleep for a the full amount of timevoid
Sleep for a small amount of time<T> T
takeFromQueue
(BlockingQueue<T> queue) Try to take an item from the given queueint
tickTime()
Value to use for server "tickTime"
-
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 multiplewaitingMultiple
- multiple of main timing to use when waiting
-
Timing2
- Parameters:
value
- base timeunit
- base time unit
-
Timing2
- Parameters:
value
- base timeunit
- base time unitwaitingMultiple
- 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 -
awaitLatch
Wait on the given latch- Parameters:
latch
- latch to wait on- Returns:
- result of
CountDownLatch.await(long, java.util.concurrent.TimeUnit)
-
takeFromQueue
Try to take an item from the given queue- Parameters:
queue
- queue- Returns:
- item
- Throws:
Exception
- interrupted or timed out
-
acquireSemaphore
Wait on the given semaphore- Parameters:
semaphore
- the semaphore- Returns:
- result of
Semaphore.tryAcquire()
-
acquireSemaphore
Wait on the given semaphore- Parameters:
semaphore
- the semaphoren
- number of permits to acquire- Returns:
- result of
Semaphore.tryAcquire(int, long, java.util.concurrent.TimeUnit)
-
multiple
Return a new timing that is a multiple of the this timing- Parameters:
n
- the multiple- Returns:
- this timing times the multiple
-
multiple
Return a new timing that is a multiple of the this timing- Parameters:
n
- the multiplewaitingMultiple
- new waitingMultiple- Returns:
- this timing times the multiple
-
forWaiting
Return a new timing with the standard multiple for waiting on latches, etc.- Returns:
- this timing multiplied
-
forSessionSleep
Return a new timing with a multiple that ensures a ZK session timeout- Returns:
- this timing multiplied
-
forSleepingABit
Return a new timing with a multiple for sleeping a smaller amount of time- Returns:
- this timing multiplied
-
sleepABit
Sleep for a small amount of time- Throws:
InterruptedException
- if interrupted
-
sleep
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
-