@Test public void schedule() throws Exception { CountTask task = new CountTask(); ControllableScheduler scheduler = new ControllableScheduler(); scheduler.schedule(task, 5, TimeUnit.HOURS); assertTrue(scheduler.schedulerIsIdle()); scheduler.jumpAndExecute(5, TimeUnit.HOURS); assertEquals(1, task.runTimes()); }
@Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { ScheduledTask<Void> task = new ScheduledTask<Void>(command); mQueue.add(TimeUnit.MILLISECONDS.convert(delay, unit), task); return task; }
ControllableScheduler implements ScheduledExecutorService { @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { ScheduledTask<Void> task = new ScheduledTask<Void>(command); mQueue.add(TimeUnit.MILLISECONDS.convert(delay, unit), task); return task; } }
ControllableScheduler implements ScheduledExecutorService { @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { ScheduledTask<Void> task = new ScheduledTask<Void>(command); mQueue.add(TimeUnit.MILLISECONDS.convert(delay, unit), task); return task; }  }
ControllableScheduler implements ScheduledExecutorService { @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { ScheduledTask<Void> task = new ScheduledTask<Void>(command); mQueue.add(TimeUnit.MILLISECONDS.convert(delay, unit), task); return task; }  void jumpAndExecute(long duration, TimeUnit timeUnit); boolean schedulerIsIdle(); void runNextPendingCommand(); @Override void execute(Runnable command); @Override ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit); @Override ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit); @Override ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
      long initialDelay, long period, TimeUnit unit); @Override ScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
      long initialDelay, long delay, TimeUnit unit); @Override Future<T> submit(Callable<T> callable); @Override Future<?> submit(Runnable command); @Override Future<T> submit(Runnable command, T result); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks); @Override List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
      long timeout, TimeUnit unit); @Override T invokeAny(Collection<? extends Callable<T>> tasks); @Override T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit); @Override boolean isShutdown(); @Override boolean isTerminated(); @Override void shutdown(); @Override List<Runnable> shutdownNow(); }
ControllableScheduler implements ScheduledExecutorService { @Override public ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit) { ScheduledTask<Void> task = new ScheduledTask<Void>(command); mQueue.add(TimeUnit.MILLISECONDS.convert(delay, unit), task); return task; }  void jumpAndExecute(long duration, TimeUnit timeUnit); boolean schedulerIsIdle(); void runNextPendingCommand(); @Override void execute(Runnable command); @Override ScheduledFuture<?> schedule(Runnable command, long delay, TimeUnit unit); @Override ScheduledFuture<V> schedule(Callable<V> callable, long delay, TimeUnit unit); @Override ScheduledFuture<?> scheduleAtFixedRate(Runnable command,
      long initialDelay, long period, TimeUnit unit); @Override ScheduledFuture<?> scheduleWithFixedDelay(Runnable command,
      long initialDelay, long delay, TimeUnit unit); @Override Future<T> submit(Callable<T> callable); @Override Future<?> submit(Runnable command); @Override Future<T> submit(Runnable command, T result); @Override boolean awaitTermination(long timeout, TimeUnit unit); @Override List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks); @Override List<Future<T>> invokeAll(Collection<? extends Callable<T>> tasks,
      long timeout, TimeUnit unit); @Override T invokeAny(Collection<? extends Callable<T>> tasks); @Override T invokeAny(Collection<? extends Callable<T>> tasks, long timeout, TimeUnit unit); @Override boolean isShutdown(); @Override boolean isTerminated(); @Override void shutdown(); @Override List<Runnable> shutdownNow();  }