incubator-ambari-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From hit...@apache.org
Subject svn commit: r1382186 - in /incubator/ambari/branches/AMBARI-666: ./ ambari-project/ ambari-server/ ambari-server/src/main/java/org/apache/ambari/server/state/live/ ambari-server/src/main/java/org/apache/ambari/server/state/live/node/ ambari-server/src/...
Date Fri, 07 Sep 2012 21:53:50 GMT
Author: hitesh
Date: Fri Sep  7 21:53:49 2012
New Revision: 1382186

URL: http://svn.apache.org/viewvc?rev=1382186&view=rev
Log:
AMBARI-706. Basic tests for Node FSM. (Contributed by hitesh)

Added:
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/node/
    incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/node/TestNodeImpl.java
  (with props)
Modified:
    incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt
    incubator/ambari/branches/AMBARI-666/ambari-project/pom.xml
    incubator/ambari/branches/AMBARI-666/ambari-server/pom.xml
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java
    incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/node/NodeImpl.java
    incubator/ambari/branches/AMBARI-666/pom.xml

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=1382186&r1=1382185&r2=1382186&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt (original)
+++ incubator/ambari/branches/AMBARI-666/AMBARI-666-CHANGES.txt Fri Sep  7 21:53:49 2012
@@ -12,6 +12,8 @@ AMBARI-666 branch (unreleased changes)
 
   NEW FEATURES
 
+  AMBARI-706. Basic tests for Node FSM (hitesh)
+
   AMBARI-705. Initial work on Node FSM. (hitesh)
 
   AMBARI-703. Heartbeat handler classes. (jitendra)

Modified: incubator/ambari/branches/AMBARI-666/ambari-project/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-project/pom.xml?rev=1382186&r1=1382185&r2=1382186&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-project/pom.xml (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-project/pom.xml Fri Sep  7 21:53:49 2012
@@ -79,11 +79,6 @@
   <dependencyManagement>
     <dependencies>
       <dependency>
-        <groupId>org.testng</groupId>
-        <artifactId>testng</artifactId>
-        <version>6.7</version>
-      </dependency>
-      <dependency>
         <groupId>com.google.inject</groupId>
         <artifactId>guice</artifactId>
         <version>3.0</version>
@@ -187,4 +182,30 @@
       </dependency>
     </dependencies>
   </dependencyManagement>
+  <build>
+    <pluginManagement>
+      <plugins>
+        <plugin>
+          <groupId>org.apache.rat</groupId>
+          <artifactId>apache-rat-plugin</artifactId>
+          <version>0.8</version>
+        </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>2.12</version>
+        </plugin>
+      </plugins>
+    </pluginManagement>
+    <plugins>
+      <plugin>
+        <groupId>org.apache.maven.plugins</groupId>
+        <artifactId>maven-surefire-plugin</artifactId>
+        <configuration>
+          <forkMode>always</forkMode>
+          <forkedProcessTimeoutInSeconds>900</forkedProcessTimeoutInSeconds>
+        </configuration>
+      </plugin>
+    </plugins>
+  </build>
 </project>

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/pom.xml?rev=1382186&r1=1382185&r2=1382186&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/pom.xml (original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/pom.xml Fri Sep  7 21:53:49 2012
@@ -57,10 +57,6 @@
   </profiles>
   <dependencies>
     <dependency>
-      <groupId>org.testng</groupId>
-      <artifactId>testng</artifactId>
-    </dependency>
-    <dependency>
       <groupId>com.google.inject</groupId>
       <artifactId>guice</artifactId>
     </dependency>
@@ -71,6 +67,7 @@
     <dependency>
       <groupId>org.mockito</groupId>
       <artifactId>mockito-core</artifactId>
+      <scope>test</scope>
     </dependency>
     <dependency>
       <groupId>org.mortbay.jetty</groupId>
@@ -115,6 +112,12 @@
     <dependency>
       <groupId>com.sun.jersey.jersey-test-framework</groupId>
       <artifactId>jersey-test-framework-external</artifactId>
+      <scope>test</scope>
+    </dependency>
+    <dependency>
+      <groupId>junit</groupId>
+      <artifactId>junit</artifactId>
+      <scope>test</scope>
     </dependency>
   </dependencies>
 </project>

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java?rev=1382186&r1=1382185&r2=1382186&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/DiskInfo.java
Fri Sep  7 21:53:49 2012
@@ -50,4 +50,22 @@ public class DiskInfo {
    */
   long currentCapacityBytes;
 
+  /**
+   * Default constructor
+   * @param device
+   * @param fsType
+   * @param mountPath
+   * @param totalCapacityBytes
+   * @param currentCapacityBytes
+   */
+  public DiskInfo(String device, String fsType, String mountPath,
+      long totalCapacityBytes, long currentCapacityBytes) {
+    super();
+    this.device = device;
+    this.fsType = fsType;
+    this.mountPath = mountPath;
+    this.totalCapacityBytes = totalCapacityBytes;
+    this.currentCapacityBytes = currentCapacityBytes;
+  }
+
 }

Modified: incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/node/NodeImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/node/NodeImpl.java?rev=1382186&r1=1382185&r2=1382186&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/node/NodeImpl.java
(original)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/main/java/org/apache/ambari/server/state/live/node/NodeImpl.java
Fri Sep  7 21:53:49 2012
@@ -257,6 +257,7 @@ public class NodeImpl implements Node {
     @Override
     public void transition(NodeImpl node, NodeEvent event) {
       NodeHealthyHeartbeatEvent e = (NodeHealthyHeartbeatEvent) event;
+      node.setLastHeartbeatTime(e.getHeartbeatTime());
       // TODO Audit logs
       LOG.info("Node transitioned to a healthy state"
           + ", node=" + e.nodeName
@@ -271,11 +272,12 @@ public class NodeImpl implements Node {
     @Override
     public void transition(NodeImpl node, NodeEvent event) {
       NodeUnhealthyHeartbeatEvent e = (NodeUnhealthyHeartbeatEvent) event;
+      node.setLastHeartbeatTime(e.getHeartbeatTime());
       // TODO Audit logs
       LOG.info("Node transitioned to an unhealthy state"
           + ", node=" + e.nodeName
           + ", heartbeatTime=" + e.getHeartbeatTime()
-          + ", healthStatis=" + e.getHealthStatus());
+          + ", healthStatus=" + e.getHealthStatus());
       node.setHealthStatus(e.getHealthStatus());
     }
   }
@@ -294,7 +296,7 @@ public class NodeImpl implements Node {
     }
   } 
 
-  private void importNodeInfo(NodeInfo nodeInfo) {
+  void importNodeInfo(NodeInfo nodeInfo) {
     try {
       writeLock.lock();
       this.hostName = nodeInfo.hostName;

Added: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/node/TestNodeImpl.java
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/node/TestNodeImpl.java?rev=1382186&view=auto
==============================================================================
--- incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/node/TestNodeImpl.java
(added)
+++ incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/node/TestNodeImpl.java
Fri Sep  7 21:53:49 2012
@@ -0,0 +1,195 @@
+package org.apache.ambari.server.state.live.node;
+
+import static org.junit.Assert.fail;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+
+import org.junit.Assert;
+import org.junit.Test;
+
+import org.apache.ambari.server.state.live.AgentVersion;
+import org.apache.ambari.server.state.live.DiskInfo;
+
+public class TestNodeImpl {
+
+  
+  @Test
+  public void testNodeInfoImport() {
+    NodeInfo info = new NodeInfo();
+    info.availableMemBytes = 100;
+    info.cpuCount = 10;
+    info.disksInfo = new ArrayList<DiskInfo>();
+    info.disksInfo.add(new DiskInfo("/dev/sda", "ext3", "/mnt/disk1",
+        5000000, 4000000));    
+    info.hostAttributes = new HashMap<String, String>();
+    info.hostName = "foo";
+    info.ipv4 = "fip_4";
+    info.osArch = "os_arch";
+    info.osType = "os_type";
+    info.osInfo = "os_info";
+    info.rackInfo = "/default-rack";
+    info.totalMemBytes = 200;
+    
+    NodeImpl node = new NodeImpl();
+    node.importNodeInfo(info);
+    
+    Assert.assertEquals(info.hostName, node.getHostName());
+    Assert.assertEquals(info.ipv4, node.getIPv4());
+    Assert.assertEquals(info.ipv6, node.getIPv6());
+    Assert.assertEquals(info.availableMemBytes, node.getAvailableMemBytes());
+    Assert.assertEquals(info.totalMemBytes, node.getTotalMemBytes());
+    Assert.assertEquals(info.cpuCount, node.getCpuCount());
+    Assert.assertEquals(info.disksInfo.size(), node.getDisksInfo().size());
+    Assert.assertEquals(info.hostAttributes.size(),
+        node.getHostAttributes().size());
+    Assert.assertEquals(info.osArch, node.getOsArch());
+    Assert.assertEquals(info.osType, node.getOsType());
+    Assert.assertEquals(info.osInfo, node.getOsInfo());
+    Assert.assertEquals(info.rackInfo, node.getRackInfo());
+    
+  }
+
+  private void registerNode(NodeImpl node) throws Exception {
+    NodeInfo info = new NodeInfo();
+    info.availableMemBytes = 100;
+    info.cpuCount = 10;
+    info.disksInfo = new ArrayList<DiskInfo>();
+    info.disksInfo.add(new DiskInfo("/dev/sda", "ext3", "/mnt/disk1",
+        5000000, 4000000));    
+    info.hostAttributes = new HashMap<String, String>();
+    info.hostName = "foo";
+    info.ipv4 = "fip_4";
+    info.osArch = "os_arch";
+    info.osType = "os_type";
+    info.osInfo = "os_info";
+    info.rackInfo = "/default-rack";
+    info.totalMemBytes = 200;
+    AgentVersion agentVersion = null;
+    long currentTime = System.currentTimeMillis();
+    
+    NodeRegistrationRequestEvent e = 
+        new NodeRegistrationRequestEvent("foo", agentVersion, currentTime,
+            info);
+    node.handleEvent(e);
+    Assert.assertEquals(node.getLastRegistrationTime(), currentTime);
+  }
+
+  private void verifyNode(NodeImpl node) throws Exception {
+    NodeVerifiedEvent e = new NodeVerifiedEvent(node.getHostName());
+    node.handleEvent(e);    
+  }
+  
+  private void verifyNodeState(NodeImpl node, NodeState state) {
+    Assert.assertEquals(node.getState(), state);
+  }
+  
+  private void sendHealthyHeartbeat(NodeImpl node, long counter) throws Exception {
+    NodeHealthyHeartbeatEvent e = new NodeHealthyHeartbeatEvent(
+        node.getHostName(), counter);
+    node.handleEvent(e);
+  }
+
+  private void sendUnhealthyHeartbeat(NodeImpl node, long counter) throws Exception {
+    NodeHealthStatus healthStatus = null;
+    NodeUnhealthyHeartbeatEvent e = new NodeUnhealthyHeartbeatEvent(
+        node.getHostName(), counter, healthStatus);
+    node.handleEvent(e);
+  }
+  
+  private void timeoutNode(NodeImpl node) throws Exception {
+    NodeHeartbeatTimedOutEvent e = new NodeHeartbeatTimedOutEvent(
+        node.getHostName());
+    node.handleEvent(e);
+  }
+  
+  @Test
+  public void testNodeFSMInit() {
+    NodeImpl node = new NodeImpl();
+    verifyNodeState(node, NodeState.INIT);
+  }
+  
+  @Test
+  public void testNodeRegistrationFlow() throws Exception {
+    NodeImpl node = new NodeImpl();
+    registerNode(node);
+    verifyNodeState(node, NodeState.WAITING_FOR_VERIFICATION);
+    
+    boolean exceptionThrown = false;
+    try {
+      registerNode(node);
+    } catch (Exception e) {
+      // Expected
+      exceptionThrown = true;
+    }
+    if (!exceptionThrown) {
+      fail("Expected invalid transition exception to be thrown");
+    }
+
+    verifyNode(node);
+    verifyNodeState(node, NodeState.VERIFIED);
+
+    exceptionThrown = false;
+    try {
+      verifyNode(node);
+    } catch (Exception e) {
+      // Expected
+      exceptionThrown = true;
+    }
+    if (!exceptionThrown) {
+      fail("Expected invalid transition exception to be thrown");
+    }
+  }
+
+  @Test
+  public void testNodeHeartbeatFlow() throws Exception {
+    NodeImpl node = new NodeImpl();
+    registerNode(node);
+    verifyNode(node);
+
+    // TODO need to verify audit logs generated
+    // TODO need to verify health status updated properly
+    
+    long counter = 0;
+    sendHealthyHeartbeat(node, ++counter);
+    verifyNodeState(node, NodeState.HEALTHY);
+    Assert.assertEquals(node.getLastHeartbeatTime(), counter);
+    
+    sendHealthyHeartbeat(node, ++counter);
+    verifyNodeState(node, NodeState.HEALTHY);
+    Assert.assertEquals(node.getLastHeartbeatTime(), counter);
+
+    sendUnhealthyHeartbeat(node, ++counter);
+    verifyNodeState(node, NodeState.UNHEALTHY);
+    Assert.assertEquals(node.getLastHeartbeatTime(), counter);
+
+    sendUnhealthyHeartbeat(node, ++counter);
+    verifyNodeState(node, NodeState.UNHEALTHY);
+    Assert.assertEquals(node.getLastHeartbeatTime(), counter);
+
+    sendHealthyHeartbeat(node, ++counter);
+    verifyNodeState(node, NodeState.HEALTHY);
+    Assert.assertEquals(node.getLastHeartbeatTime(), counter);
+    
+    timeoutNode(node);
+    verifyNodeState(node, NodeState.HEARTBEAT_LOST);
+    Assert.assertEquals(node.getLastHeartbeatTime(), counter);
+
+    timeoutNode(node);
+    verifyNodeState(node, NodeState.HEARTBEAT_LOST);
+    Assert.assertEquals(node.getLastHeartbeatTime(), counter);
+
+    sendUnhealthyHeartbeat(node, ++counter);
+    verifyNodeState(node, NodeState.UNHEALTHY);
+    Assert.assertEquals(node.getLastHeartbeatTime(), counter);
+    
+    timeoutNode(node);
+    verifyNodeState(node, NodeState.HEARTBEAT_LOST);
+    Assert.assertEquals(node.getLastHeartbeatTime(), counter);
+
+    sendHealthyHeartbeat(node, ++counter);
+    verifyNodeState(node, NodeState.HEALTHY);
+    Assert.assertEquals(node.getLastHeartbeatTime(), counter);    
+    
+  }
+}

Propchange: incubator/ambari/branches/AMBARI-666/ambari-server/src/test/java/org/apache/ambari/server/state/live/node/TestNodeImpl.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: incubator/ambari/branches/AMBARI-666/pom.xml
URL: http://svn.apache.org/viewvc/incubator/ambari/branches/AMBARI-666/pom.xml?rev=1382186&r1=1382185&r2=1382186&view=diff
==============================================================================
--- incubator/ambari/branches/AMBARI-666/pom.xml (original)
+++ incubator/ambari/branches/AMBARI-666/pom.xml Fri Sep  7 21:53:49 2012
@@ -49,6 +49,11 @@
           <artifactId>apache-rat-plugin</artifactId>
           <version>0.8</version>
         </plugin>
+        <plugin>
+          <groupId>org.apache.maven.plugins</groupId>
+          <artifactId>maven-surefire-plugin</artifactId>
+          <version>2.12</version>
+        </plugin>
       </plugins>
     </pluginManagement>
     <plugins>



Mime
View raw message