You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@ambari.apache.org by hi...@apache.org on 2012/09/27 22:26:57 UTC

svn commit: r1391200 - in /incubator/ambari/branches/AMBARI-666: ./ ambari-server/src/main/java/org/apache/ambari/server/state/live/host/ ambari-server/src/test/java/org/apache/ambari/server/state/live/ ambari-server/src/test/java/org/apache/ambari/ser...

Author: hitesh
Date: Thu Sep 27 20:26:56 2012
New Revision: 1391200

URL: http://svn.apache.org/viewvc?rev=1391200&view=rev
Log:
AMBARI-773. Change Host FSM as per new requirements of heartbeat handler. (Contributed by hitesh)

Added:
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostHeartbeatLostEvent.java   (with props)
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostStatusUpdatesReceivedEvent.java   (with props)
Removed:
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostHeartbeatTimedOutEvent.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostVerifiedEvent.java
Modified:
    incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostEventType.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostState.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.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=1391200&r1=1391199&r2=1391200&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Thu Sep 27 20:26:56 2012
@@ -169,6 +169,8 @@ AMBARI-666 branch (unreleased changes)
 
   BUG FIXES
 
+  AMBARI-773. Change Host FSM as per new requirements of heartbeat handler. (hitesh)
+
   AMBARI-761. Fix broken build for adding guice servlet dependency. (mahadev)
 
   AMBARI-753. Fix broken compile as a result of re-factor of FSM layout. (hitesh)

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostEventType.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostEventType.java?rev=1391200&r1=1391199&r2=1391200&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostEventType.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostEventType.java Thu Sep 27 20:26:56 2012
@@ -24,9 +24,9 @@ public enum HostEventType {
    */
   HOST_REGISTRATION_REQUEST,
   /**
-   * Host authenticated/verified.
+   * Host status check response received.
    */
-  HOST_VERIFIED,
+  HOST_STATUS_UPDATES_RECEIVED,
   /**
    * A healthy heartbeat event received from the Host.
    */
@@ -34,7 +34,7 @@ public enum HostEventType {
   /**
    * No heartbeat received from the Host within the defined expiry interval.
    */
-  HOST_HEARTBEAT_TIMED_OUT,
+  HOST_HEARTBEAT_LOST,
   /**
    * A non-healthy heartbeat event received from the Host.
    */

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostHeartbeatLostEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostHeartbeatLostEvent.java?rev=1391200&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostHeartbeatLostEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostHeartbeatLostEvent.java Thu Sep 27 20:26:56 2012
@@ -0,0 +1,28 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+
+package org.apache.ambari.server.state.live.host;
+
+public class HostHeartbeatLostEvent extends HostEvent {
+
+  public HostHeartbeatLostEvent(String hostName) {
+    super(hostName, HostEventType.HOST_HEARTBEAT_LOST);
+  }
+
+}

Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostHeartbeatLostEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java?rev=1391200&r1=1391199&r2=1391200&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostImpl.java Thu Sep 27 20:26:56 2012
@@ -135,27 +135,25 @@ public class HostImpl implements Host {
 
    // Transition from INIT state
    // when the initial registration request is received
-   .addTransition(HostState.INIT, HostState.WAITING_FOR_VERIFICATION,
-       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())
-
-   // Transition from WAITING_FOR_VERIFICATION state
-   // when the host is authenticated
-   .addTransition(HostState.WAITING_FOR_VERIFICATION, HostState.VERIFIED,
-       HostEventType.HOST_VERIFIED, new HostVerifiedTransition())
-
-   // Transitions from VERIFIED state
+   .addTransition(HostState.INIT, HostState.WAITING_FOR_HOST_STATUS_UPDATES,
+       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())       
+       
+   // Transition from WAITING_FOR_STATUS_UPDATES state
+   // when the host has responded to its status update requests
+   // TODO this will create problems if the host is not healthy
+   // TODO Based on discussion with Jitendra, ignoring this for now    
+   .addTransition(HostState.WAITING_FOR_HOST_STATUS_UPDATES, HostState.HEALTHY,
+       HostEventType.HOST_STATUS_UPDATES_RECEIVED,
+       new HostStatusUpdatesReceivedTransition())
    // when a normal heartbeat is received
-   .addTransition(HostState.VERIFIED, HostState.HEALTHY,
-       HostEventType.HOST_HEARTBEAT_HEALTHY,
-       new HostBecameHealthyTransition())
-   // when a heartbeat is not received within the configured timeout period
-   .addTransition(HostState.VERIFIED, HostState.HEARTBEAT_LOST,
-       HostEventType.HOST_HEARTBEAT_TIMED_OUT,
-       new HostHeartbeatTimedOutTransition())
+   .addTransition(HostState.WAITING_FOR_HOST_STATUS_UPDATES,
+       HostState.WAITING_FOR_HOST_STATUS_UPDATES,
+       HostEventType.HOST_HEARTBEAT_HEALTHY)
    // when a heartbeart denoting host as unhealthy is received
-   .addTransition(HostState.VERIFIED, HostState.UNHEALTHY,
+   .addTransition(HostState.WAITING_FOR_HOST_STATUS_UPDATES,
+       HostState.WAITING_FOR_HOST_STATUS_UPDATES,
        HostEventType.HOST_HEARTBEAT_UNHEALTHY,
-       new HostBecameUnhealthyTransition())
+       new HostHeartbeatReceivedTransition())
 
    // Transitions from HEALTHY state
    // when a normal heartbeat is received
@@ -164,12 +162,16 @@ public class HostImpl implements Host {
        new HostHeartbeatReceivedTransition())
    // when a heartbeat is not received within the configured timeout period
    .addTransition(HostState.HEALTHY, HostState.HEARTBEAT_LOST,
-       HostEventType.HOST_HEARTBEAT_TIMED_OUT,
-       new HostHeartbeatTimedOutTransition())
+       HostEventType.HOST_HEARTBEAT_LOST,
+       new HostHeartbeatLostTransition())
    // when a heartbeart denoting host as unhealthy is received
    .addTransition(HostState.HEALTHY, HostState.UNHEALTHY,
        HostEventType.HOST_HEARTBEAT_UNHEALTHY,
        new HostBecameUnhealthyTransition())
+   // if a new registration request is received   
+   .addTransition(HostState.HEALTHY,
+       HostState.WAITING_FOR_HOST_STATUS_UPDATES,
+       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())       
 
    // Transitions from UNHEALTHY state
    // when a normal heartbeat is received
@@ -182,21 +184,22 @@ public class HostImpl implements Host {
        new HostHeartbeatReceivedTransition())
    // when a heartbeat is not received within the configured timeout period
    .addTransition(HostState.UNHEALTHY, HostState.HEARTBEAT_LOST,
-       HostEventType.HOST_HEARTBEAT_TIMED_OUT,
-       new HostHeartbeatTimedOutTransition())
+       HostEventType.HOST_HEARTBEAT_LOST,
+       new HostHeartbeatLostTransition())
+   // if a new registration request is received   
+   .addTransition(HostState.UNHEALTHY,
+       HostState.WAITING_FOR_HOST_STATUS_UPDATES,
+       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())       
 
    // Transitions from HEARTBEAT_LOST state
-   // when a normal heartbeat is received
-   .addTransition(HostState.HEARTBEAT_LOST, HostState.HEALTHY,
-       HostEventType.HOST_HEARTBEAT_HEALTHY,
-       new HostBecameHealthyTransition())
-   // when a heartbeart denoting host as unhealthy is received
-   .addTransition(HostState.HEARTBEAT_LOST, HostState.UNHEALTHY,
-       HostEventType.HOST_HEARTBEAT_UNHEALTHY,
-       new HostBecameUnhealthyTransition())
    // when a heartbeat is not received within the configured timeout period
    .addTransition(HostState.HEARTBEAT_LOST, HostState.HEARTBEAT_LOST,
-       HostEventType.HOST_HEARTBEAT_TIMED_OUT)
+       HostEventType.HOST_HEARTBEAT_LOST)
+   // if a new registration request is received   
+   .addTransition(HostState.HEARTBEAT_LOST,
+       HostState.WAITING_FOR_HOST_STATUS_UPDATES,
+       HostEventType.HOST_REGISTRATION_REQUEST, new HostRegistrationReceived())       
+       
    .installTopology();
 
   private final StateMachine<HostState, HostEventType, HostEvent> stateMachine;
@@ -223,12 +226,17 @@ public class HostImpl implements Host {
     }
   }
 
-  static class HostVerifiedTransition
+  static class HostStatusUpdatesReceivedTransition
       implements SingleArcTransition<HostImpl, HostEvent> {
 
     @Override
     public void transition(HostImpl host, HostEvent event) {
-      // TODO Auto-generated method stub
+      HostStatusUpdatesReceivedEvent e = (HostStatusUpdatesReceivedEvent)event;
+      // TODO Audit logs
+      LOG.debug("Host transition to host status updates received state"
+          + ", host=" + e.hostName
+          + ", heartbeatTime=" + e.getTimestamp());
+      host.getHealthStatus().setHealthStatus(HealthStatus.HEALTHY);
     }
   }
 
@@ -240,10 +248,12 @@ public class HostImpl implements Host {
       long heartbeatTime = 0;
       switch (event.getType()) {
         case HOST_HEARTBEAT_HEALTHY:
-          heartbeatTime = ((HostHealthyHeartbeatEvent)event).getHeartbeatTime();
+          heartbeatTime =
+            ((HostHealthyHeartbeatEvent)event).getHeartbeatTime();
           break;
         case HOST_HEARTBEAT_UNHEALTHY:
-          heartbeatTime = ((HostUnhealthyHeartbeatEvent)event).getHeartbeatTime();
+          heartbeatTime =
+            ((HostUnhealthyHeartbeatEvent)event).getHeartbeatTime();
           break;
         default:
           break;
@@ -263,7 +273,7 @@ public class HostImpl implements Host {
       HostHealthyHeartbeatEvent e = (HostHealthyHeartbeatEvent) event;
       host.setLastHeartbeatTime(e.getHeartbeatTime());
       // TODO Audit logs
-      LOG.info("Host transitioned to a healthy state"
+      LOG.debug("Host transitioned to a healthy state"
           + ", host=" + e.hostName
           + ", heartbeatTime=" + e.getHeartbeatTime());
       host.getHealthStatus().setHealthStatus(HealthStatus.HEALTHY);
@@ -278,7 +288,7 @@ public class HostImpl implements Host {
       HostUnhealthyHeartbeatEvent e = (HostUnhealthyHeartbeatEvent) event;
       host.setLastHeartbeatTime(e.getHeartbeatTime());
       // TODO Audit logs
-      LOG.info("Host transitioned to an unhealthy state"
+      LOG.debug("Host transitioned to an unhealthy state"
           + ", host=" + e.hostName
           + ", heartbeatTime=" + e.getHeartbeatTime()
           + ", healthStatus=" + e.getHealthStatus());
@@ -286,14 +296,14 @@ public class HostImpl implements Host {
     }
   }
 
-  static class HostHeartbeatTimedOutTransition
+  static class HostHeartbeatLostTransition
       implements SingleArcTransition<HostImpl, HostEvent> {
 
     @Override
     public void transition(HostImpl host, HostEvent event) {
-      HostHeartbeatTimedOutEvent e = (HostHeartbeatTimedOutEvent) event;
+      HostHeartbeatLostEvent e = (HostHeartbeatLostEvent) event;
       // TODO Audit logs
-      LOG.info("Host transitioned to heartbeat timed out state"
+      LOG.debug("Host transitioned to heartbeat lost state"
           + ", host=" + e.hostName
           + ", lastHeartbeatTime=" + host.getLastHeartbeatTime());
       host.getHealthStatus().setHealthStatus(HealthStatus.UNKNOWN);

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostState.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostState.java?rev=1391200&r1=1391199&r2=1391200&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostState.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostState.java Thu Sep 27 20:26:56 2012
@@ -25,13 +25,9 @@ public enum HostState {
   INIT,
   /**
    * State when a registration request is received from the Host but
-   * the host has not been verified/authenticated.
+   * the host has not responded to its status update check.
    */
-  WAITING_FOR_VERIFICATION,
-  /**
-   * State when the host has been verified/authenticated
-   */
-  VERIFIED,
+  WAITING_FOR_HOST_STATUS_UPDATES,
   /**
    * State when the server is receiving heartbeats regularly from the Host
    * and the state of the Host is healthy

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostStatusUpdatesReceivedEvent.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostStatusUpdatesReceivedEvent.java?rev=1391200&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostStatusUpdatesReceivedEvent.java (added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostStatusUpdatesReceivedEvent.java Thu Sep 27 20:26:56 2012
@@ -0,0 +1,40 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements.  See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership.  The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License.  You may obtain a copy of the License at
+ *
+ *     http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+
+package org.apache.ambari.server.state.live.host;
+
+public class HostStatusUpdatesReceivedEvent extends HostEvent {
+
+  private final long timestamp;
+  
+  // TODO need to add any additional information required for verification
+  // tracking
+  public HostStatusUpdatesReceivedEvent(String hostName,
+      long timestamp) {
+    super(hostName, HostEventType.HOST_STATUS_UPDATES_RECEIVED);
+    this.timestamp = timestamp;
+  }
+
+  /**
+   * @return the timestamp
+   */
+  public long getTimestamp() {
+    return timestamp;
+  }
+
+}

Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/host/HostStatusUpdatesReceivedEvent.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java?rev=1391200&r1=1391199&r2=1391200&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/TestClusterImpl.java Thu Sep 27 20:26:56 2012
@@ -31,6 +31,7 @@ import org.apache.ambari.server.agent.Ho
 import org.apache.ambari.server.state.ConfigVersion;
 import org.apache.ambari.server.state.StackVersion;
 import org.apache.ambari.server.state.fsm.InvalidStateTransitonException;
+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.svccomphost.ServiceComponentHostInstallEvent;
@@ -126,14 +127,13 @@ public class TestClusterImpl {
     c1.handleHostEvent(h1, new HostRegistrationRequestEvent(h1, agentVersion,
         currentTime, hostInfo));
 
-    Assert.assertEquals(HostState.WAITING_FOR_VERIFICATION,
+    Assert.assertEquals(HostState.WAITING_FOR_HOST_STATUS_UPDATES,
         c1.getHostState(h1));
 
-    c1.setHostState(h1, HostState.VERIFIED);
+    c1.setHostState(h1, HostState.HEARTBEAT_LOST);
 
     try {
-      c1.handleHostEvent(h1, new HostRegistrationRequestEvent(h1, agentVersion,
-          currentTime, hostInfo));
+      c1.handleHostEvent(h1, new HostHealthyHeartbeatEvent(h1, currentTime));
       fail("Exception should be thrown on invalid event");
     }
     catch (InvalidStateTransitonException e) {

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.java?rev=1391200&r1=1391199&r2=1391200&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.java (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/host/TestHostImpl.java Thu Sep 27 20:26:56 2012
@@ -85,8 +85,9 @@ public class TestHostImpl {
     Assert.assertEquals(currentTime, host.getLastRegistrationTime());
   }
 
-  private void verifyHost(HostImpl host) throws Exception {
-    HostVerifiedEvent e = new HostVerifiedEvent(host.getHostName());
+  private void ensureHostUpdatesReceived(HostImpl host) throws Exception {
+    HostStatusUpdatesReceivedEvent e =
+        new HostStatusUpdatesReceivedEvent(host.getHostName(), 1);
     host.handleEvent(e);
   }
 
@@ -94,13 +95,15 @@ public class TestHostImpl {
     Assert.assertEquals(state, host.getState());
   }
 
-  private void sendHealthyHeartbeat(HostImpl host, long counter) throws Exception {
+  private void sendHealthyHeartbeat(HostImpl host, long counter)
+      throws Exception {
     HostHealthyHeartbeatEvent e = new HostHealthyHeartbeatEvent(
         host.getHostName(), counter);
     host.handleEvent(e);
   }
 
-  private void sendUnhealthyHeartbeat(HostImpl host, long counter) throws Exception {
+  private void sendUnhealthyHeartbeat(HostImpl host, long counter)
+      throws Exception {
     HostHealthStatus healthStatus = new HostHealthStatus(HealthStatus.UNHEALTHY,
         "Unhealthy server");
     HostUnhealthyHeartbeatEvent e = new HostUnhealthyHeartbeatEvent(
@@ -109,7 +112,7 @@ public class TestHostImpl {
   }
 
   private void timeoutHost(HostImpl host) throws Exception {
-    HostHeartbeatTimedOutEvent e = new HostHeartbeatTimedOutEvent(
+    HostHeartbeatLostEvent e = new HostHeartbeatLostEvent(
         host.getHostName());
     host.handleEvent(e);
   }
@@ -124,7 +127,7 @@ public class TestHostImpl {
   public void testHostRegistrationFlow() throws Exception {
     HostImpl host = new HostImpl("foo");
     registerHost(host);
-    verifyHostState(host, HostState.WAITING_FOR_VERIFICATION);
+    verifyHostState(host, HostState.WAITING_FOR_HOST_STATUS_UPDATES);
 
     boolean exceptionThrown = false;
     try {
@@ -137,12 +140,12 @@ public class TestHostImpl {
       fail("Expected invalid transition exception to be thrown");
     }
 
-    verifyHost(host);
-    verifyHostState(host, HostState.VERIFIED);
+    ensureHostUpdatesReceived(host);
+    verifyHostState(host, HostState.HEALTHY);
 
     exceptionThrown = false;
     try {
-      verifyHost(host);
+      ensureHostUpdatesReceived(host);
     } catch (Exception e) {
       // Expected
       exceptionThrown = true;
@@ -156,7 +159,7 @@ public class TestHostImpl {
   public void testHostHeartbeatFlow() throws Exception {
     HostImpl host = new HostImpl("foo");
     registerHost(host);
-    verifyHost(host);
+    ensureHostUpdatesReceived(host);
 
     // TODO need to verify audit logs generated
     // TODO need to verify health status updated properly
@@ -202,23 +205,51 @@ public class TestHostImpl {
     Assert.assertEquals(HealthStatus.UNKNOWN,
         host.getHealthStatus().getHealthStatus());
 
-    sendUnhealthyHeartbeat(host, ++counter);
-    verifyHostState(host, HostState.UNHEALTHY);
-    Assert.assertEquals(counter, host.getLastHeartbeatTime());
-    Assert.assertEquals(HealthStatus.UNHEALTHY,
-        host.getHealthStatus().getHealthStatus());
+    try {
+      sendUnhealthyHeartbeat(host, ++counter);
+      fail("Invalid event should have triggered an exception");
+    } catch (Exception e) {
+      // Expected
+    }       
+    verifyHostState(host, HostState.HEARTBEAT_LOST);
 
-    timeoutHost(host);
+    try {
+      sendHealthyHeartbeat(host, ++counter);
+      fail("Invalid event should have triggered an exception");
+    } catch (Exception e) {
+      // Expected
+    }       
     verifyHostState(host, HostState.HEARTBEAT_LOST);
-    Assert.assertEquals(counter, host.getLastHeartbeatTime());
-    Assert.assertEquals(HealthStatus.UNKNOWN,
-        host.getHealthStatus().getHealthStatus());
+  }
+  
+  @Test
+  public void testHostRegistrationsInAnyState() throws Exception {
+    HostImpl host = new HostImpl("foo");
+    long counter = 0;
 
+    registerHost(host);
+    
+    ensureHostUpdatesReceived(host);
+    registerHost(host);
+    
+    ensureHostUpdatesReceived(host);
     sendHealthyHeartbeat(host, ++counter);
     verifyHostState(host, HostState.HEALTHY);
-    Assert.assertEquals(counter, host.getLastHeartbeatTime());
-    Assert.assertEquals(HealthStatus.HEALTHY,
-        host.getHealthStatus().getHealthStatus());
+    registerHost(host);
+    ensureHostUpdatesReceived(host);
 
+    sendUnhealthyHeartbeat(host, ++counter);
+    verifyHostState(host, HostState.UNHEALTHY);
+    registerHost(host);
+    ensureHostUpdatesReceived(host);
+
+    timeoutHost(host);
+    verifyHostState(host, HostState.HEARTBEAT_LOST);
+    registerHost(host);
+    ensureHostUpdatesReceived(host);
+    
+    host.setState(HostState.INIT);
+    registerHost(host);
+    
   }
 }