HeartBeatHandler { public ComponentsResponse handleComponents(String clusterName) throws AmbariException { ComponentsResponse response = new ComponentsResponse(); Cluster cluster = clusterFsm.getCluster(clusterName); StackId stackId = cluster.getCurrentStackVersion(); if (stackId == null) { throw new AmbariException("Cannot provide stack components map. " + "Stack hasn't been selected yet."); } StackInfo stack = ambariMetaInfo.getStack(stackId.getStackName(), stackId.getStackVersion()); response.setClusterName(clusterName); response.setStackName(stackId.getStackName()); response.setStackVersion(stackId.getStackVersion()); response.setComponents(getComponentsMap(stack)); return response; } @Inject  HeartBeatHandler(Clusters fsm, ActionQueue aq, ActionManager am,
                          Injector injector); void start(); void setHeartbeatProcessor(HeartbeatProcessor heartbeatProcessor); HeartbeatProcessor getHeartbeatProcessor(); HeartBeatResponse handleHeartBeat(HeartBeat heartbeat); String getOsType(String os, String osRelease); RegistrationResponse handleRegistration(Register register); ComponentsResponse handleComponents(String clusterName); void stop();  }
@Test public void testComponents() throws Exception, InvalidStateTransitionException { ComponentsResponse expected = new ComponentsResponse(); StackId dummyStackId = new StackId(DummyStackId); Map<String, Map<String, String>> dummyComponents = new HashMap<String, Map<String, String>>(); Map<String, String> dummyCategoryMap = new HashMap<String, String>(); dummyCategoryMap.put("PIG", "CLIENT"); dummyComponents.put("PIG", dummyCategoryMap); dummyCategoryMap = new HashMap<String, String>(); dummyCategoryMap.put("MAPREDUCE_CLIENT", "CLIENT"); dummyCategoryMap.put("JOBTRACKER", "MASTER"); dummyCategoryMap.put("TASKTRACKER", "SLAVE"); dummyComponents.put("MAPREDUCE", dummyCategoryMap); dummyCategoryMap = new HashMap<String, String>(); dummyCategoryMap.put("DATANODE2", "SLAVE"); dummyCategoryMap.put("NAMENODE", "MASTER"); dummyCategoryMap.put("HDFS_CLIENT", "CLIENT"); dummyCategoryMap.put("DATANODE1", "SLAVE"); dummyCategoryMap.put("SECONDARY_NAMENODE", "MASTER"); dummyCategoryMap.put("DATANODE", "SLAVE"); dummyComponents.put("HDFS", dummyCategoryMap); expected.setClusterName(DummyCluster); expected.setStackName(dummyStackId.getStackName()); expected.setStackVersion(dummyStackId.getStackVersion()); expected.setComponents(dummyComponents); heartbeatTestHelper.getDummyCluster(); HeartBeatHandler handler = heartbeatTestHelper.getHeartBeatHandler( actionManagerTestHelper.getMockActionManager(), new ActionQueue()); ComponentsResponse actual = handler.handleComponents(DummyCluster); if (log.isDebugEnabled()) { log.debug(actual.toString()); } assertEquals(expected.getClusterName(), actual.getClusterName()); assertEquals(expected.getStackName(), actual.getStackName()); assertEquals(expected.getStackVersion(), actual.getStackVersion()); assertEquals(expected.getComponents(), actual.getComponents()); }