@Test
  public void testStaleAlertFromAgent() {
    Long alertDefinitionId = 1L;

    // create current alerts that are not stale
    AlertDefinitionEntity definition = new AlertDefinitionEntity();
    definition.setClusterId(CLUSTER_ID);
    definition.setDefinitionName("foo-definition");
    definition.setServiceName("HDFS");
    definition.setComponentName("NAMENODE");
    definition.setEnabled(true);
    definition.setScheduleInterval(1);

    // create current alerts that are stale
    AlertCurrentEntity current1 = createNiceMock(AlertCurrentEntity.class);
    AlertHistoryEntity history1 = createNiceMock(AlertHistoryEntity.class);

    expect(current1.getAlertHistory()).andReturn(history1).atLeastOnce();
    expect(current1.getDefinitionId()).andReturn(alertDefinitionId).atLeastOnce();
    expect(history1.getAlertDefinition()).andReturn(definition).atLeastOnce();
    expect(history1.getHostName()).andReturn("host1").atLeastOnce();

    reset(m_alertHelper);
    expect(m_alertHelper.getWaitFactorMultiplier(anyObject(AlertDefinition.class))).andReturn(2).anyTimes();
    expect(m_alertHelper.getStaleAlerts(anyLong())).andReturn(Collections.singletonMap(alertDefinitionId, 0L)).atLeastOnce();

    expect(current1.getMaintenanceState()).andReturn(MaintenanceState.OFF).atLeastOnce();
    expect(current1.getLatestTimestamp()).andReturn(System.currentTimeMillis()).atLeastOnce();

    replay(current1, history1, m_alertHelper);

    m_currentAlerts.add(current1);

    // precondition that no events were fired
    assertEquals(0,
        m_listener.getAlertEventReceivedCount(AlertReceivedEvent.class));

    // instantiate and inject mocks
    StaleAlertRunnable runnable = new StaleAlertRunnable(m_definition.getDefinitionName());
    m_injector.injectMembers(runnable);

    // run the alert
    runnable.run();

    checkSingleEventToState(AlertState.CRITICAL);

    verify(m_cluster, m_clusters, m_definitionDao, m_alertHelper);
  }
Tests that a stale message from agent triggers the event with a status of CRITICAL.
ambari-server/src/test/java/org/apache/ambari/server/alerts/StaleAlertRunnableTest.java