[jboss-cvs] JBossAS SVN: r94300 - in trunk/testsuite: src/main/org/jboss/test/cluster/defaultcfg/profileservice/test and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 2 18:13:26 EDT 2009


Author: bstansberry at jboss.com
Date: 2009-10-02 18:13:25 -0400 (Fri, 02 Oct 2009)
New Revision: 94300

Added:
   trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/profileservice/test/FarmedClusterHugeDeploymentUnitTestCase.java
   trunk/testsuite/src/resources/cluster/profileservice/farm-huge-index.html
   trunk/testsuite/src/resources/cluster/profileservice/farm-huge-web.xml
Modified:
   trunk/testsuite/imports/sections/cluster.xml
Log:
[JBAS-7102] Add a test of pushing a 150MB file

Modified: trunk/testsuite/imports/sections/cluster.xml
===================================================================
--- trunk/testsuite/imports/sections/cluster.xml	2009-10-02 21:08:48 UTC (rev 94299)
+++ trunk/testsuite/imports/sections/cluster.xml	2009-10-02 22:13:25 UTC (rev 94300)
@@ -61,9 +61,9 @@
     </jar>
       
       <!-- MBeans for testing Clustered DeploymentRepository additions -->
-      <copy todir="${build.lib}"
-         file="${build.resources}/cluster/profileservice/farm-addedcontent-service.xml"
-         overwrite="true"/>
+      <copy todir="${build.lib}" overwrite="true">
+         <fileset dir="${build.resources}/cluster/profileservice"/>
+      </copy>
       
       <!-- MBeans for testing Clustered DeploymentRepository additions -->
       <copy todir="${build.lib}" overwrite="true">

Copied: trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/profileservice/test/FarmedClusterHugeDeploymentUnitTestCase.java (from rev 94295, branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/profileservice/test/FarmedClusterHugeDeploymentUnitTestCase.java)
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/profileservice/test/FarmedClusterHugeDeploymentUnitTestCase.java	                        (rev 0)
+++ trunk/testsuite/src/main/org/jboss/test/cluster/defaultcfg/profileservice/test/FarmedClusterHugeDeploymentUnitTestCase.java	2009-10-02 22:13:25 UTC (rev 94300)
@@ -0,0 +1,324 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2008, Red Hat Middleware LLC, and individual contributors
+ * as indicated by the @author tags. See the copyright.txt file in the
+ * distribution for a full listing of individual contributors.
+ *
+ * This is free software; you can redistribute it and/or modify it
+ * under the terms of the GNU Lesser General Public License as
+ * published by the Free Software Foundation; either version 2.1 of
+ * the License, or (at your option) any later version.
+ *
+ * This software is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+ * Lesser General Public License for more details.
+ *
+ * You should have received a copy of the GNU Lesser General Public
+ * License along with this software; if not, write to the Free
+ * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+ * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+ */
+
+package org.jboss.test.cluster.defaultcfg.profileservice.test;
+
+import java.io.BufferedOutputStream;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.net.HttpURLConnection;
+import java.util.Properties;
+
+import javax.management.ObjectName;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+
+import org.apache.commons.httpclient.HttpClient;
+import org.apache.commons.httpclient.methods.GetMethod;
+import org.jboss.deployers.spi.management.ManagementView;
+import org.jboss.managed.api.ComponentType;
+import org.jboss.managed.api.ManagedComponent;
+import org.jboss.metatype.api.values.SimpleValue;
+import org.jboss.profileservice.spi.ProfileKey;
+import org.jboss.profileservice.spi.ProfileService;
+import org.jboss.test.JBossClusteredTestCase;
+import org.jboss.virtual.VFS;
+
+/**
+ * Test for JBAS-7102. Creates a war w/ 150MB of content in the farm
+ * folder; verifies that it is farmed and deployed correctly.
+ * @author Brian Stansberry
+ *
+ */
+public class FarmedClusterHugeDeploymentUnitTestCase extends JBossClusteredTestCase
+{  
+   /** We use the default profile, defined by DeploymentManager to deploy apps. */
+   public static final ProfileKey farmProfile = new ProfileKey("farm");
+   public static final String SCANNER_ONAME = "jboss.deployment:flavor=URL,type=DeploymentScanner";
+   private ManagementView activeView;
+   private File farm0Dir;
+   private File farm1Dir;
+   
+   /**
+    * Create a new FarmedClusterHotDeployUnitTestCase.
+    * 
+    * @param name
+    */
+   public FarmedClusterHugeDeploymentUnitTestCase(String name)
+   {
+      super(name);
+   }
+   
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp(); 
+      
+      ManagementView mgtView = getManagementView(getNamingContext(0));
+      ComponentType type = new ComponentType("MCBean", "ServerConfig");
+      ManagedComponent mc = mgtView.getComponent("jboss.system:type=ServerConfig", type);
+      if (mc == null)
+      {
+         throw new IllegalStateException("No ServerConfig for node0 available");
+      }
+      String homeDir = (String) ((SimpleValue) mc.getProperty("serverHomeDir").getValue()).getValue();
+      if (homeDir == null)
+      {
+         throw new IllegalStateException("No serverHomeDir for node0 available");
+      }
+      
+      this.farm0Dir = new File(homeDir, "farm");    
+      
+      mgtView = getManagementView(getNamingContext(1));
+      mc = mgtView.getComponent("jboss.system:type=ServerConfig", type);
+      if (mc == null)
+      {
+         throw new IllegalStateException("No ServerConfig for node1 available");
+      }
+      homeDir = (String) ((SimpleValue) mc.getProperty("serverHomeDir").getValue()).getValue();
+      if (homeDir == null)
+      {
+         throw new IllegalStateException("No serverHomeDir for node1 available");
+      }
+      
+      this.farm1Dir = new File(homeDir, "farm");    
+   }
+
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      try
+      {
+      super.tearDown();
+      }
+      finally
+      {
+         // Be a good boy and delete the huge files.
+         try
+         {
+            deleteHugeFile(farm0Dir);
+         }
+         finally
+         {
+            deleteHugeFile(farm1Dir);
+         }
+      }
+   }
+
+   public void testFarmHotDeployment() throws Exception
+   {       
+      assertTrue(farm0Dir + " exists", farm0Dir.exists());
+      
+      ObjectName scanner = new ObjectName(SCANNER_ONAME);      
+      try
+      {
+         getAdaptors()[0].invoke(scanner, "stop", new Object[]{}, new String[]{});
+         validateState(false);
+         performModifications();
+      }
+      finally
+      {
+         getAdaptors()[0].invoke(scanner, "start", new Object[]{}, new String[]{});
+      }      
+
+      validateState(true);
+   }
+
+   private void performModifications() throws Exception
+   {
+      // Create a war
+      File dir = new File(farm0Dir, "huge.war");
+      dir.mkdir();
+      
+      // Add a file we can request to verify deployment
+      copyFile(dir, "farm-huge-index.html", "index.html");
+      
+      // Add a 150MB file to it
+      File huge = new File(dir, "huge.bin");
+      FileOutputStream fos = new FileOutputStream(huge);
+      BufferedOutputStream bos = new BufferedOutputStream(fos);
+      int count = 150 * 1024 * 1024 / 4096;
+      for (int i = 0; i < count; i++)
+    	  bos.write(new byte[4096]);
+      bos.close();
+      
+      // Add the deployment descriptor
+      dir = new File(dir, "WEB-INF");
+      dir.mkdir();
+      copyFile(dir, "farm-huge-web.xml", "web.xml");
+   }
+   
+   private void validateState(boolean expectContent) throws Exception
+   {
+	  boolean node0ok = false;
+	  boolean node1ok = false;
+	  
+	  long start = System.nanoTime();
+	  long timeout = expectContent ? 45000000000L : 0;
+	  
+	  while (true)
+	  {
+	      // Create an instance of HttpClient.
+	      HttpClient client = new HttpClient();
+	
+	      if (!node0ok)
+	      {	  
+	         node0ok = makeGet(client, getHttpURLs()[0] + "/huge/index.html", expectContent);
+	      }
+	      
+	      if (node0ok && !node1ok)
+	      {
+	    	  client = new HttpClient();
+	      
+	    	  node1ok = makeGet(client, getHttpURLs()[1] + "/huge/index.html", expectContent);
+	      }
+	      
+	      if ((node0ok && node1ok) || (System.nanoTime() - start > timeout))
+	      {
+	    	  break;
+	      }
+	      else
+	      {
+	    	  Thread.sleep(1000);
+	      }
+	  }
+	  
+	  assertTrue("node 0 ok", node0ok);
+	  assertTrue("node 1 ok", node1ok);
+   }
+   
+   private boolean makeGet(HttpClient client, String url, boolean expectSuccess)
+      throws IOException
+   {
+      getLog().debug("makeGet(): trying to get from url " +url);
+
+      GetMethod method = new GetMethod(url);
+      int responseCode = 0;
+      try
+      {
+         responseCode = client.executeMethod(method);
+      } catch (IOException e)
+      {
+         e.printStackTrace();
+         fail("HttpClient executeMethod fails." +e.toString());
+      }
+      boolean ok = false;
+      if (expectSuccess)
+      {
+	      ok = responseCode == HttpURLConnection.HTTP_OK;
+      }
+      else
+      {
+    	  ok = responseCode != HttpURLConnection.HTTP_OK;
+      }
+      
+      // Read the response body.
+      byte[] responseBody = method.getResponseBody();
+
+      // Release the connection.
+//      method.releaseConnection();
+
+      // Deal with the response.
+      // Use caution: ensure correct character encoding and is not binary data
+      return ok;
+   }
+
+   /**
+    * Obtain the ProfileService.ManagementView
+    * @return
+    * @throws Exception
+    */
+   private ManagementView getManagementView(Context ctx)
+      throws Exception
+   {
+      if( activeView == null )
+      {
+         ProfileService ps = (ProfileService) ctx.lookup("ProfileService");
+         activeView = ps.getViewManager();
+         // Init the VFS to setup the vfs* protocol handlers
+         VFS.init();
+      }
+      // Reload
+      activeView.load();
+      return activeView;
+   }
+   
+   private Context getNamingContext(int nodeIndex) throws Exception
+   {
+      // Connect to the server0 JNDI
+      String[] urls = getNamingURLs();
+      Properties env1 = new Properties();
+      env1.setProperty(Context.INITIAL_CONTEXT_FACTORY,
+         "org.jnp.interfaces.NamingContextFactory");
+      env1.setProperty(Context.PROVIDER_URL, urls[nodeIndex]);
+      return new InitialContext(env1);
+   }
+
+   private void copyFile(File dir, String sourceName, String targetName) throws Exception
+   {
+      InputStream is = getDeployURL(sourceName).openStream();
+      try
+      {
+         File output = new File(dir, targetName);
+         FileOutputStream fos = new FileOutputStream(output);
+         try
+         {
+            byte[] tmp = new byte[1024];
+            int read;
+            while((read = is.read(tmp)) > 0)
+            {
+               fos.write(tmp, 0, read);
+            }
+            fos.flush();
+         }
+         finally
+         {
+            fos.close();
+         }         
+      }
+      finally
+      {
+         is.close();
+      }
+   }
+
+
+   private void deleteHugeFile(File farmDir)
+   {
+      if (farmDir.exists())
+      {
+         File war = new File(farmDir, "huge.war");
+         if (war.exists())
+         {
+            File huge = new File(war, "huge.bin");
+            if (huge.exists() && !huge.delete())
+            {
+               huge.deleteOnExit();
+            }
+         }
+      }      
+   }
+
+}

Copied: trunk/testsuite/src/resources/cluster/profileservice/farm-huge-index.html (from rev 94296, branches/Branch_5_x/testsuite/src/resources/cluster/profileservice/farm-huge-index.html)
===================================================================
--- trunk/testsuite/src/resources/cluster/profileservice/farm-huge-index.html	                        (rev 0)
+++ trunk/testsuite/src/resources/cluster/profileservice/farm-huge-index.html	2009-10-02 22:13:25 UTC (rev 94300)
@@ -0,0 +1 @@
+<html><head><title>Huge</title></head><body><p>Huge</p></body></html>
\ No newline at end of file

Copied: trunk/testsuite/src/resources/cluster/profileservice/farm-huge-web.xml (from rev 94296, branches/Branch_5_x/testsuite/src/resources/cluster/profileservice/farm-huge-web.xml)
===================================================================
--- trunk/testsuite/src/resources/cluster/profileservice/farm-huge-web.xml	                        (rev 0)
+++ trunk/testsuite/src/resources/cluster/profileservice/farm-huge-web.xml	2009-10-02 22:13:25 UTC (rev 94300)
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE web-app PUBLIC
+   "-//Sun Microsystems, Inc.//DTD Web Application 2.3//EN"
+   "http://java.sun.com/dtd/web-app_2_3.dtd">
+
+<web-app>
+   <description>A huge war</description>
+</web-app>




More information about the jboss-cvs-commits mailing list