@Test public void testAddTask() throws Exception { Iterable<TaskState> tasks = queue.getAllTasks(); assertNotNull(tasks); assertTrue(Iterables.isEmpty(tasks)); assertTrue(Iterables.isEmpty(queue.findActiveTasksForApp(123L))); assertTrue(Iterables.isEmpty(queue.findActiveTasksForFeed(123L))); assertNull(queue.findTaskById(123L)); AppFactoryTask task = newSleepyTask(); Long id = task.getCurrentTaskState().getId(); assertNotNull(id); assertTrue(id > 0); queue.addTask(task); TaskState taskState = queue.findTaskById(id); assertNotNull(taskState); assertEquals(id, taskState.getId()); assertTrue(taskState.getQueued() > 0); assertNotNull(taskState.getQueueStatus()); assertTrue(taskState.getQueueStatus().ordinal() >= TaskQueue.MetaStatus.WAITING.ordinal()); assertFalse(Iterables.isEmpty(queue.getAllTasks())); assertTrue(Iterables.isEmpty(queue.findActiveTasksForApp(id))); assertTrue(Iterables.isEmpty(queue.findActiveTasksForFeed(id))); assertTrue(Iterables.isEmpty(queue.findActiveTasksForFeed(123L))); assertEquals(id, queue.getAllTasks().iterator().next().getId()); queue.gracefulShutdown(false); taskState = queue.findTaskById(id); assertNotNull(taskState); assertEquals(TestState.TestStatus.complete, taskState.getStatus()); assertEquals(100, taskState.getProgress()); assertEquals(TaskQueue.MetaStatus.FINISHED, taskState.getQueueStatus()); assertFalse(taskState.isAborted()); assertTrue(factory.resetNumEventsFired() > 0); }
@Override public synchronized void addTask(@Nonnull AppFactoryTask task) { if (!MetaStatus.INIT.equals( (Preconditions.checkNotNull(task).getCurrentTaskState().getQueueStatus())) || (null != taskRecorder.findTaskById(task.getCurrentTaskState().getId())) ) { throw new IllegalArgumentException("Task is already queued"); } executorService.submit(task); taskRecorder.recordTask(task); fireTaskEvent(TaskEvent.newTaskAdded(task.getCurrentTaskState())); }
TaskQueueImpl implements
      TaskQueue,
      ApplicationListener,
      ApplicationEventPublisherAware,
      DisposableBean { @Override public synchronized void addTask(@Nonnull AppFactoryTask task) { if (!MetaStatus.INIT.equals( (Preconditions.checkNotNull(task).getCurrentTaskState().getQueueStatus())) || (null != taskRecorder.findTaskById(task.getCurrentTaskState().getId())) ) { throw new IllegalArgumentException("Task is already queued"); } executorService.submit(task); taskRecorder.recordTask(task); fireTaskEvent(TaskEvent.newTaskAdded(task.getCurrentTaskState())); } }
TaskQueueImpl implements
      TaskQueue,
      ApplicationListener,
      ApplicationEventPublisherAware,
      DisposableBean { @Override public synchronized void addTask(@Nonnull AppFactoryTask task) { if (!MetaStatus.INIT.equals( (Preconditions.checkNotNull(task).getCurrentTaskState().getQueueStatus())) || (null != taskRecorder.findTaskById(task.getCurrentTaskState().getId())) ) { throw new IllegalArgumentException("Task is already queued"); } executorService.submit(task); taskRecorder.recordTask(task); fireTaskEvent(TaskEvent.newTaskAdded(task.getCurrentTaskState())); } TaskQueueImpl(String name,
                 int expectedTasksPerId,
                 Supplier<Integer> maxPoolSizeSupplier,
                 Supplier<Integer> maxFinishedSizeSupplier); }
TaskQueueImpl implements
      TaskQueue,
      ApplicationListener,
      ApplicationEventPublisherAware,
      DisposableBean { @Override public synchronized void addTask(@Nonnull AppFactoryTask task) { if (!MetaStatus.INIT.equals( (Preconditions.checkNotNull(task).getCurrentTaskState().getQueueStatus())) || (null != taskRecorder.findTaskById(task.getCurrentTaskState().getId())) ) { throw new IllegalArgumentException("Task is already queued"); } executorService.submit(task); taskRecorder.recordTask(task); fireTaskEvent(TaskEvent.newTaskAdded(task.getCurrentTaskState())); } TaskQueueImpl(String name,
                 int expectedTasksPerId,
                 Supplier<Integer> maxPoolSizeSupplier,
                 Supplier<Integer> maxFinishedSizeSupplier); @Override synchronized void addTask(@Nonnull AppFactoryTask task); @Nonnull @Override synchronized Iterable<TaskState> getAllTasks(); @Nonnull @Override Iterable<TaskState> getTasks(Predicate<? super TaskState> predicate); @Override int countActiveTasksByDatastoreId(Long datastoreId); @Override @Nullable synchronized TaskState findTaskById(long id); @Nonnull @Override synchronized Iterable<? extends AbstractCaptureState> findActiveTasksForApp(
         final long appId); @Nonnull @Override synchronized Iterable<? extends TaskState> findActiveTasksForFeed(
         final long feedId); @Nullable @Override synchronized TaskState abortTask(long taskId); @Override synchronized boolean moveToHead(long taskIdToMove); @Override synchronized boolean moveToTail(long taskIdToMove); @Override synchronized boolean moveBefore(long taskIdToMove, long taskIdToFollow); @Override synchronized void cleanup(); @Override synchronized boolean cleanup(long taskId); @Nullable @Override synchronized TaskState unstallConversion(long taskId); @Override @Nonnull @VisibleForTesting List<Runnable> gracefulShutdown(boolean abortUnfinishedTasks); @Override synchronized void abortAllTasks(); @Override void destroy(); @Override void onApplicationEvent(ApplicationEvent applicationEvent); @Override void setApplicationEventPublisher(@Nullable ApplicationEventPublisher applicationEventPublisher); }
TaskQueueImpl implements
      TaskQueue,
      ApplicationListener,
      ApplicationEventPublisherAware,
      DisposableBean { @Override public synchronized void addTask(@Nonnull AppFactoryTask task) { if (!MetaStatus.INIT.equals( (Preconditions.checkNotNull(task).getCurrentTaskState().getQueueStatus())) || (null != taskRecorder.findTaskById(task.getCurrentTaskState().getId())) ) { throw new IllegalArgumentException("Task is already queued"); } executorService.submit(task); taskRecorder.recordTask(task); fireTaskEvent(TaskEvent.newTaskAdded(task.getCurrentTaskState())); } TaskQueueImpl(String name,
                 int expectedTasksPerId,
                 Supplier<Integer> maxPoolSizeSupplier,
                 Supplier<Integer> maxFinishedSizeSupplier); @Override synchronized void addTask(@Nonnull AppFactoryTask task); @Nonnull @Override synchronized Iterable<TaskState> getAllTasks(); @Nonnull @Override Iterable<TaskState> getTasks(Predicate<? super TaskState> predicate); @Override int countActiveTasksByDatastoreId(Long datastoreId); @Override @Nullable synchronized TaskState findTaskById(long id); @Nonnull @Override synchronized Iterable<? extends AbstractCaptureState> findActiveTasksForApp(
         final long appId); @Nonnull @Override synchronized Iterable<? extends TaskState> findActiveTasksForFeed(
         final long feedId); @Nullable @Override synchronized TaskState abortTask(long taskId); @Override synchronized boolean moveToHead(long taskIdToMove); @Override synchronized boolean moveToTail(long taskIdToMove); @Override synchronized boolean moveBefore(long taskIdToMove, long taskIdToFollow); @Override synchronized void cleanup(); @Override synchronized boolean cleanup(long taskId); @Nullable @Override synchronized TaskState unstallConversion(long taskId); @Override @Nonnull @VisibleForTesting List<Runnable> gracefulShutdown(boolean abortUnfinishedTasks); @Override synchronized void abortAllTasks(); @Override void destroy(); @Override void onApplicationEvent(ApplicationEvent applicationEvent); @Override void setApplicationEventPublisher(@Nullable ApplicationEventPublisher applicationEventPublisher);  }