[jboss-cvs] JBossAS SVN: r94295 - in branches/Branch_5_x/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 15:49:43 EDT 2009
Author: bstansberry at jboss.com
Date: 2009-10-02 15:49:43 -0400 (Fri, 02 Oct 2009)
New Revision: 94295
Added:
branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/profileservice/test/FarmedClusterHugeDeploymentUnitTestCase.java
branches/Branch_5_x/testsuite/src/resources/cluster/profileservice/farm-huge-index.html
branches/Branch_5_x/testsuite/src/resources/cluster/profileservice/farm-huge-web.xml
Modified:
branches/Branch_5_x/testsuite/imports/sections/cluster.xml
Log:
[JBAS-7102] Add a test of farming a 150MB file.
Modified: branches/Branch_5_x/testsuite/imports/sections/cluster.xml
===================================================================
--- branches/Branch_5_x/testsuite/imports/sections/cluster.xml 2009-10-02 19:48:30 UTC (rev 94294)
+++ branches/Branch_5_x/testsuite/imports/sections/cluster.xml 2009-10-02 19:49:43 UTC (rev 94295)
@@ -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">
Added: branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/profileservice/test/FarmedClusterHugeDeploymentUnitTestCase.java
===================================================================
--- branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/profileservice/test/FarmedClusterHugeDeploymentUnitTestCase.java (rev 0)
+++ branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/profileservice/test/FarmedClusterHugeDeploymentUnitTestCase.java 2009-10-02 19:49:43 UTC (rev 94295)
@@ -0,0 +1,256 @@
+/*
+ * 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 farmDir;
+
+ /**
+ * Create a new FarmedClusterHotDeployUnitTestCase.
+ *
+ * @param name
+ */
+ public FarmedClusterHugeDeploymentUnitTestCase(String name)
+ {
+ super(name);
+ }
+
+ public void testFarmHotDeployment() throws Exception
+ {
+ ManagementView mgtView = getManagementView(getNamingContext(0));
+ ComponentType type = new ComponentType("MCBean", "ServerConfig");
+ ManagedComponent mc = mgtView.getComponent("jboss.system:type=ServerConfig", type);
+ assertNotNull(mc);
+ String homeDir = (String) ((SimpleValue) mc.getProperty("serverHomeDir").getValue()).getValue();
+ assertNotNull(homeDir);
+
+ this.farmDir = new File(homeDir, "farm");
+ assertTrue(farmDir + " exists", farmDir.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(farmDir, "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);
+ for (int i = 0; i < 150 * 1024 * 1024; i++)
+ bos.write(i);
+ 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 (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();
+ }
+ }
+
+}
Property changes on: branches/Branch_5_x/testsuite/src/main/org/jboss/test/cluster/defaultcfg/profileservice/test/FarmedClusterHugeDeploymentUnitTestCase.java
___________________________________________________________________
Name: svn:keywords
+
Added: branches/Branch_5_x/testsuite/src/resources/cluster/profileservice/farm-huge-index.html
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/cluster/profileservice/farm-huge-index.html (rev 0)
+++ branches/Branch_5_x/testsuite/src/resources/cluster/profileservice/farm-huge-index.html 2009-10-02 19:49:43 UTC (rev 94295)
@@ -0,0 +1 @@
+<html><head><title>Huge</title></head><body><p>Huge</p></body></html>
\ No newline at end of file
Added: branches/Branch_5_x/testsuite/src/resources/cluster/profileservice/farm-huge-web.xml
===================================================================
--- branches/Branch_5_x/testsuite/src/resources/cluster/profileservice/farm-huge-web.xml (rev 0)
+++ branches/Branch_5_x/testsuite/src/resources/cluster/profileservice/farm-huge-web.xml 2009-10-02 19:49:43 UTC (rev 94295)
@@ -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>
Property changes on: branches/Branch_5_x/testsuite/src/resources/cluster/profileservice/farm-huge-web.xml
___________________________________________________________________
Name: svn:keywords
+
More information about the jboss-cvs-commits
mailing list