private void testTimeoutRequest(RoleCommand roleCommand, boolean stageSupportsAutoSkip,
      boolean autoSkipFailedTask) throws AmbariException, InvalidStateTransitionException {
    final long HOST_REGISTRATION_TIME = 100L;
    final long STAGE_TASK_START_TIME = HOST_REGISTRATION_TIME - 1L;

    Clusters fsm = EasyMock.createMock(Clusters.class);
    Cluster cluster = EasyMock.createMock(Cluster.class);
    Service service = EasyMock.createMock(Service.class);
    ServiceComponent serviceComponent = EasyMock.createMock(ServiceComponent.class);
    ServiceComponentHost serviceComponentHost = EasyMock.createMock(ServiceComponentHost.class);
    Host host = EasyMock.createMock(Host.class);
    ActionDBAccessor db = EasyMock.createMock(ActionDBAccessor.class);
    AmbariEventPublisher ambariEventPublisher = EasyMock.createMock(AmbariEventPublisher.class);
    AgentCommandsPublisher agentCommandsPublisher = EasyMock.createStrictMock(AgentCommandsPublisher.class);

    EasyMock.expect(fsm.getCluster(EasyMock.anyString())).andReturn(cluster).anyTimes();
    EasyMock.expect(fsm.getHost(EasyMock.anyString())).andReturn(host);
    EasyMock.expect(cluster.getService(EasyMock.anyString())).andReturn(null);
    EasyMock.expect(host.getHostName()).andReturn(Stage.INTERNAL_HOSTNAME).anyTimes();

    if (RoleCommand.ACTIONEXECUTE.equals(roleCommand)) {
      EasyMock.expect(cluster.getClusterName()).andReturn("clusterName").anyTimes();
      EasyMock.expect(cluster.getClusterId()).andReturn(1L);

      ambariEventPublisher.publish(EasyMock.anyObject(AmbariEvent.class));
      EasyMock.expectLastCall();
    } else if (RoleCommand.EXECUTE.equals(roleCommand)) {
      EasyMock.expect(cluster.getClusterName()).andReturn("clusterName");
      EasyMock.expect(cluster.getService(EasyMock.anyString())).andReturn(service);
      EasyMock.expect(service.getServiceComponent(EasyMock.anyString())).andReturn(serviceComponent);
      EasyMock.expect(serviceComponent.getServiceComponentHost(EasyMock.anyString())).andReturn(serviceComponentHost);

      serviceComponentHost.handleEvent(EasyMock.anyObject(ServiceComponentHostEvent.class));
      EasyMock.expectLastCall();
    }

    Stage s = getStageWithServerAction(1, 977, null, "test", 2, stageSupportsAutoSkip, autoSkipFailedTask);
    s.setStartTime(null, Role.AMBARI_SERVER_ACTION.toString(), STAGE_TASK_START_TIME);
    s.setHostRoleStatus(null, Role.AMBARI_SERVER_ACTION.toString(), HostRoleStatus.IN_PROGRESS);
    s.getExecutionCommands(null).get(0).getExecutionCommand().setServiceName("Service name");
    s.getExecutionCommands(null).get(0).getExecutionCommand().setRoleCommand(roleCommand);

    //aq.enqueue(Stage.INTERNAL_HOSTNAME, s.getExecutionCommands(null).get(0).getExecutionCommand());
    List<ExecutionCommand> commandsToSchedule = new ArrayList<>();
    Multimap<Long, AgentCommand> commandsToEnqueue = ArrayListMultimap.create();

    boolean taskShouldBeSkipped = stageSupportsAutoSkip && autoSkipFailedTask;
    db.timeoutHostRole(EasyMock.anyString(), EasyMock.anyLong(), EasyMock.anyLong(),
        EasyMock.anyString(), EasyMock.eq(taskShouldBeSkipped), EasyMock.anyBoolean());

    EasyMock.expectLastCall();

    ActionScheduler scheduler = EasyMock.createMockBuilder(ActionScheduler.class)
      .withConstructor(long.class, long.class, ActionDBAccessor.class, Clusters.class, int.class,
            HostsMap.class, UnitOfWork.class, AmbariEventPublisher.class, Configuration.class,
            Provider.class, HostRoleCommandDAO.class, HostRoleCommandFactory.class,AgentCommandsPublisher.class)
        .withArgs(100L, 50L, db, fsm, -1, null, null, ambariEventPublisher, null,
            entityManagerProviderMock, mock(HostRoleCommandDAO.class),
            mock(HostRoleCommandFactory.class), agentCommandsPublisher)
      .createNiceMock();

    EasyMock.replay(scheduler, fsm, host, db, cluster, ambariEventPublisher, service, serviceComponent,
        serviceComponentHost, agentCommandsPublisher);

    scheduler.processInProgressStage(s, commandsToSchedule, commandsToEnqueue);

    EasyMock.verify(scheduler, fsm, host, db, cluster, ambariEventPublisher, service, serviceComponent,
        serviceComponentHost, agentCommandsPublisher);
  }
Ensures that the task is timed out and that it will be skipped.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java