[jboss-cvs] JBossAS SVN: r112199 - in branches/JBPAPP_5_1: testsuite/src/main/org/jboss/test/deployment and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Sat Sep 3 20:23:38 EDT 2011


Author: bmaxwell
Date: 2011-09-03 20:23:37 -0400 (Sat, 03 Sep 2011)
New Revision: 112199

Modified:
   branches/JBPAPP_5_1/system-jmx/src/main/org/jboss/deployment/MainDeployer.java
   branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/deployment/JBPAPP6716UnitTestCase.java
Log:
[JBPAPP-6716] removed ManagementView dependency to improve performance - added more tests to testcase

Modified: branches/JBPAPP_5_1/system-jmx/src/main/org/jboss/deployment/MainDeployer.java
===================================================================
--- branches/JBPAPP_5_1/system-jmx/src/main/org/jboss/deployment/MainDeployer.java	2011-09-03 02:13:01 UTC (rev 112198)
+++ branches/JBPAPP_5_1/system-jmx/src/main/org/jboss/deployment/MainDeployer.java	2011-09-04 00:23:37 UTC (rev 112199)
@@ -32,10 +32,10 @@
 import java.net.URL;
 import java.net.URLClassLoader;
 import java.util.ArrayList;
-import java.util.Arrays;
 import java.util.Collection;
 import java.util.Collections;
 import java.util.Comparator;
+import java.util.Date;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
@@ -46,6 +46,7 @@
 import java.util.StringTokenizer;
 import java.util.jar.Attributes;
 import java.util.jar.Manifest;
+
 import javax.management.MBeanServer;
 import javax.management.MalformedObjectNameException;
 import javax.management.Notification;
@@ -54,19 +55,12 @@
 import org.jboss.bootstrap.spi.ServerConfig;
 import org.jboss.deployers.client.spi.DeployerClient;
 import org.jboss.deployers.client.spi.Deployment;
-import org.jboss.deployers.spi.management.deploy.DeploymentManager;
-import org.jboss.deployers.spi.management.deploy.DeploymentProgress;
-import org.jboss.deployers.spi.management.deploy.DeploymentStatus;
-import org.jboss.deployers.spi.management.KnownDeploymentTypes;
-import org.jboss.deployers.spi.management.ManagementView;
 import org.jboss.deployers.structure.spi.DeploymentContext;
 import org.jboss.deployers.structure.spi.DeploymentUnit;
 import org.jboss.deployers.structure.spi.main.MainDeployerStructure;
 import org.jboss.deployers.vfs.spi.client.VFSDeployment;
 import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
 import org.jboss.kernel.spi.dependency.KernelController;
-import org.jboss.managed.api.ManagedDeployment;
-import org.jboss.managed.api.ManagedProperty;
 import org.jboss.system.ServiceMBeanSupport;
 import org.jboss.system.server.ServerConfigLocator;
 import org.jboss.util.file.Files;
@@ -95,9 +89,6 @@
    /** The controller */
    private KernelController controller;
    private DeployerClient delegate;
-   private DeploymentManager deploymentManager;
-   private ManagementView managementView;
-   private List<String> deployed = Collections.synchronizedList(new ArrayList<String>());   
    private Map<URL, String> contextMap = Collections.synchronizedMap(new HashMap<URL, String>());
 
    /** The deployment factory */
@@ -163,7 +154,7 @@
    }
    public void setKernelMainDeployer(DeployerClient delegate)
    {
-      this.delegate = delegate;
+      this.delegate = (org.jboss.deployers.client.spi.main.MainDeployer) delegate;
    }
 
    public KernelController getController()
@@ -583,29 +574,36 @@
     * @jmx.managed-operation
     */
    public void redeploy(URL url) throws DeploymentException
-   {      
-      String urlspec = url.toString();
-      try
+   {
+      String deploymentName = contextMap.get(url);
+      
+      if(isDeployed(url))
       {
-         // only call undeploy if it is known else profileserivce will log an exception stacktrace
-         if(isDeployedManagementView(urlspec, null))
-            undeploy(urlspec);
-         else
-            log.info(urlspec + " was not deployed, calling deploy");
+         // then check deploymentName, if it is null then create
+         if(deploymentName == null)
+         {
+            deploymentName = getDeploymentName(url);
+         }
+                 
+         if (deploymentName != null)
+         {
+            try
+            {
+               Deployment deployment = delegate.getDeployment(deploymentName);
+               delegate.addDeployment(deployment);
+               delegate.process();
+               delegate.checkComplete(deployment);
+            }
+            catch (org.jboss.deployers.spi.DeploymentException e)
+            {
+               throw new DeploymentException(e);
+            }
+         }
       }
-      catch(Exception e)
+      else
       {
-         // if we fail to undeploy, then try to deploy, if that fails then exception will be thrown up
-         log.warn("error occured trying to undeploy: " + url + " proceeding to deploy");
+         deploy(url);
       }
-      try
-      {
-         deploy(urlspec);
-      }
-      catch(MalformedURLException me)
-      {
-         throw new DeploymentException(me);
-      }     
    }
 
    /**
@@ -662,6 +660,12 @@
    public void undeploy(URL url) throws DeploymentException
    {
       String deploymentName = contextMap.remove(url);
+      
+      if(deploymentName == null)
+      {         
+            deploymentName = getDeploymentName(url);       
+      }
+      
       if (deploymentName != null)
       {
          try
@@ -677,47 +681,10 @@
       }
       else
       {
-         // if the undeploy is called on a deployment not deployed by this mbean
-         // this will just warn, will not throw if url is not deployed, this was the previous behavior expected by testsuite
-         undeployDeploymentManager(url);
+         log.warn("undeploy '" + url + "' : package not deployed");
       }
    }
-   
-   private void undeployDeploymentManager(URL url) throws DeploymentException
-   {
-      String urlspec = url.toString();
-      try
-      {
-         if (deployed.contains(urlspec)) // it was originally deployed by this mbean
-         {
-            log.debug("deployment was deployed my MBean");
-            try
-            {
-               unDeployment(urlspec, true);
-            }
-            finally
-            {
-               deployed.remove(urlspec);
-            }
-         }
-         else
-         // it was originally deployed by deployment scanner, calling remove will delete it from deploy which we do not want
-         {
-            log.debug("in deploy dir, stop will not remove: " + urlspec);
-            unDeployment(urlspec, false);
-         }
-      }
-      catch (RuntimeException re)
-      {
-         log.warn("undeploy '" + urlspec + "' : package not deployed");
-      }
-      catch (Exception e)
-      {
-         throw new DeploymentException(e);
-      }
-   }
-   
-   
+
    /**
     * The <code>undeploy</code> method undeploys a package represented by a
     * DeploymentInfo object.
@@ -872,59 +839,26 @@
       // if it does not exist create a new deployment
       if (deploymentName == null)
       {
-         // check to see if this was deployed by something other than this mbean
-         if( isDeployedManagementView(url.toExternalForm(), null) )
+         try
          {
-            deployDeploymentManager(url);
+            VirtualFile file = VFS.createNewRoot(url);
+            VFSDeployment deployment = deploymentFactory.createVFSDeployment(file);
+            delegate.addDeployment(deployment);
+            deploymentName = deployment.getName();
+            delegate.process();
+            // TODO: JBAS-4292
+            contextMap.put(url, deploymentName);
+            delegate.checkComplete(deployment);
          }
-         else
-         {       
-            try
-            {
-               VirtualFile file = VFS.createNewRoot(url);
-               VFSDeployment deployment = deploymentFactory.createVFSDeployment(file);
-               delegate.addDeployment(deployment);
-               deploymentName = deployment.getName();
-               delegate.process();
-               // TODO: JBAS-4292
-               contextMap.put(url, deploymentName);
-               delegate.checkComplete(deployment);
-            }
-            catch(Exception e)
-            {
-               log.warn("Failed to deploy: "+url, e);
-               DeploymentException ex = new DeploymentException("Failed to deploy: "+url, e);
-               throw ex;
-            }
-         }
-      }                   
-   }
-   
-   private void deployDeploymentManager(URL url) throws DeploymentException
-   {
-      log.debug("deploy, url=" + url);
-
-      String urlspec = url.toString();
-      try
-      {
-         if (isDeployedManagementView(urlspec, null))
+         catch(Exception e)
          {
-            log.debug("already deployed, just start, do not distrubute" + urlspec);
-            doDeployment(urlspec, false);
+            log.warn("Failed to deploy: "+url, e);
+            DeploymentException ex = new DeploymentException("Failed to deploy: "+url, e);
+            throw ex;
          }
-         else
-         {
-            log.debug("not deployed, doDeployment, then add to MBean list" + urlspec);
-            doDeployment(urlspec, true);
-            deployed.add(urlspec);
-         }
       }
-      catch (Exception e)
-      {
-         throw new DeploymentException(e);
-      }
    }
-   
+      
    /**
     * The <code>deploy</code> method deploys a package represented by a DeploymentInfo object.
     *
@@ -1437,16 +1371,22 @@
     */
    public boolean isDeployed(URL url)
    {
-      String name = contextMap.get(url);
-      if (name == null)
+      try
       {
-         if (url == null)
-            throw new IllegalArgumentException("Null url");
-         
-         return isDeployedManagementView(url.toString(), DeploymentState.STARTED);
+         String name = contextMap.get(url);
+         if (name == null)
+         {                        
+            name = getDeploymentName(url);
+            if(name == null)
+               return false;
+         }
+   
+         return checkDeployed(name);
       }
-      
-      return checkDeployed(name);
+      catch(Exception e)
+      {
+         throw new RuntimeException(e);
+      }
    }
    
    /**
@@ -1582,23 +1522,8 @@
    }
 
    // Helper Methods for JBPAPP-6716 - we are calling the KernelController because if we had used injection we would need to change the MBean interface,
-   // which could cause backwards compatibilty issues for customers who are utilizing the current EAP 5.x MainDeployerMBean interface 
-   private ManagementView getManagementView()
-   {
-      if(managementView == null)
-         managementView = (ManagementView) controller.getInstalledContext("ManagementView").getTarget();
-      
-      return managementView;
-   }
-   
-   private DeploymentManager getDeploymentManager()
-   {
-      if(deploymentManager == null)
-         deploymentManager = (DeploymentManager) controller.getInstalledContext("DeploymentManager").getTarget();
-      return deploymentManager;
-   }
-      
-   private DeploymentInfo createDeploymentInfo(String urlPath, org.jboss.deployment.DeploymentState state) throws DeploymentException, MalformedURLException
+   // which could cause backwards compatibilty issues for customers who are utilizing the current EAP 5.x MainDeployerMBean interface       
+   private DeploymentInfo createDeploymentInfo(String urlPath, org.jboss.deployment.DeploymentState state, String status) throws DeploymentException, MalformedURLException
    {            
       if(urlPath.startsWith("vfs"))
       {
@@ -1607,196 +1532,68 @@
       
       DeploymentInfo di = new DeploymentInfo(new URL(urlPath), null, null);
       di.state = state;
+      di.status = status;
       
       // this is a hack to prevent SerializableDeploymentInfo from having a null pointer
       di.deployer = new JARDeployer();
       
       return di;
    }
-   
+         
    private Collection getAllDeployments()
    {
-      List<ManagedDeployment> managedDeployments = getManagedDeployments();
-      List<DeploymentInfo> deploymentInfos = new ArrayList<DeploymentInfo>(managedDeployments.size() + contextMap.size());
+      Date start = new Date();   
+      Collection<Deployment> deployments = delegate.getTopLevel();
       
-      for(URL url : contextMap.keySet())
+      List<DeploymentInfo> deploymentInfos = new ArrayList<DeploymentInfo>(deployments.size() + contextMap.size());
+                                 
+      for(Deployment deployment : deployments)
       {
          try
          {
-            org.jboss.deployers.spi.DeploymentState deploymentState = delegate.getDeploymentState(contextMap.get(url));                  
+            org.jboss.deployers.spi.DeploymentState deploymentState = delegate.getDeploymentState(deployment.getName());                  
             org.jboss.deployment.DeploymentState state = null;
+            String status = deploymentState.toString();
             
             // convert deployment state to DeploymentInfo state
             if(deploymentState == org.jboss.deployers.spi.DeploymentState.DEPLOYED)
-               state = org.jboss.deployment.DeploymentState.STARTED;
+            {
+               state = org.jboss.deployment.DeploymentState.STARTED;               
+            }
             else if(deploymentState == org.jboss.deployers.spi.DeploymentState.ERROR)
-               state = org.jboss.deployment.DeploymentState.FAILED;
+            {
+               state = org.jboss.deployment.DeploymentState.FAILED;               
+            }
             else if(deploymentState == org.jboss.deployers.spi.DeploymentState.UNDEPLOYED)
-               state = org.jboss.deployment.DeploymentState.STOPPED;            
+            {
+               state = org.jboss.deployment.DeploymentState.STOPPED;               
+            }
                                     
-            deploymentInfos.add(createDeploymentInfo(url.toExternalForm(), state));
+            deploymentInfos.add(createDeploymentInfo(deployment.getName(), state, status));            
          }
          catch(Exception e)
          {
-            log.warn("Unable to convert deployment: " + url + " to DeploymentInfo", e);
+            log.warn("Unable to convert deployment: " + deployment + " to DeploymentInfo", e);
          }
       }
-               
-      // convert from ManagedDeployment object to DeploymentInfo object
-      for (ManagedDeployment md : managedDeployments)
-      {
-         try
-         {                                                           
-            deploymentInfos.add( createDeploymentInfo(md.getName(), org.jboss.deployment.DeploymentState.getDeploymentState(md.getDeploymentState().toString())) );
-         }
-         catch (Exception e)
-         {            
-            log.warn("Unable to convert managed deployment: " + md + " to DeploymentInfo", e);
-         }
-      }
+            
+      log.trace("getAllDeployments: " + (( new Date().getTime() - start.getTime() ) /1000));
       return deploymentInfos;
    }
-   
-   private List<ManagedDeployment> getManagedDeployments() throws RuntimeException
-   {      
-      try
-      {
-         getManagementView().reload();
-         List<ManagedDeployment> managedDeployments = new LinkedList<ManagedDeployment>();
-   
-         for (KnownDeploymentTypes type : KnownDeploymentTypes.values())
-         {            
-            Set<ManagedDeployment> deployments = getManagementView().getDeploymentsForType(type.getType());
-            managedDeployments.addAll(deployments);                           
-         }
-
-         return managedDeployments;
-      }
-      catch(Exception e)
-      {         
-         log.error("Error getting deployments from ManagementView", e);
-         // this only returning message for twiddle calls that don't have access to the profile exceptions
-         throw new RuntimeException(e.getMessage());
-      }
-   }
-   
-   private boolean isDeployedManagementView(String url, DeploymentState state)
-   {
-      String simpleName = getFilenameFromURL(url);
-
-      List<ManagedDeployment> managedDeployments = getManagedDeployments();
-
-      for (ManagedDeployment deployment : managedDeployments)
-      {
-         log.trace("SimpleName: " + deployment.getSimpleName() + "State: " + deployment.getDeploymentState());
-         if (simpleName.equals(deployment.getSimpleName()))
-         {
-            if (state == null)
-            {
-               return true;
-            }
-            else
-            {
-               return deployment.getDeploymentState().toString().compareTo(state.toString()) == 0;
-            }
-         }
-      }
-      return false;
-   }
-   
-   private String getFilenameFromURL( String url )
-   { 
-      String[] split_url = url.split("/");
-
-      return split_url[split_url.length - 1];
-   }
-   
-   private void handleStatusFailures( String message, DeploymentProgress progress ) throws Exception
-   {
-      DeploymentStatus status = progress.getDeploymentStatus();
-
-      if( status.isFailed() ) {
-        throw new Exception(message + " - " + status.getFailure());
-      }
-   }
-   
-   private void doDeployment(String url, boolean distribute)
-   {
-      try
-      {
-         URL contentURL = new URL(url);
-         log.debug("Content URL: " + contentURL);
-   
-         String name = this.getFilenameFromURL(url);
-   
-         log.debug("Content Name: " + name);
-            
-         DeploymentProgress progress;
-         String[] uploadedNames = new String[] { name };    
-         
-         if(distribute)
-         {
-            log.trace("distribute: " + url);
-            // Upload the deployment target
-            // false means do not copy to the deploy directory
-            progress = getDeploymentManager().distribute(name, contentURL, false);
-            
-            progress.run();
-   
-            handleStatusFailures( "doDeployment.distribute", progress );
-            
-            // Get the unique deployment name
-            uploadedNames = progress.getDeploymentID().getRepositoryNames();
       
-            log.debug("Uploaded deployment names: "+Arrays.asList(uploadedNames));
-         }
-            
-         log.trace("start: " + url);
-         // Now start the deployment
-         progress = getDeploymentManager().start(uploadedNames);
-         progress.run();
-   
-         handleStatusFailures( "doDeployment.start", progress );
-      }
-      catch(Exception e)
-      {                 
-         log.error("Error distributing / starting using DeploymentManager", e);
-         // this only returning message for twiddle calls that don't have access to the profile exceptions
-         throw new RuntimeException(e.getMessage());
-      }
-   }
-
-   private void unDeployment(String name, boolean remove)
+   private String getDeploymentName(URL url)
    {
       try
       {
-         String simpleName = this.getFilenameFromURL(name);
-   
-         String[] uploadedNames = {simpleName};
-   
-         // Stop the deployment         
-         log.trace("stop: " + name);
-         DeploymentProgress progress = getDeploymentManager().stop(uploadedNames);
-         progress.run();
-   
-         handleStatusFailures( "unDeployment.stop", progress );
-   
-         if(remove)
-         {
-            // Remove the deployment
-            log.trace("remove: " + name);
-            progress = getDeploymentManager().remove(uploadedNames);
-            progress.run();
-      
-            handleStatusFailures( "unDeployment.remove", progress );
-         }
+         VirtualFile file = VFS.createNewRoot(url);         
+         VFSDeployment deployment = deploymentFactory.createVFSDeployment(file);
+         return deployment.getName();
       }
-      catch(Exception e)
-      {                 
-         log.error("Error stopping / remove using DeploymentManager", e);
-         // this only returning message for twiddle calls that don't have access to the profile exceptions
-         throw new RuntimeException(e.getMessage());
-      }
-   }      
+      catch(IOException io)
+      {
+         // return null since the url was not valid
+         return null;
+      }      
+   }  
    // End of : Helper Methods for JBPAPP-6716
 }

Modified: branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/deployment/JBPAPP6716UnitTestCase.java
===================================================================
--- branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/deployment/JBPAPP6716UnitTestCase.java	2011-09-03 02:13:01 UTC (rev 112198)
+++ branches/JBPAPP_5_1/testsuite/src/main/org/jboss/test/deployment/JBPAPP6716UnitTestCase.java	2011-09-04 00:23:37 UTC (rev 112199)
@@ -19,22 +19,21 @@
 
 import java.io.BufferedReader;
 import java.io.File;
-import java.io.FileInputStream;
 import java.io.FileOutputStream;
 import java.io.IOException;
 import java.io.InputStream;
 import java.io.InputStreamReader;
+import java.net.MalformedURLException;
 import java.net.URL;
 import java.net.URLConnection;
 import java.security.Principal;
 import java.util.Collection;
-import java.util.Date;
-import java.util.Properties;
 
 import javax.management.JMX;
 import javax.management.MBeanServerConnection;
 import javax.management.ObjectName;
 
+import org.jboss.deployment.DeploymentException;
 import org.jboss.deployment.MainDeployerMBean;
 import org.jboss.mx.util.ObjectNameFactory;
 import org.jboss.security.SecurityAssociation;
@@ -59,6 +58,7 @@
    private String JBOSS_HOME;
    private String JBOSS_DEPLOY;
    private Object[] previousSecurity = new Object[2];
+   private int maxWaitForHDScanner = 10;
 
    public JBPAPP6716UnitTestCase(String name) throws Exception
    {
@@ -119,29 +119,29 @@
       {
          //Deploy & undeploy with URL
          deployer.deploy(dummyUrl);
-         assertTrue("Failed to deploy URL", isDeployed(dummyUrl, false));
+         assertTrue("Failed to deploy URL: " + dummyUrl, isDeployed(dummyUrl, false));
 
          deployer.undeploy(dummyUrl);
-         assertTrue(dummyUrlString + " is not deployed when it should be", !isDeployed(dummyUrl, false));
+         assertTrue("Failed to undeploy URL: " + dummyUrl, !isDeployed(dummyUrl, false));
 
          //Deploy & undeploy with String
          deployer.deploy(dummyUrlString);
-         assertTrue(isDeployed(dummyUrl, true));
+         assertTrue("Failed to deploy String: " + dummyUrlString, isDeployed(dummyUrl, true));
 
          deployer.undeploy(dummyUrlString);
-         assertTrue(!isDeployed(dummyUrl, true));
+         assertTrue("Failed to undeploy String: " + dummyUrlString, !isDeployed(dummyUrl, true));
 
          //Redploy 
          deployer.deploy(dummyUrl);
-         assertTrue(isDeployed(dummyUrl, false));
+         assertTrue("Failed to deploy URL: " + dummyUrl, isDeployed(dummyUrl, false));
 
          //With URL
          deployer.redeploy(dummyUrl);
-         assertTrue(isDeployed(dummyUrl, false));
+         assertTrue("Failed to redeploy URL: " + dummyUrl, isDeployed(dummyUrl, false));
 
          //With String
          deployer.redeploy(dummyUrlString);
-         assertTrue(isDeployed(dummyUrl, true));
+         assertTrue("Failed to redeploy String: " + dummyUrlString, isDeployed(dummyUrl, true));
       }
       catch (Exception e)
       {
@@ -165,9 +165,8 @@
    // run tests using $JBOSS_HOME/bin/twiddle.sh
    public void testTwiddle()
    {
-      // $JBOSS_HOME/bin/twiddle.sh -u admin -p admin invoke jboss.system:service=MainDeployer listDeployedAsString      
-      String invoke = "-s " + hostname + " -u admin -p admin invoke jboss.system:service=MainDeployer ";
-
+      // $JBOSS_HOME/bin/twiddle.sh -u admin -p admin -s hostname invoke jboss.system:service=MainDeployer listDeployedAsString      
+      String invoke = "-u admin -p admin -s " + hostname + " invoke jboss.system:service=MainDeployer ";
       String[] deployments = new String[] 
                                         { 
             dummyUrl.toExternalForm(), 
@@ -222,24 +221,14 @@
    
    public void testDeploymentsInDeployDirectory()
    {
-      File dummyWarFile = new File(JBOSS_DEPLOY,"dummy.war");
+      File dummyWarFile = new File(JBOSS_DEPLOY, "dummy.war");
       try
       {
          // copy dummy.war to deploy directory
          copyUrlToFile(dummyUrl, dummyWarFile);
          
-         // wait 1 second for deployment, max of 5 seconds, then fail         
-         int attempts = 0;
-         do
-         {
-            Thread.sleep(1000);
-            attempts++;
-         } while (deployer.isDeployed(dummyWarFile.getAbsolutePath()) == false && attempts < 5);
-         
-         if(attempts >= 5)
-         {
-            fail("Failed to deploy: " + dummyWarFile.getAbsolutePath() + " waited 5 seconds and it has not been deployed");
-         }
+         // wait 1 second for deployment, max of 5 seconds, then fail
+         failIfIsFileDeployedNotEqual(dummyWarFile, true);
             
          // call undeploy, confirm dummy.war file is still in deploy dir and that it is not running, else fail
          log.info("call undeploy, confirm dummy.war file is still in deploy dir and that it is not running, else fail");
@@ -268,6 +257,7 @@
       }
       catch(Exception e)
       {
+         log.error("testDeploymentsInDeployDirectory failed", e);
          fail(e.getMessage());
       }
       finally
@@ -277,24 +267,8 @@
          {
             fail("Failed to remove: " + dummyWarFile.getAbsolutePath() + " test deployment from: " + JBOSS_DEPLOY);
          }
-         int attempts = 0;
-         try
-         {
-            do
-            {
-               Thread.sleep(1000);
-               attempts++;
-            } while (deployer.isDeployed(dummyWarFile.getAbsolutePath()) == true && attempts < 5);
-            
-            if(attempts >= 5)
-            {
-               fail("Failed to undeploy: " + dummyWarFile.getAbsolutePath() + " waited 5 seconds and it has not been undeployed");
-            }
-         }
-         catch(Exception e)
-         {
-            
-         }                  
+         
+         failIfIsFileDeployedNotEqual(dummyWarFile, false);          
       }
    }      
    
@@ -347,6 +321,82 @@
       }
    }
    
+   // tests isDeployed, undeploy, deploy, redeploy with a URL/String does not exist
+   public void testNonExistantDeployments()
+   {
+      // this file does not exist
+      File nonExistantFile = new File(JBOSS_DEPLOY, "jbpapp6716-non-existant.war");
+      
+      if(nonExistantFile.exists())
+      {
+         fail("The file: " + nonExistantFile + " should not exist");
+      }
+      
+      // isDeployed should return false
+      try
+      {
+         assertFalse("isDeployed should return false for non-existant deployment: " + nonExistantFile, deployer.isDeployed(nonExistantFile.getAbsolutePath()));;
+      }
+      catch(Exception e)
+      {
+         log.error("isDeployed threw an exception checking non-existant file: " + nonExistantFile, e);
+         fail("isDeployed should not throw an exception checking non-existant file: " + nonExistantFile);
+      }
+            
+      // undeploy should not throw an exception, it should just display a warning in the server.log
+      try
+      {
+         deployer.undeploy(nonExistantFile.getAbsolutePath());
+      }
+      catch(Exception e)
+      {
+         log.error("undeploy threw an exception checking non-existant file: " + nonExistantFile, e);
+         fail("undeploy should not throw an exception checking non-existant file: " + nonExistantFile + " , it should just have a warning in the JBoss server.log");
+      }
+      
+      // deploy should throw an exception
+      boolean fail = true;
+      try
+      {
+         deployer.deploy(nonExistantFile.getAbsolutePath());         
+      }
+      catch(MalformedURLException me)
+      {
+         log.error("deploy threw an MalformedURLException checking non-existant file: " + nonExistantFile, me);
+         fail("deploy should not throw a MalformedURLException checking non-existant file: " + nonExistantFile);         
+      }
+      catch(DeploymentException de)
+      {
+         log.error("deploy threw an exception as expected when checking non-existant file: " + nonExistantFile, de);
+         fail = false;
+      }
+      if(fail)
+      {
+         fail("deploy should have thrown a DeploymentException checking non-existant file: " + nonExistantFile);
+      }
+      
+      // redeploy should throw an exception
+      fail = true;
+      try
+      {
+         deployer.redeploy(nonExistantFile.getAbsolutePath());         
+      }
+      catch(MalformedURLException me)
+      {
+         log.error("redeploy threw an MalformedURLException checking non-existant file: " + nonExistantFile, me);
+         fail("redeploy should not throw a MalformedURLException checking non-existant file: " + nonExistantFile);         
+      }
+      catch(DeploymentException de)
+      {
+         log.error("redeploy threw an exception as expected when checking non-existant file: " + nonExistantFile, de);
+         fail = false;
+      }
+      if(fail)
+      {
+         fail("redeploy should have thrown a DeploymentException checking non-existant file: " + nonExistantFile);
+      }
+   }
+   
    /** Utility Methods **/
    
    private void cleanUp()
@@ -382,21 +432,56 @@
          throws Exception
    {
       boolean isDeployed = false;
-      for (int tries = 0; tries < 5; tries++)
-      {
-         // sleep for 3 secs
-//         Thread.sleep(3000);
+
          if(isString)
             isDeployed = deployer.isDeployed(url.toExternalForm());
          else
             isDeployed = deployer.isDeployed(url);
 
-         if(isDeployed)
-            break;
-      }
       return isDeployed;
    }
    
+   private void failIfIsFileDeployedNotEqual(File file, boolean isDeployed)
+   {
+      int attempts = 0;
+      String message = "undeploy";
+      if(isDeployed)
+      {         
+         message = "deploy";
+      }   
+      try
+      {
+         try
+         {
+            // wait 1 second for deployment, max of 5 seconds, then fail                  
+            do
+            {
+               Thread.sleep(1000);
+               attempts++;
+            } while (deployer.isDeployed(file.getAbsolutePath()) != isDeployed && attempts < maxWaitForHDScanner);
+            
+            if(attempts >= maxWaitForHDScanner)
+            {                  
+               fail("Failed to " + message + file.getAbsolutePath() + ", waited " + attempts + " seconds and it has not been " + message + "ed");
+            }
+            else
+            {
+               log.info("Waited " + attempts + " seconds for hd scanner to " + message + " " + file.getAbsolutePath());         
+            }
+         }
+         catch(InterruptedException ie)
+         {
+            if(deployer.isDeployed(file.getAbsolutePath()) != isDeployed)
+               fail("Failed to " + message + file.getAbsolutePath() + ", waited " + attempts + " seconds and it has not been " + message + "ed, and sleep interrupted");         
+         }
+      }
+      catch(MalformedURLException me)
+      {
+         log.error(file.getAbsolutePath() + " is malformed", me);
+         fail(file.getAbsolutePath() + " is malformed");         
+      }            
+   }
+   
    private void twiddle(String args, String searchString)
    {
       String command = JBOSS_HOME + "/bin/twiddle.sh " + args;      
@@ -427,7 +512,6 @@
 
          // if exit code is not 0, then we also fail
          pass &= (child.waitFor() == 0);
-         //         pass &= (child.exitValue() == 0);
 
          if (!pass)
             fail(command + " failed, exitCode=" + child.exitValue() + " should be 0 and output should contain: "
@@ -537,4 +621,4 @@
          }            
       }
    }
-}
+}
\ No newline at end of file



More information about the jboss-cvs-commits mailing list