Package net.jodah.concurrentunit
Class Waiter
- java.lang.Object
-
- net.jodah.concurrentunit.Waiter
-
public class Waiter extends java.lang.ObjectWaits on a test, carrying out assertions, until being resumed.
-
-
Field Summary
Fields Modifier and Type Field Description private ReentrantCircuitcircuitprivate java.lang.Throwablefailureprivate java.util.concurrent.atomic.AtomicIntegerremainingResumesprivate static java.lang.StringTIMEOUT_MESSAGE
-
Constructor Summary
Constructors Constructor Description Waiter()Creates a new Waiter.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidassertEquals(java.lang.Object expected, java.lang.Object actual)Asserts that theexpectedvalues equals theactualvaluevoidassertFalse(boolean condition)Asserts that theconditionis false.voidassertNotNull(java.lang.Object object)Asserts that theobjectis not null.voidassertNull(java.lang.Object object)Asserts that theobjectis null.<T> voidassertThat(T actual, org.hamcrest.Matcher<? super T> matcher)Asserts thatactualsatisfies the condition specified bymatcher.voidassertTrue(boolean condition)Asserts that theconditionis true.voidawait()Waits untilresume()is called, or the test is failed.voidawait(long delay)Waits until thedelayhas elapsed,resume()is called, or the test is failed.voidawait(long delay, int expectedResumes)voidawait(long delay, java.util.concurrent.TimeUnit timeUnit)Waits until thedelayhas elapsed,resume()is called, or the test is failed.voidawait(long delay, java.util.concurrent.TimeUnit timeUnit, int expectedResumes)voidfail()Fails the current test.voidfail(java.lang.String reason)Fails the current test for the givenreason.voidfail(java.lang.Throwable reason)Fails the current test with the givenreason, sets the number of expected resumes to 0, and throws thereasonas anAssertionErrorin the main test thread and in the current thread.private java.lang.Stringformat(java.lang.Object expected, java.lang.Object actual)voidresume()Resumes the waiter when the expected number ofresume()calls have occurred.voidrethrow(java.lang.Throwable failure)Rethrows thefailurein the main test thread and in the current thread.private static voidsneakyThrow(java.lang.Throwable t)private static <T extends java.lang.Throwable>
voidsneakyThrow2(java.lang.Throwable t)
-
-
-
Field Detail
-
TIMEOUT_MESSAGE
private static final java.lang.String TIMEOUT_MESSAGE
- See Also:
- Constant Field Values
-
remainingResumes
private java.util.concurrent.atomic.AtomicInteger remainingResumes
-
circuit
private final ReentrantCircuit circuit
-
failure
private volatile java.lang.Throwable failure
-
-
Method Detail
-
assertEquals
public void assertEquals(java.lang.Object expected, java.lang.Object actual)Asserts that theexpectedvalues equals theactualvalue- Throws:
java.lang.AssertionError- when the assertion fails
-
assertFalse
public void assertFalse(boolean condition)
Asserts that theconditionis false.- Throws:
java.lang.AssertionError- when the assertion fails
-
assertNotNull
public void assertNotNull(java.lang.Object object)
Asserts that theobjectis not null.- Throws:
java.lang.AssertionError- when the assertion fails
-
assertNull
public void assertNull(java.lang.Object object)
Asserts that theobjectis null.- Throws:
java.lang.AssertionError- when the assertion fails
-
assertTrue
public void assertTrue(boolean condition)
Asserts that theconditionis true.- Throws:
java.lang.AssertionError- when the assertion fails
-
assertThat
public <T> void assertThat(T actual, org.hamcrest.Matcher<? super T> matcher)Asserts thatactualsatisfies the condition specified bymatcher.- Throws:
java.lang.AssertionError- when the assertion fails
-
await
public void await() throws java.util.concurrent.TimeoutException, java.lang.InterruptedExceptionWaits untilresume()is called, or the test is failed.- Throws:
java.util.concurrent.TimeoutException- if the operation times out while waitingjava.lang.InterruptedException- if the operations is interrupted while waitingjava.lang.AssertionError- if any assertion fails while waiting
-
await
public void await(long delay) throws java.util.concurrent.TimeoutException, java.lang.InterruptedExceptionWaits until thedelayhas elapsed,resume()is called, or the test is failed.- Parameters:
delay- Delay to wait in milliseconds- Throws:
java.util.concurrent.TimeoutException- if the operation times out while waitingjava.lang.InterruptedException- if the operations is interrupted while waitingjava.lang.AssertionError- if any assertion fails while waiting
-
await
public void await(long delay, java.util.concurrent.TimeUnit timeUnit) throws java.util.concurrent.TimeoutException, java.lang.InterruptedExceptionWaits until thedelayhas elapsed,resume()is called, or the test is failed.- Parameters:
delay- Delay to wait fortimeUnit- TimeUnit to delay for- Throws:
java.util.concurrent.TimeoutException- if the operation times out while waitingjava.lang.InterruptedException- if the operations is interrupted while waitingjava.lang.AssertionError- if any assertion fails while waiting
-
await
public void await(long delay, int expectedResumes) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException- Parameters:
delay- Delay to wait for in millisecondsexpectedResumes- Number of timesresume()is expected to be called before the awaiting thread is resumed- Throws:
java.util.concurrent.TimeoutException- if the operation times out while waitingjava.lang.InterruptedException- if the operations is interrupted while waitingjava.lang.AssertionError- if any assertion fails while waiting
-
await
public void await(long delay, java.util.concurrent.TimeUnit timeUnit, int expectedResumes) throws java.util.concurrent.TimeoutException, java.lang.InterruptedException- Parameters:
delay- Delay to wait fortimeUnit- TimeUnit to delay forexpectedResumes- Number of timesresume()is expected to be called before the awaiting thread is resumed- Throws:
java.util.concurrent.TimeoutException- if the operation times out while waitingjava.lang.InterruptedException- if the operations is interrupted while waitingjava.lang.AssertionError- if any assertion fails while waiting
-
resume
public void resume()
Resumes the waiter when the expected number ofresume()calls have occurred.
-
fail
public void fail()
Fails the current test.- Throws:
java.lang.AssertionError
-
fail
public void fail(java.lang.String reason)
Fails the current test for the givenreason.- Throws:
java.lang.AssertionError
-
fail
public void fail(java.lang.Throwable reason)
Fails the current test with the givenreason, sets the number of expected resumes to 0, and throws thereasonas anAssertionErrorin the main test thread and in the current thread.- Throws:
java.lang.AssertionError- wrapping thereason
-
rethrow
public void rethrow(java.lang.Throwable failure)
Rethrows thefailurein the main test thread and in the current thread. Differs fromfail(Throwable)which wraps a failure in an AssertionError before throwing.- Throws:
java.lang.Throwable- thefailure
-
sneakyThrow
private static void sneakyThrow(java.lang.Throwable t)
-
sneakyThrow2
private static <T extends java.lang.Throwable> void sneakyThrow2(java.lang.Throwable t) throws T extends java.lang.Throwable- Throws:
T extends java.lang.Throwable
-
format
private java.lang.String format(java.lang.Object expected, java.lang.Object actual)
-
-