Class AbstractListenableFutureTest

  • All Implemented Interfaces:
    junit.framework.Test
    Direct Known Subclasses:
    AbstractCheckedFutureTest

    @Beta
    @GwtIncompatible
    public abstract class AbstractListenableFutureTest
    extends junit.framework.TestCase
    Abstract test case parent for anything implementing ListenableFuture. Tests the two get methods and the addListener method.
    Since:
    10.0
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected ListenableFuture<java.lang.Boolean> future  
      protected java.util.concurrent.CountDownLatch latch  
    • Method Summary

      All Methods Instance Methods Abstract Methods Concrete Methods 
      Modifier and Type Method Description
      protected abstract <V> ListenableFuture<V> createListenableFuture​(V value, java.lang.Exception except, java.util.concurrent.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.
      • 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
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • latch

        protected java.util.concurrent.CountDownLatch latch
    • Constructor Detail

      • AbstractListenableFutureTest

        public AbstractListenableFutureTest()
    • Method Detail

      • setUp

        protected void setUp()
                      throws java.lang.Exception
        Overrides:
        setUp in class junit.framework.TestCase
        Throws:
        java.lang.Exception
      • tearDown

        protected void tearDown()
                         throws java.lang.Exception
        Overrides:
        tearDown in class junit.framework.TestCase
        Throws:
        java.lang.Exception
      • createListenableFuture

        protected abstract <V> ListenableFuture<V> createListenableFuture​(V value,
                                                                          java.lang.Exception except,
                                                                          java.util.concurrent.CountDownLatch waitOn)
        Constructs a listenable future with a value available after the latch has counted down.
      • testGetBlocksUntilValueAvailable

        public void testGetBlocksUntilValueAvailable()
                                              throws java.lang.Throwable
        Tests that the Future.get() method blocks until a value is available.
        Throws:
        java.lang.Throwable
      • testTimeoutOnGetWorksCorrectly

        public void testTimeoutOnGetWorksCorrectly()
                                            throws java.lang.InterruptedException,
                                                   java.util.concurrent.ExecutionException
        Tests that the Future.get(long, TimeUnit) method times out correctly.
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • testCanceledFutureThrowsCancellation

        public void testCanceledFutureThrowsCancellation()
                                                  throws java.lang.Exception
        Tests that a canceled future throws a cancellation exception. This method checks the cancel, isCancelled, and isDone methods.
        Throws:
        java.lang.Exception
      • testListenersNotifiedOnError

        public void testListenersNotifiedOnError()
                                          throws java.lang.Exception
        Throws:
        java.lang.Exception
      • testAllListenersCompleteSuccessfully

        public void testAllListenersCompleteSuccessfully()
                                                  throws java.lang.InterruptedException,
                                                         java.util.concurrent.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.
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException