private List<AgentCommand> waitForQueueSize(Long hostId, AgentCommandsPublisher agentCommandsPublisher,
                                              int expectedQueueSize, ActionScheduler scheduler) throws AmbariException {
    AtomicLongMap<Long> callCounterByHost = AtomicLongMap.create(new HashMap<Long, Long>());
    AtomicInteger methodCallCounter = new AtomicInteger(0);
    ArgumentCaptor<Multimap<Long, AgentCommand>> executionCommandCaptor = ArgumentCaptor.forClass((Class) Multimap.class);
    int counter = 0;
    resetAgentCommandPublisherMock(agentCommandsPublisher, callCounterByHost, methodCallCounter);
    while (counter++ <= MAX_CYCLE_ITERATIONS) {
      long callsCount = callCounterByHost.get(hostId);
      if (callsCount == expectedQueueSize) {
        verify(agentCommandsPublisher, times(methodCallCounter.get()))
            .sendAgentCommand(executionCommandCaptor.capture());
        Multimap<Long, AgentCommand> scheduledCommands = executionCommandCaptor.getValue();
        return new ArrayList<>(scheduledCommands.asMap().get(hostId));
      } else if (callsCount > expectedQueueSize) {
        Assert.fail("Expected size : " + expectedQueueSize + " Actual size="
            + counter);
      }
      try {
        scheduler.doWork();
      } catch (AmbariException e) {
        Assert.fail("Ambari exception : " + e.getMessage() + e.getStackTrace());
      }
    }
    return null;
  }
This test sends a new action to the action scheduler and verifies that the action
shows up in the action queue.
ambari-server/src/test/java/org/apache/ambari/server/actionmanager/TestActionScheduler.java