### Question:
SqlTask { public TaskInfo cancel() { taskStateMachine.cancel(); return getTaskInfo(); } private  SqlTask(
            TaskId taskId,
            URI location,
            String nodeId,
            QueryContext queryContext,
            SqlTaskExecutionFactory sqlTaskExecutionFactory,
            ExecutorService taskNotificationExecutor,
            DataSize maxBufferSize); static SqlTask createSqlTask(
            TaskId taskId,
            URI location,
            String nodeId,
            QueryContext queryContext,
            SqlTaskExecutionFactory sqlTaskExecutionFactory,
            ExecutorService taskNotificationExecutor,
            Function<SqlTask, ?> onDone,
            DataSize maxBufferSize,
            CounterStat failedTasks); boolean isOutputBufferOverutilized(); SqlTaskIoStats getIoStats(); TaskId getTaskId(); String getTaskInstanceId(); void recordHeartbeat(); TaskInfo getTaskInfo(); TaskStatus getTaskStatus(); VersionedDynamicFilterDomains acknowledgeAndGetNewDynamicFilterDomains(long callersDynamicFiltersVersion); synchronized ListenableFuture<TaskStatus> getTaskStatus(long callersCurrentVersion); synchronized ListenableFuture<TaskInfo> getTaskInfo(long callersCurrentVersion); TaskInfo updateTask(Session session, Optional<PlanFragment> fragment, List<TaskSource> sources, OutputBuffers outputBuffers, OptionalInt totalPartitions); ListenableFuture<BufferResult> getTaskResults(OutputBufferId bufferId, long startingSequenceId, DataSize maxSize); void acknowledgeTaskResults(OutputBufferId bufferId, long sequenceId); TaskInfo abortTaskResults(OutputBufferId bufferId); void failed(Throwable cause); TaskInfo cancel(); TaskInfo abort(); @Override String toString(); void addStateChangeListener(StateChangeListener<TaskState> stateChangeListener); QueryContext getQueryContext();  }### Answer:
@Test public void testCancel() { SqlTask sqlTask = createInitialTask(); TaskInfo taskInfo = sqlTask.updateTask(TEST_SESSION, Optional.of(PLAN_FRAGMENT), ImmutableList.of(), createInitialEmptyOutputBuffers(PARTITIONED) .withBuffer(OUT, 0) .withNoMoreBufferIds(), OptionalInt.empty()); assertEquals(taskInfo.getTaskStatus().getState(), TaskState.RUNNING); assertNull(taskInfo.getStats().getEndTime()); taskInfo = sqlTask.getTaskInfo(); assertEquals(taskInfo.getTaskStatus().getState(), TaskState.RUNNING); assertNull(taskInfo.getStats().getEndTime()); taskInfo = sqlTask.cancel(); assertEquals(taskInfo.getTaskStatus().getState(), TaskState.CANCELED); assertNotNull(taskInfo.getStats().getEndTime()); taskInfo = sqlTask.getTaskInfo(); assertEquals(taskInfo.getTaskStatus().getState(), TaskState.CANCELED); assertNotNull(taskInfo.getStats().getEndTime()); }