@Beta public abstract class AbstractListenableFutureTest extends TestCase
Abstract test case parent for anything implementing ListenableFuture. Tests the two get methods and the addListener method.
| Modifier and Type | Field and Description |
|---|---|
protected com.diffplug.common.util.concurrent.ListenableFuture<Boolean> |
future |
protected CountDownLatch |
latch |
| Constructor and Description |
|---|
AbstractListenableFutureTest() |
| Modifier and Type | Method and Description |
|---|---|
protected abstract <V> com.diffplug.common.util.concurrent.ListenableFuture<V> |
createListenableFuture(V value,
Exception except,
CountDownLatch waitOn)
Constructs a listenable future with a value available after the latch has counted down.
|
protected void |
setUp() |
protected void |
tearDown() |
void |
testAllListenersCompleteSuccessfully()
Tests that all listeners complete, even if they were added before or after the future was finishing.
|
void |
testCanceledFutureThrowsCancellation()
Tests that a canceled future throws a cancellation exception.
|
void |
testGetBlocksUntilValueAvailable()
Tests that the
Future.get() method blocks until a value is available. |
void |
testListenersNotifiedOnError() |
void |
testTimeoutOnGetWorksCorrectly()
Tests that the
Future.get(long, TimeUnit) method times out correctly. |
assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertEquals, assertFalse, assertFalse, assertNotNull, assertNotNull, assertNotSame, assertNotSame, assertNull, assertNull, assertSame, assertSame, assertTrue, assertTrue, countTestCases, createResult, fail, fail, failNotEquals, failNotSame, failSame, format, getName, run, run, runBare, runTest, setName, toStringprotected CountDownLatch latch
protected com.diffplug.common.util.concurrent.ListenableFuture<Boolean> future
protected void tearDown()
throws Exception
protected abstract <V> com.diffplug.common.util.concurrent.ListenableFuture<V> createListenableFuture(V value, Exception except, CountDownLatch waitOn)
Constructs a listenable future with a value available after the latch has counted down.
public void testGetBlocksUntilValueAvailable()
throws Throwable
Tests that the Future.get() method blocks until a value is available.
Throwablepublic void testTimeoutOnGetWorksCorrectly()
throws InterruptedException,
ExecutionException
Tests that the Future.get(long, TimeUnit) method times out correctly.
public void testCanceledFutureThrowsCancellation()
throws Exception
Tests that a canceled future throws a cancellation exception.
This method checks the cancel, isCancelled, and isDone methods.
Exceptionpublic void testListenersNotifiedOnError()
throws Exception
Exceptionpublic void testAllListenersCompleteSuccessfully()
throws InterruptedException,
ExecutionException
Tests that all listeners complete, even if they were added before or after the future was finishing. Also acts as a concurrency test to make sure the locking is done correctly when a future is finishing so that no listeners can be lost.