Class AbstractListenableFutureTest
- java.lang.Object
-
- junit.framework.Assert
-
- junit.framework.TestCase
-
- com.google.common.util.concurrent.testing.AbstractListenableFutureTest
-
- All Implemented Interfaces:
junit.framework.Test
@GwtIncompatible public abstract class AbstractListenableFutureTest extends junit.framework.TestCase
Abstract test case parent for anything implementingListenableFuture. Tests the two get methods and the addListener method.- Since:
- 10.0
- Author:
- Sven Mawson
-
-
Field Summary
Fields Modifier and Type Field Description protected com.google.common.util.concurrent.ListenableFuture<Boolean>futureprotected CountDownLatchlatch
-
Constructor Summary
Constructors Constructor Description AbstractListenableFutureTest()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected abstract <V> com.google.common.util.concurrent.ListenableFuture<V>createListenableFuture(V value, @Nullable Exception except, CountDownLatch waitOn)Constructs a listenable future with a value available after the latch has counted down.protected voidsetUp()protected voidtearDown()voidtestAllListenersCompleteSuccessfully()Tests that all listeners complete, even if they were added before or after the future was finishing.voidtestCanceledFutureThrowsCancellation()Tests that a canceled future throws a cancellation exception.voidtestGetBlocksUntilValueAvailable()Tests that theFuture.get()method blocks until a value is available.voidtestListenersNotifiedOnError()voidtestTimeoutOnGetWorksCorrectly()Tests that theFuture.get(long, TimeUnit)method times out correctly.-
Methods inherited from class junit.framework.TestCase
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, toString
-
-
-
-
Field Detail
-
latch
protected CountDownLatch latch
-
-
Constructor Detail
-
AbstractListenableFutureTest
public AbstractListenableFutureTest()
-
-
Method Detail
-
setUp
protected void setUp() throws Exception
- Overrides:
setUpin classjunit.framework.TestCase- Throws:
Exception
-
tearDown
protected void tearDown() throws Exception
- Overrides:
tearDownin classjunit.framework.TestCase- Throws:
Exception
-
createListenableFuture
protected abstract <V> com.google.common.util.concurrent.ListenableFuture<V> createListenableFuture(V value, @Nullable Exception except, CountDownLatch waitOn)
Constructs a listenable future with a value available after the latch has counted down.
-
testGetBlocksUntilValueAvailable
public void testGetBlocksUntilValueAvailable() throws Throwable
Tests that theFuture.get()method blocks until a value is available.- Throws:
Throwable
-
testTimeoutOnGetWorksCorrectly
public void testTimeoutOnGetWorksCorrectly() throws InterruptedException, ExecutionException
Tests that theFuture.get(long, TimeUnit)method times out correctly.
-
testCanceledFutureThrowsCancellation
public void testCanceledFutureThrowsCancellation() throws Exception
Tests that a canceled future throws a cancellation exception.This method checks the cancel, isCancelled, and isDone methods.
- Throws:
Exception
-
testListenersNotifiedOnError
public void testListenersNotifiedOnError() throws Exception
- Throws:
Exception
-
testAllListenersCompleteSuccessfully
public 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.
-
-