You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by ji...@apache.org on 2012/10/02 00:35:41 UTC

svn commit: r1392669 - in /incubator/ambari/branches/AMBARI-666: AMBARI-666-CHANGES.txt ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java

Author: jitendra
Date: Mon Oct  1 22:35:40 2012
New Revision: 1392669

URL: http://svn.apache.org/viewvc?rev=1392669&view=rev
Log:
AMBARI-781. Registration unit test.

Modified:
    incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java

Modified: incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt?rev=1392669&r1=1392668&r2=1392669&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Mon Oct  1 22:35:40 2012
@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-781. Registration unit test. (jitendra)
+
   AMBARI-754. Heartbeat handler: Registration response should query component 
   status. (jitendra)
 

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java?rev=1392669&r1=1392668&r2=1392669&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java Mon Oct  1 22:35:40 2012
@@ -32,6 +32,7 @@ import org.apache.ambari.server.state.li
 import org.apache.ambari.server.state.live.host.HostHealthyHeartbeatEvent;
 import org.apache.ambari.server.state.live.host.HostRegistrationRequestEvent;
 import org.apache.ambari.server.state.live.host.HostState;
+import org.apache.ambari.server.state.live.host.HostStatusUpdatesReceivedEvent;
 import org.apache.ambari.server.state.live.host.HostUnhealthyHeartbeatEvent;
 import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHost;
 import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHostLiveState;
@@ -134,11 +135,16 @@ public class HeartBeatHandler {
       cmds.add(statusCmd);
     }
     Host hostObject = clusterFsm.getHost(hostname);
-    RegistrationResponse response = new RegistrationResponse();
-    response.setCommand(cmds);
-
     hostObject.handleEvent(new HostRegistrationRequestEvent(hostname,
         new AgentVersion("v1"), now, register.getHardwareProfile()));
+    RegistrationResponse response = new RegistrationResponse();
+    if (cmds.isEmpty()) {
+      //No status commands needed let the fsm know that status step is done
+      hostObject.handleEvent(new HostStatusUpdatesReceivedEvent(hostname,
+          now));
+    } else {
+      response.setCommand(cmds);
+    }
     return response;
   }
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java?rev=1392669&r1=1392668&r2=1392669&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java Mon Oct  1 22:35:40 2012
@@ -24,6 +24,7 @@ import org.apache.ambari.server.AmbariEx
 import org.apache.ambari.server.actionmanager.ActionDBInMemoryImpl;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.agent.HostStatus.Status;
+import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
 import org.apache.ambari.server.state.live.Clusters;
 import org.apache.ambari.server.state.live.host.Host;
 import org.apache.ambari.server.state.live.host.HostImpl;
@@ -54,5 +55,26 @@ public class TestHeartbeatHandler {
     assertEquals(HostState.HEALTHY, hostObject.getState());
     assertEquals(0, aq.dequeueAll(hostname).size());
   }
+  
+  @Test
+  public void testRegistration() throws AmbariException,
+      InvalidStateTransitonException {
+    ActionManager am = new ActionManager(0, 0, null, null,
+        new ActionDBInMemoryImpl());
+    Clusters fsm = mock(Clusters.class);
+    String hostname = "host1";
+    HeartBeatHandler handler = new HeartBeatHandler(fsm, new ActionQueue(), am);
+    Host hostObject = new HostImpl(hostname);
+    when(fsm.getHost(hostname)).thenReturn(hostObject);
+    
+    Register reg = new Register();
+    HostInfo hi = new HostInfo();
+    hi.setOS("MegaOperatingSystem");
+    reg.setHostname(hostname);
+    reg.setHardwareProfile(hi);
+    handler.handleRegistration(reg);
+    assertEquals(hostObject.getState(), HostState.HEALTHY);
+    assertEquals("MegaOperatingSystem", hostObject.getOsType());
+  }
 
 }