Class FakeScheduledExecutor

  • All Implemented Interfaces:
    java.util.concurrent.Executor, java.util.concurrent.ExecutorService, java.util.concurrent.ScheduledExecutorService, FakeClock.TimeListener

    public class FakeScheduledExecutor
    extends java.lang.Object
    implements java.util.concurrent.ScheduledExecutorService, FakeClock.TimeListener
    A scheduled executor that uses a fake clock as back-bone to the executor. To trigger the executions, call FakeClock.tick(long) on the fake clock.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean awaitTermination​(long l, java.util.concurrent.TimeUnit timeUnit)  
      void execute​(java.lang.Runnable runnable)  
      <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(java.util.Collection<? extends java.util.concurrent.Callable<T>> collection)  
      <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(java.util.Collection<? extends java.util.concurrent.Callable<T>> collection, long l, java.util.concurrent.TimeUnit timeUnit)  
      <T> T invokeAny​(java.util.Collection<? extends java.util.concurrent.Callable<T>> collection)  
      <T> T invokeAny​(java.util.Collection<? extends java.util.concurrent.Callable<T>> collection, long l, java.util.concurrent.TimeUnit timeUnit)  
      boolean isShutdown()  
      boolean isTerminated()  
      void newCurrentTimeUTC​(long millis)  
      net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeTask<?> schedule​(java.lang.Runnable runnable, long l, java.util.concurrent.TimeUnit timeUnit)  
      <V> net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeTask<V> schedule​(java.util.concurrent.Callable<V> callable, long delay, java.util.concurrent.TimeUnit timeUnit)  
      net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeRecurringTask scheduleAtFixedRate​(java.lang.Runnable runnable, long initialDelay, long period, java.util.concurrent.TimeUnit timeUnit)  
      net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeRecurringTask scheduleWithFixedDelay​(java.lang.Runnable runnable, long initialDelay, long delay, java.util.concurrent.TimeUnit timeUnit)  
      void shutdown()  
      java.util.List<java.lang.Runnable> shutdownNow()  
      net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeTask<?> submit​(java.lang.Runnable runnable)  
      <T> net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeTask<T> submit​(java.lang.Runnable runnable, T t)  
      <T> net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeTask<T> submit​(java.util.concurrent.Callable<T> callable)  
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Constructor Detail

      • FakeScheduledExecutor

        public FakeScheduledExecutor​(@Nonnull
                                     FakeClock clock)
    • Method Detail

      • schedule

        @Nonnull
        public net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeTask<?> schedule​(@Nonnull
                                                                                           java.lang.Runnable runnable,
                                                                                           long l,
                                                                                           @Nonnull
                                                                                           java.util.concurrent.TimeUnit timeUnit)
        Specified by:
        schedule in interface java.util.concurrent.ScheduledExecutorService
      • schedule

        @Nonnull
        public <V> net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeTask<V> schedule​(@Nonnull
                                                                                               java.util.concurrent.Callable<V> callable,
                                                                                               long delay,
                                                                                               @Nonnull
                                                                                               java.util.concurrent.TimeUnit timeUnit)
        Specified by:
        schedule in interface java.util.concurrent.ScheduledExecutorService
      • scheduleAtFixedRate

        @Nonnull
        public net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeRecurringTask scheduleAtFixedRate​(@Nonnull
                                                                                                            java.lang.Runnable runnable,
                                                                                                            long initialDelay,
                                                                                                            long period,
                                                                                                            @Nonnull
                                                                                                            java.util.concurrent.TimeUnit timeUnit)
        Specified by:
        scheduleAtFixedRate in interface java.util.concurrent.ScheduledExecutorService
      • scheduleWithFixedDelay

        @Nonnull
        public net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeRecurringTask scheduleWithFixedDelay​(@Nonnull
                                                                                                               java.lang.Runnable runnable,
                                                                                                               long initialDelay,
                                                                                                               long delay,
                                                                                                               @Nonnull
                                                                                                               java.util.concurrent.TimeUnit timeUnit)
        Specified by:
        scheduleWithFixedDelay in interface java.util.concurrent.ScheduledExecutorService
      • shutdown

        public void shutdown()
        Specified by:
        shutdown in interface java.util.concurrent.ExecutorService
      • shutdownNow

        @Nonnull
        public java.util.List<java.lang.Runnable> shutdownNow()
        Specified by:
        shutdownNow in interface java.util.concurrent.ExecutorService
      • isShutdown

        public boolean isShutdown()
        Specified by:
        isShutdown in interface java.util.concurrent.ExecutorService
      • isTerminated

        public boolean isTerminated()
        Specified by:
        isTerminated in interface java.util.concurrent.ExecutorService
      • awaitTermination

        public boolean awaitTermination​(long l,
                                        @Nonnull
                                        java.util.concurrent.TimeUnit timeUnit)
                                 throws java.lang.InterruptedException
        Specified by:
        awaitTermination in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • submit

        @Nonnull
        public <T> net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeTask<T> submit​(@Nonnull
                                                                                             java.util.concurrent.Callable<T> callable)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • submit

        @Nonnull
        public <T> net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeTask<T> submit​(@Nonnull
                                                                                             java.lang.Runnable runnable,
                                                                                             T t)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • submit

        @Nonnull
        public net.morimekta.testing.concurrent.FakeScheduledExecutor.FakeTask<?> submit​(@Nonnull
                                                                                         java.lang.Runnable runnable)
        Specified by:
        submit in interface java.util.concurrent.ExecutorService
      • invokeAll

        @Nonnull
        public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(@Nonnull
                                                                            java.util.Collection<? extends java.util.concurrent.Callable<T>> collection)
                                                                     throws java.lang.InterruptedException
        Specified by:
        invokeAll in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • invokeAll

        @Nonnull
        public <T> java.util.List<java.util.concurrent.Future<T>> invokeAll​(@Nonnull
                                                                            java.util.Collection<? extends java.util.concurrent.Callable<T>> collection,
                                                                            long l,
                                                                            @Nonnull
                                                                            java.util.concurrent.TimeUnit timeUnit)
                                                                     throws java.lang.InterruptedException
        Specified by:
        invokeAll in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
      • invokeAny

        @Nonnull
        public <T> T invokeAny​(@Nonnull
                               java.util.Collection<? extends java.util.concurrent.Callable<T>> collection)
                        throws java.lang.InterruptedException,
                               java.util.concurrent.ExecutionException
        Specified by:
        invokeAny in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
      • invokeAny

        public <T> T invokeAny​(@Nonnull
                               java.util.Collection<? extends java.util.concurrent.Callable<T>> collection,
                               long l,
                               @Nonnull
                               java.util.concurrent.TimeUnit timeUnit)
                        throws java.lang.InterruptedException,
                               java.util.concurrent.ExecutionException,
                               java.util.concurrent.TimeoutException
        Specified by:
        invokeAny in interface java.util.concurrent.ExecutorService
        Throws:
        java.lang.InterruptedException
        java.util.concurrent.ExecutionException
        java.util.concurrent.TimeoutException
      • execute

        public void execute​(@Nonnull
                            java.lang.Runnable runnable)
        Specified by:
        execute in interface java.util.concurrent.Executor