@Test
  public void testHeartBeatWithAlertAndInvalidCluster() throws Exception {
    ActionManager am = actionManagerTestHelper.getMockActionManager();

    expect(am.getTasks(EasyMock.<List<Long>>anyObject())).andReturn(new ArrayList<>());

    replay(am);

    Cluster cluster = heartbeatTestHelper.getDummyCluster();
    Clusters fsm = clusters;
    Host hostObject = clusters.getHost(DummyHostname1);
    hostObject.setIPv4("ipv4");
    hostObject.setIPv6("ipv6");
    hostObject.setOsType(DummyOsType);

    HeartBeatHandler handler = new HeartBeatHandler(config, fsm, am, Encryptor.NONE, injector);
    Register reg = new Register();
    HostInfo hi = new HostInfo();
    hi.setHostName(DummyHostname1);
    hi.setOS(DummyOs);
    hi.setOSRelease(DummyOSRelease);
    reg.setHostname(DummyHostname1);
    reg.setHardwareProfile(hi);
    reg.setAgentVersion(metaInfo.getServerVersion());
    handler.handleRegistration(reg);

    hostObject.setState(HostState.UNHEALTHY);

    ExecutionCommand execCmd = new ExecutionCommand();
    execCmd.setRequestAndStage(2, 34);
    execCmd.setHostname(DummyHostname1);
    //aq.enqueue(DummyHostname1, new ExecutionCommand());

    HeartBeat hb = new HeartBeat();
    HostStatus hs = new HostStatus(HostStatus.Status.HEALTHY, DummyHostStatus);

    hb.setResponseId(0);
    hb.setNodeStatus(hs);
    hb.setHostname(DummyHostname1);

    Alert alert = new Alert("foo", "bar", "baz", "foobar", "foobarbaz",
        AlertState.OK);

    alert.setClusterId(-1L);

    List<Alert> alerts = Collections.singletonList(alert);
    hb.setAlerts(alerts);

    // should NOT throw AmbariException from alerts.
    handler.getHeartbeatProcessor().processHeartbeat(hb);
  }
Tests that if there is an invalid cluster in heartbeat data, the heartbeat
doesn't fail.

@throws Exception
ambari-server/src/test/java/org/apache/ambari/server/agent/HeartbeatProcessorTest.java