StateManagerImpl implements StateManager { @Override public void deleteTasks(MutableStoreProvider storeProvider, final Set<String> taskIds) { Map<String, IScheduledTask> tasks = Maps.uniqueIndex( storeProvider.getTaskStore().fetchTasks(Query.taskScoped(taskIds)), Tasks::id); for (Map.Entry<String, IScheduledTask> entry : tasks.entrySet()) { updateTaskAndExternalState( storeProvider.getUnsafeTaskStore(), entry.getKey(), Optional.of(entry.getValue()), Optional.absent(), Optional.absent()); } } @Inject  StateManagerImpl(
      final Clock clock,
      Driver driver,
      TaskIdGenerator taskIdGenerator,
      EventSink eventSink,
      RescheduleCalculator rescheduleCalculator); @Override void insertPendingTasks(
      MutableStoreProvider storeProvider,
      final ITaskConfig task,
      Set<Integer> instanceIds); @Override StateChangeResult changeState(
      MutableStoreProvider storeProvider,
      String taskId,
      Optional<ScheduleStatus> casState,
      final ScheduleStatus newState,
      final Optional<String> auditMessage); @Override IAssignedTask assignTask(
      MutableStoreProvider storeProvider,
      String taskId,
      String slaveHost,
      SlaveID slaveId,
      Map<String, Integer> assignedPorts); @Override void deleteTasks(MutableStoreProvider storeProvider, final Set<String> taskIds);  }
@Test public void testDeleteTasks() { final String taskId = "a"; expect(taskIdGenerator.generate(NON_SERVICE_CONFIG, 0)).andReturn(taskId); expectStateTransitions(taskId, INIT, PENDING, ASSIGNED, RUNNING, FINISHED); eventSink.post(matchTasksDeleted(taskId)); control.replay(); insertTask(NON_SERVICE_CONFIG, 0); assignTask(taskId, HOST_A); changeState(taskId, RUNNING); changeState(taskId, FINISHED); storage.write((NoResult.Quiet) storeProvider -> stateManager.deleteTasks(storeProvider, ImmutableSet.of(taskId))); }