Browse Source

AMBARI-781. Registration unit test.

git-svn-id: https://svn.apache.org/repos/asf/incubator/ambari/branches/AMBARI-666@1392669 13f79535-47bb-0310-9956-ffa450edef68
Jitendra Nath Pandey 13 năm trước cách đây
mục cha
commit
7e59ad9b94

+ 2 - 0
AMBARI-666-CHANGES.txt

@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
 
   NEW FEATURES
   NEW FEATURES
 
 
+  AMBARI-781. Registration unit test. (jitendra)
+
   AMBARI-754. Heartbeat handler: Registration response should query component 
   AMBARI-754. Heartbeat handler: Registration response should query component 
   status. (jitendra)
   status. (jitendra)
 
 

+ 9 - 3
ambari-server/src/main/java/org/apache/ambari/server/agent/HeartBeatHandler.java

@@ -32,6 +32,7 @@ import org.apache.ambari.server.state.live.host.HostEventType;
 import org.apache.ambari.server.state.live.host.HostHealthyHeartbeatEvent;
 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.HostRegistrationRequestEvent;
 import org.apache.ambari.server.state.live.host.HostState;
 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.host.HostUnhealthyHeartbeatEvent;
 import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHost;
 import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHost;
 import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHostLiveState;
 import org.apache.ambari.server.state.live.svccomphost.ServiceComponentHostLiveState;
@@ -134,11 +135,16 @@ public class HeartBeatHandler {
       cmds.add(statusCmd);
       cmds.add(statusCmd);
     }
     }
     Host hostObject = clusterFsm.getHost(hostname);
     Host hostObject = clusterFsm.getHost(hostname);
-    RegistrationResponse response = new RegistrationResponse();
-    response.setCommand(cmds);
-
     hostObject.handleEvent(new HostRegistrationRequestEvent(hostname,
     hostObject.handleEvent(new HostRegistrationRequestEvent(hostname,
         new AgentVersion("v1"), now, register.getHardwareProfile()));
         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;
     return response;
   }
   }
 }
 }

+ 22 - 0
ambari-server/src/test/java/org/apache/ambari/server/agent/TestHeartbeatHandler.java

@@ -24,6 +24,7 @@ import org.apache.ambari.server.AmbariException;
 import org.apache.ambari.server.actionmanager.ActionDBInMemoryImpl;
 import org.apache.ambari.server.actionmanager.ActionDBInMemoryImpl;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.actionmanager.ActionManager;
 import org.apache.ambari.server.agent.HostStatus.Status;
 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.Clusters;
 import org.apache.ambari.server.state.live.host.Host;
 import org.apache.ambari.server.state.live.host.Host;
 import org.apache.ambari.server.state.live.host.HostImpl;
 import org.apache.ambari.server.state.live.host.HostImpl;
@@ -54,5 +55,26 @@ public class TestHeartbeatHandler {
     assertEquals(HostState.HEALTHY, hostObject.getState());
     assertEquals(HostState.HEALTHY, hostObject.getState());
     assertEquals(0, aq.dequeueAll(hostname).size());
     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());
+  }
 
 
 }
 }