@Test
  public void testStaleAlertHeartbeatLost() {
    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();

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

    reset(m_cluster, m_host);
    m_host = createNiceMock(Host.class);
    expect(m_host.getHostId()).andReturn(1L);
    expect(m_host.getState()).andReturn(HostState.HEARTBEAT_LOST);

    expect(m_cluster.getClusterId()).andReturn(CLUSTER_ID).atLeastOnce();
    expect(m_cluster.getHost(anyString())).andReturn(m_host).anyTimes();

    replay(current1, history1, m_host, m_cluster);

    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);
  }
<AlertCurrentEntity> currentAlerts = m_alertsDao.findCurrentByCluster(
        cluster.getClusterId());

    long now = System.currentTimeMillis();

    Map<Long, List<Long>> alertDefinitionsToHosts = prepareHostDefinitions(cluster.getClusterId());
Tests that a heartbeat loose triggers the event with a status of CRITICAL.
ambari-server/src/test/java/org/apache/ambari/server/alerts/StaleAlertRunnableTest.java