knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kmin...@apache.org
Subject git commit: Comments for some of the pieces of the func test framework.
Date Fri, 12 Apr 2013 13:07:42 GMT
Updated Branches:
  refs/heads/master 61ca72e10 -> ae2d31c7a


Comments for some of the pieces of the func test framework.


Project: http://git-wip-us.apache.org/repos/asf/incubator-knox/repo
Commit: http://git-wip-us.apache.org/repos/asf/incubator-knox/commit/ae2d31c7
Tree: http://git-wip-us.apache.org/repos/asf/incubator-knox/tree/ae2d31c7
Diff: http://git-wip-us.apache.org/repos/asf/incubator-knox/diff/ae2d31c7

Branch: refs/heads/master
Commit: ae2d31c7a58c85fe2cff3dafa2dbe1e39f331bbc
Parents: 61ca72e
Author: Kevin Minder <kevin.minder@hortonworks.com>
Authored: Fri Apr 12 09:07:37 2013 -0400
Committer: Kevin Minder <kevin.minder@hortonworks.com>
Committed: Fri Apr 12 09:07:37 2013 -0400

----------------------------------------------------------------------
 .../org/apache/hadoop/test/mock/MockServer.java    |   15 ++++++
 .../hadoop/gateway/GatewayBasicFuncTest.java       |   34 +++++++++++++++
 .../hadoop/gateway/GatewayFuncTestDriver.java      |   24 ++++++++++
 3 files changed, 73 insertions(+), 0 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/ae2d31c7/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServer.java
----------------------------------------------------------------------
diff --git a/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServer.java
b/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServer.java
index eb7eb29..72aea0f 100644
--- a/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServer.java
+++ b/gateway-test-utils/src/main/java/org/apache/hadoop/test/mock/MockServer.java
@@ -28,6 +28,21 @@ import javax.servlet.Servlet;
 import java.util.LinkedList;
 import java.util.Queue;
 
+/**
+ * An embedded Jetty server with a single servlet deployed on "/*".
+ * It is used by populating a queue of "interactions".
+ * Each interaction is an expected request and a resulting response.
+ * These interactions are added to a queue in a fluent API style.
+ * So in most of the tests like GatewayBasicFuncTest.testBasicJsonUseCase you will see calls
like
+ * driver.getMock( "NAMENODE" ).expect()....respond()...;
+ * This adds a single interaction to the mock server which is returned via the driver.getMock(
"NAMENODE" ) above.
+ * Any number of interactions may be added.
+ * When the request comes in it will check the request against the expected request.
+ * If it matches return the response otherwise it will return a 500 error.
+ * Typically at the end of a test you should check to make sure the interaction queue is
consumed by calling isEmpty().
+ * The reset() method can be used to ensure everything is cleaned up so that the mock server
can be reused beteween tests.
+ * The whole idea was modeled after how the REST testing framework REST-assured and aims
to be a server side equivalent.
+ */
 public class MockServer {
 
   private Logger log = LoggerFactory.getLogger( this.getClass() );

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/ae2d31c7/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
index 21d7429..94eb094 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayBasicFuncTest.java
@@ -31,6 +31,7 @@ import org.apache.velocity.runtime.RuntimeConstants;
 import org.apache.velocity.runtime.resource.loader.ClasspathResourceLoader;
 import org.hamcrest.MatcherAssert;
 import org.junit.After;
+import org.junit.AfterClass;
 import org.junit.BeforeClass;
 import org.junit.Ignore;
 import org.junit.Test;
@@ -52,6 +53,8 @@ import static org.hamcrest.CoreMatchers.startsWith;
 @Category( { FunctionalTests.class, MediumTests.class } )
 public class GatewayBasicFuncTest {
 
+  // Uncomment to cause the test to hang after the gateway instance is setup.
+  // This will allow the gateway instance to be hit directly via some external client.
 //  @Test
 //  public void hang() throws IOException {
 //    System.out.println( "Server on port " + driver.gateway.getAddresses()[0].getPort()
);
@@ -63,10 +66,22 @@ public class GatewayBasicFuncTest {
 
   public static GatewayFuncTestDriver driver = new GatewayFuncTestDriver();
 
+  // Controls the host name to which the gateway dispatch requests.  This may be the name
of a sandbox VM
+  // or an EC2 instance.  Currently only a single host is supported.
   private static final String TEST_HOST = "vm.local";
+
+  // Specifies if the test requests should go through the gateway or directly to the services.
+  // This is frequently used to verify the behavior of the test both with and without the
gateway.
   private static final boolean USE_GATEWAY = true;
+
+  // Specifies if the test requests should be sent to mock services or the real services.
+  // This is frequently used to verify the behavior of the test both with and without mock
services.
   private static final boolean USE_MOCK_SERVICES = true;
+
+  // Specifies if the GATEWAY_HOME created for the test should be deleted when the test suite
is complete.
+  // This is frequently used during debugging to keep the GATEWAY_HOME around for inspection.
   private static final boolean CLEANUP_TEST = true;
+
 //  private static final boolean USE_GATEWAY = false;
 //  private static final boolean USE_MOCK_SERVICES = false;
 //  private static final boolean CLEANUP_TEST = false;
@@ -78,6 +93,13 @@ public class GatewayBasicFuncTest {
     return port;
   }
 
+  /**
+   * Creates a deployment of a gateway instance that all test methods will share.  This method
also creates a
+   * registry of sorts for all of the services that will be used by the test methods.
+   * The createTopology method is used to create the topology file that would normally be
read from disk.
+   * The driver.setupGateway invocation is where the creation of GATEWAY_HOME occurs.
+   * @throws Exception Thrown if any failure occurs.
+   */
   @BeforeClass
   public static void setupSuite() throws Exception {
     GatewayTestConfig config = new GatewayTestConfig();
@@ -93,11 +115,23 @@ public class GatewayBasicFuncTest {
     driver.setupGateway( config, "cluster", createTopology(), USE_GATEWAY );
   }
 
+  @AfterClass
+  public static void cleanupSuite() throws Exception {
+    if( CLEANUP_TEST ) {
+      driver.cleanup();
+    }
+  }
+
   @After
   public void cleanupTest() {
     driver.reset();
   }
 
+  /**
+   * Creates a topology that is deployed to the gateway instance for the test suite.
+   * Note that this topology is shared by all of the test methods in this suite.
+   * @return A populated XML structure for a topology file.
+   */
   private static XMLTag createTopology() {
     XMLTag xml = XMLDoc.newDocument( true )
         .addRoot( "topology" )

http://git-wip-us.apache.org/repos/asf/incubator-knox/blob/ae2d31c7/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
----------------------------------------------------------------------
diff --git a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
index f479d2c..6d4cd65 100644
--- a/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
+++ b/gateway-test/src/test/java/org/apache/hadoop/gateway/GatewayFuncTestDriver.java
@@ -68,6 +68,14 @@ import static org.hamcrest.Matchers.is;
 import static org.hamcrest.Matchers.isIn;
 import static org.junit.Assert.assertThat;
 
+/**
+ * This class was created to reduce much of the duplication and boiler plate that was ending
up in the GatewayBasicFuncTest class.
+ * It basically does a number of different things.
+ * 1) Creates a GATEWAY_HOME starts a gateway instance and deployes a test topology.
+ * 2) Provides a registry of mock Hadoop services.
+ * 3) Provides "bundled" methods for common Hadoop operations to avoid duplication in tests.
+ * 4) Provides methods to access test resources.
+ */
 public class GatewayFuncTestDriver {
 
   private static Logger log = LoggerFactory.getLogger( GatewayFuncTestDriver.class );
@@ -79,10 +87,20 @@ public class GatewayFuncTestDriver {
   public GatewayServer gateway;
   public GatewayConfig config;
 
+  /**
+   * Sets the class from which relative test resource names should be resolved.
+   * @param resourceBaseClass The class from which relative test resource names should be
resolved.
+   */
   public void setResourceBase( Class<?> resourceBaseClass ) {
     this.resourceBaseClass = resourceBaseClass;
   }
 
+  /**
+   * Starts an embedded LDAP server of the specified port.
+   * @param port The desired port the LDAP server should listen on.
+   * @return The actual port the LDAP server is listening on.
+   * @throws Exception Thrown if a failure occurs.
+   */
   public int setupLdap( int port ) throws Exception {
     URL usersUrl = getResourceUrl( "users.ldif" );
     ldap = new EmbeddedApacheDirectoryServer( "dc=hadoop,dc=apache,dc=org", null, port );
@@ -92,12 +110,18 @@ public class GatewayFuncTestDriver {
     return port;
   }
 
+  /**
+   * Adds a mock service to the registry.
+   */
   public void setupService( String role, String realUrl, String gatewayPath, boolean mock
) throws Exception {
     Service service = new Service( role, realUrl, gatewayPath, mock );
     services.put( role, service );
     log.info( role + " port = " + service.server.getPort() );
   }
 
+  /**
+   * Creates a GATEWAY_HOME, starts a gateway intance and deploys a test topology.
+   */
   public void setupGateway( GatewayTestConfig config, String cluster, XMLTag topology, boolean
use ) throws IOException {
     this.useGateway = use;
 


Mime
View raw message