[jboss-cvs] JBossAS SVN: r74791 - in trunk: profileservice/src/main/org/jboss/profileservice/management/upload/remoting and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Wed Jun 18 07:54:58 EDT 2008


Author: alesj
Date: 2008-06-18 07:54:58 -0400 (Wed, 18 Jun 2008)
New Revision: 74791

Modified:
   trunk/profileservice/src/main/org/jboss/profileservice/management/upload/DeploymentManagerImpl.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/DeployHandler.java
   trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/StreamingDeploymentTarget.java
   trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
   trunk/testsuite/src/main/org/jboss/test/profileservice/test/DeployUnitTestCase.java
Log:
Refactory DeployUTC.
Add try/finally when using locks.

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/upload/DeploymentManagerImpl.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/upload/DeploymentManagerImpl.java	2008-06-18 11:33:34 UTC (rev 74790)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/upload/DeploymentManagerImpl.java	2008-06-18 11:54:58 UTC (rev 74791)
@@ -129,8 +129,7 @@
       List<DeploymentTarget> targets = getDeploymentTargets();
       SerializableDeploymentID deployment = new SerializableDeploymentID(name, phase, contentURL.toString());
       deployment.setContentURL(contentURL);
-      DeploymentProgressImpl progressImpl = new DeploymentProgressImpl(targets, deployment, CommandType.DISTRIBUTE);
-      return progressImpl;
+      return new DeploymentProgressImpl(targets, deployment, CommandType.DISTRIBUTE);
    }
 
 
@@ -159,8 +158,7 @@
    {
       List<DeploymentTarget> targets = getDeploymentTargets();
       SerializableDeploymentID deployment = new SerializableDeploymentID(name, phase, null);
-      DeploymentProgressImpl progressImpl = new DeploymentProgressImpl(targets, deployment, CommandType.REDEPLOY);
-      return progressImpl;
+      return new DeploymentProgressImpl(targets, deployment, CommandType.REDEPLOY);
    }
 
    public DeploymentProgress prepare(DeploymentPhase phase, String... names)
@@ -168,8 +166,7 @@
    {
       List<DeploymentTarget> targets = getDeploymentTargets();
       SerializableDeploymentID deployment = new SerializableDeploymentID(names, phase, null);
-      DeploymentProgressImpl progressImpl = new DeploymentProgressImpl(targets, deployment, CommandType.PREPARE);
-      return progressImpl;
+      return new DeploymentProgressImpl(targets, deployment, CommandType.PREPARE);
    }
 
    public DeploymentProgress start(DeploymentPhase phase, String... names)
@@ -177,8 +174,7 @@
    {
       List<DeploymentTarget> targets = getDeploymentTargets();
       SerializableDeploymentID deployment = new SerializableDeploymentID(names, phase, null);
-      DeploymentProgressImpl progressImpl = new DeploymentProgressImpl(targets, deployment, CommandType.START);
-      return progressImpl;
+      return new DeploymentProgressImpl(targets, deployment, CommandType.START);
    }
 
    public DeploymentProgress stop(DeploymentPhase phase, String... names)
@@ -186,16 +182,14 @@
    {
       List<DeploymentTarget> targets = getDeploymentTargets();
       SerializableDeploymentID deployment = new SerializableDeploymentID(names, phase, null);
-      DeploymentProgressImpl progressImpl = new DeploymentProgressImpl(targets, deployment, CommandType.STOP);
-      return progressImpl;   }
+      return new DeploymentProgressImpl(targets, deployment, CommandType.STOP);
+   }
 
-   public DeploymentProgress undeploy(DeploymentPhase phase, String... names)
-      throws Exception
+   public DeploymentProgress undeploy(DeploymentPhase phase, String... names) throws Exception
    {
       List<DeploymentTarget> targets = getDeploymentTargets();
       SerializableDeploymentID deployment = new SerializableDeploymentID(names, phase, null);
-      DeploymentProgressImpl progressImpl = new DeploymentProgressImpl(targets, deployment, CommandType.UNDEPLOY);
-      return progressImpl;
+      return new DeploymentProgressImpl(targets, deployment, CommandType.UNDEPLOY);
    }
 
    /**

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/DeployHandler.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/DeployHandler.java	2008-06-18 11:33:34 UTC (rev 74790)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/DeployHandler.java	2008-06-18 11:54:58 UTC (rev 74791)
@@ -21,29 +21,16 @@
  */
 package org.jboss.profileservice.management.upload.remoting;
 
-import java.io.BufferedInputStream;
-import java.io.BufferedOutputStream;
-import java.io.File;
-import java.io.FileNotFoundException;
-import java.io.FileOutputStream;
-import java.io.IOException;
 import java.io.InputStream;
-import java.net.URI;
 import java.util.Arrays;
 import java.util.Map;
-import java.util.zip.ZipInputStream;
-
 import javax.management.MBeanServer;
-import javax.management.MBeanServerInvocationHandler;
-import javax.management.ObjectName;
 
 import org.jboss.aop.joinpoint.Invocation;
 import org.jboss.aop.joinpoint.InvocationResponse;
 import org.jboss.aspects.remoting.AOPRemotingInvocationHandler;
 import org.jboss.deployers.client.spi.main.MainDeployer;
-import org.jboss.deployers.spi.management.deploy.DeploymentTarget;
 import org.jboss.deployers.spi.management.deploy.DeploymentID;
-import org.jboss.deployers.vfs.plugins.client.AbstractVFSDeployment;
 import org.jboss.deployers.vfs.spi.client.VFSDeployment;
 import org.jboss.deployers.vfs.spi.client.VFSDeploymentFactory;
 import org.jboss.logging.Logger;
@@ -54,7 +41,6 @@
 import org.jboss.remoting.ServerInvoker;
 import org.jboss.remoting.callback.InvokerCallbackHandler;
 import org.jboss.remoting.stream.StreamInvocationHandler;
-import org.jboss.virtual.VFS;
 import org.jboss.virtual.VirtualFile;
 
 /**
@@ -110,7 +96,7 @@
    {
       SerializableDeploymentID deploymentTarget = (SerializableDeploymentID) request.getParameter();
       log.debug("handleStream, deploymentTarget: "+deploymentTarget);
-      Map payload = request.getRequestPayload();
+      //Map payload = request.getRequestPayload();
       deploymentTarget.setContentIS(contentIS);
       DeploymentPhase phase = deploymentTarget.getPhase();
       //ZipInputStream zis = new ZipInputStream(contentIS);
@@ -135,8 +121,7 @@
 
       if(parameter instanceof Invocation)
       {
-         InvocationResponse value = (InvocationResponse) super.invoke(request);
-         returnValue = value;
+         returnValue = super.invoke(request);
       }
       else
       {
@@ -178,18 +163,24 @@
       log.info("Begin start, "+Arrays.asList(names));
       // Prevent hot deployment scans from seeing in transition deployments
       deploymentRepository.acquireDeploymentContentLock();
-      for(String name : names)
+      try
       {
-         VirtualFile vf = deploymentRepository.getDeploymentContent(name, dtID.getPhase());
-         VFSDeployment vfsd = createDeployment(vf);
-         deploymentRepository.addDeployment(vf.getName(), vfsd, dtID.getPhase());
-         deploymentRepository.unlockDeploymentContent(vf.getPathName(), dtID.getPhase());
-         mainDeployer.addDeployment(vfsd);
-         log.info("Started: "+vfsd);
+         for(String name : names)
+         {
+            VirtualFile vf = deploymentRepository.getDeploymentContent(name, dtID.getPhase());
+            VFSDeployment vfsd = createDeployment(vf);
+            deploymentRepository.addDeployment(vf.getName(), vfsd, dtID.getPhase());
+            deploymentRepository.unlockDeploymentContent(vf.getPathName(), dtID.getPhase());
+            mainDeployer.addDeployment(vfsd);
+            log.info("Started: "+vfsd);
+         }
+         mainDeployer.process();
+         mainDeployer.checkComplete();
       }
-      mainDeployer.process();
-      mainDeployer.checkComplete();
-      deploymentRepository.releaseDeploymentContentLock();
+      finally
+      {
+         deploymentRepository.releaseDeploymentContentLock();
+      }
       log.info("End start, "+Arrays.asList(names));
    }
 

Modified: trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/StreamingDeploymentTarget.java
===================================================================
--- trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/StreamingDeploymentTarget.java	2008-06-18 11:33:34 UTC (rev 74790)
+++ trunk/profileservice/src/main/org/jboss/profileservice/management/upload/remoting/StreamingDeploymentTarget.java	2008-06-18 11:54:58 UTC (rev 74791)
@@ -21,17 +21,19 @@
  */
 package org.jboss.profileservice.management.upload.remoting;
 
+import java.io.IOException;
 import java.io.InputStream;
 import java.io.Serializable;
 import java.net.URL;
+import java.util.Collections;
 import java.util.HashMap;
+import java.util.Map;
 
+import org.jboss.deployers.spi.management.deploy.DeploymentID;
 import org.jboss.deployers.spi.management.deploy.DeploymentTarget;
-import org.jboss.deployers.spi.management.deploy.DeploymentID;
 import org.jboss.logging.Logger;
 import org.jboss.profileservice.management.upload.SerializableDeploymentID;
 import org.jboss.remoting.Client;
-import org.jboss.remoting.InvocationRequest;
 import org.jboss.remoting.InvokerLocator;
 
 /**
@@ -84,18 +86,23 @@
    public void distribute(DeploymentID deployment)
       throws Exception
    {
-      DeploymentID moduleID = deployment;
       URL contentURL = deployment.getContentURL();
-      SerializableDeploymentID sdtID = new SerializableDeploymentID(moduleID);
-      InputStream contentIS = contentURL.openStream();
-      sdtID.setContentIS(contentIS);
+      SerializableDeploymentID sdtID = new SerializableDeploymentID(deployment);
       Client client = getClient();
-      log.info("Begin deploy: " + moduleID);
-      transferDeployment(client, sdtID);
-      log.info("End deploy");
-      contentIS.close();
-      client.disconnect();
+      try
+      {
+         InputStream contentIS = contentURL.openStream();
+         sdtID.setContentIS(contentIS);
+         log.info("Begin deploy: " + deployment);
+         transferDeployment(client, sdtID);
+         log.info("End deploy");
+      }
+      finally
+      {
+         client.disconnect();
+      }
    }
+
    public void redeploy(DeploymentID deployment)
       throws Exception
    {
@@ -109,15 +116,24 @@
    }
 
    /**
+    * Create the client args.
+    *
+    * @param dtID the deployment id
+    * @return args map
+    */
+   protected Map<?, ?> createArgs(DeploymentID dtID)
+   {
+      return new HashMap<Object, Object>(Collections.singletonMap("DeploymentTargetID", dtID));
+   }
+
+   /**
     * Start a given deployment(s)
     */
    public void start(DeploymentID dtID) throws Exception
    {
       Client client = getClient();
       log.debug("Start: " + dtID);
-      HashMap<String, DeploymentID> args = new HashMap<String, DeploymentID>(1);
-      args.put("DeploymentTargetID", dtID);
-      invoke(client, "start", args);
+      invoke(client, "start", createArgs(dtID));
       log.info("End start: "+dtID);
    }
 
@@ -127,11 +143,16 @@
    public void stop(DeploymentID dtID) throws Exception
    {
       Client client = getClient();
-      HashMap<String, DeploymentID> args = new HashMap<String, DeploymentID>(1);
-      args.put("DeploymentTargetID", dtID);
-      log.info("Begin stop: " + dtID);
-      invoke(client, "stop", args);
-      log.info("End stop");
+      try
+      {
+         log.info("Begin stop: " + dtID);
+         invoke(client, "stop", createArgs(dtID));
+         log.info("End stop");
+      }
+      finally
+      {
+         client.disconnect();
+      }
    }
 
    /**
@@ -140,11 +161,16 @@
    public void undeploy(DeploymentID dtID) throws Exception
    {
       Client client = getClient();
-      HashMap<String, DeploymentID> args = new HashMap<String, DeploymentID>(1);
-      args.put("DeploymentTargetID", dtID);
-      log.info("Begin undeploy: " + dtID);
-      invoke(client, "undeploy", args);
-      log.info("End undeploy");
+      try
+      {
+         log.info("Begin undeploy: " + dtID);
+         invoke(client, "undeploy", createArgs(dtID));
+         log.info("End undeploy");
+      }
+      finally
+      {
+         client.disconnect();
+      }
    }
    /**
     * Get the remoting client connection
@@ -168,10 +194,6 @@
       {
          client.invoke(is, sdtID);
       }
-      catch(Exception e)
-      {
-         throw e;
-      }
       catch(Error e)
       {
          throw new RuntimeException(e);
@@ -182,22 +204,23 @@
       }
       finally
       {
-         is.close();
+         try
+         {
+            is.close();
+         }
+         catch (IOException ignored)
+         {
+         }
       }
    }
 
-   private Object invoke(Client client, String name, HashMap<?, ?> args)
+   private Object invoke(Client client, String name, Map<?, ?> args)
       throws Exception
    {
       try
       {
-         Object returnValue = client.invoke(name, args);
-         return returnValue;
+         return client.invoke(name, args);
       }
-      catch(Exception e)
-      {
-         throw e;
-      }
       catch(Error e)
       {
          throw new RuntimeException(e);
@@ -207,5 +230,4 @@
          throw new RuntimeException(e);         
       }      
    }
-
 }

Modified: trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java
===================================================================
--- trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java	2008-06-18 11:33:34 UTC (rev 74790)
+++ trunk/system/src/main/org/jboss/system/server/profileservice/repository/SerializableDeploymentRepository.java	2008-06-18 11:54:58 UTC (rev 74791)
@@ -243,37 +243,53 @@
    {
       boolean trace = log.isTraceEnabled();
       // Suspend hot deployment checking
+      if( trace )
+         log.trace("Aquiring content read lock");
       contentLock.writeLock().lock();
-      if( trace )
-         log.trace("Aquired content read lock");
+      try
+      {
+         // Write the content out
+         URI uri = getPhaseURI(phase);
+         if(uri == null)
+            throw new FileNotFoundException("Failed to obtain content URI for phase: "+phase);
+         File contentRoot = new File(uri);
+         File contentFile = new File(contentRoot, name);
+         if(failIfAlreadyExists && contentFile.exists())
+            throw new SyncFailedException("Deployment content already exists: "+contentFile.getAbsolutePath());
+         FileOutputStream fos = new FileOutputStream(contentFile);
+         try
+         {
+            byte[] tmp = new byte[4096];
+            int read;
+            while((read = contentIS.read(tmp)) > 0)
+            {
+                  log.info("write, "+read);
+                  fos.write(tmp, 0, read);
+            }
+            fos.flush();
+         }
+         finally
+         {
+            try
+            {
+               fos.close();
+            }
+            catch (IOException ignored)
+            {
+            }
+         }
+         //contentIS.close();
 
-      // Write the content out 
-      URI uri = getPhaseURI(phase);
-      if(uri == null)
-         throw new FileNotFoundException("Failed to obtain content URI for phase: "+phase);
-      File contentRoot = new File(uri);
-      File contentFile = new File(contentRoot, name);
-      if(failIfAlreadyExists && contentFile.exists())
-         throw new SyncFailedException("Deployment content already exists: "+contentFile.getAbsolutePath());
-      FileOutputStream fos = new FileOutputStream(contentFile);
-      byte[] tmp = new byte[4096];
-      int read = 0;
-      while((read = contentIS.read(tmp)) > 0)
+         // Lock the content
+         lockDeploymentContent(name, phase);
+      }
+      finally
       {
-         log.info("write, "+read);
-         fos.write(tmp, 0, read);
+         // Allow hot deployment checking
+         contentLock.writeLock().unlock();
+         if(trace)
+            log.trace("Released content write lock");
       }
-      fos.flush();
-      fos.close();
-      //contentIS.close();
-
-      // Lock the content
-      lockDeploymentContent(name, phase);
-
-      // Allow hot deployment checking
-      contentLock.writeLock().unlock();
-      if(trace)
-         log.trace("Released content write lock");
    }
 
    public VirtualFile getDeploymentContent(String vfsPath, DeploymentPhase phase)
@@ -406,69 +422,73 @@
       boolean trace = log.isTraceEnabled();
       if( trace )
          log.trace("Checking applications for modifications");
+      if( trace )
+         log.trace("Aquiring content read lock");
       contentLock.readLock().lock();
-      if( trace )
-         log.trace("Aquired content read lock");
-
-      if( apps != null )
+      try
       {
-         Iterator<VFSDeployment> iter = apps.iterator();
-         while( iter.hasNext() )
+         if( apps != null )
          {
-            VFSDeployment ctx = iter.next();
-            VirtualFile root = ctx.getRoot();
-            // See if this file is locked
-            if(this.lockedApps.contains(root.getPathName()))
+            Iterator<VFSDeployment> iter = apps.iterator();
+            while( iter.hasNext() )
             {
-               if(trace)
-                  log.trace("Ignoring locked application: "+root);
-               continue;
+               VFSDeployment ctx = iter.next();
+               VirtualFile root = ctx.getRoot();
+               // See if this file is locked
+               if(this.lockedApps.contains(root.getPathName()))
+               {
+                  if(trace)
+                     log.trace("Ignoring locked application: "+root);
+                  continue;
+               }
+               Long rootLastModified = root.getLastModified();
+               String name = root.getPathName();
+               // Check for removal
+               if( root.exists() == false )
+               {
+                  ModificationInfo info = new ModificationInfo(ctx, rootLastModified, ModifyStatus.REMOVED);
+                  modified.add(info);
+                  iter.remove();
+                  if( trace )
+                     log.trace(name+" was removed");
+               }
+               // Check for modification
+               else if( root.hasBeenModified() )
+               {
+                  if( trace )
+                     log.trace(name+" was modified: "+rootLastModified);
+                  // Need to create a duplicate ctx
+                  VFSDeployment ctx2 = loadDeploymentData(root);
+                  ModificationInfo info = new ModificationInfo(ctx2, rootLastModified, ModifyStatus.MODIFIED);
+                  modified.add(info);
+               }
+               // TODO: this could check metadata files modifications as well
             }
-            Long rootLastModified = root.getLastModified();
-            String name = root.getPathName();
-            // Check for removal
-            if( root.exists() == false )
+            // Now check for additions
+            for (File applicationDir : applicationDirs)
             {
-               ModificationInfo info = new ModificationInfo(ctx, rootLastModified, ModifyStatus.REMOVED);
-               modified.add(info);
-               iter.remove();
-               if( trace )
-                  log.trace(name+" was removed");
-            }
-            // Check for modification
-            else if( root.hasBeenModified() )
-            {
-               if( trace )
-                  log.trace(name+" was modified: "+rootLastModified);
-               // Need to create a duplicate ctx
-               VFSDeployment ctx2 = loadDeploymentData(root);               
-               ModificationInfo info = new ModificationInfo(ctx2, rootLastModified, ModifyStatus.MODIFIED);
-               modified.add(info);
-            }
-            // TODO: this could check metadata files modifications as well
-         }
-         // Now check for additions
-         for (File applicationDir : applicationDirs)
-         {
-            VFS deployVFS = VFS.getVFS(applicationDir.toURI());
-            VirtualFile deployDir = deployVFS.getRoot();
-            List<VirtualFile> children = deployDir.getChildren();
-            for(VirtualFile vf : children)
-            {
-               URI uri = vf.toURI();
-               if( applicationCtxs.containsKey(uri.toString()) == false )
+               VirtualFile deployDir = VFS.getRoot(applicationDir.toURI());
+               List<VirtualFile> children = deployDir.getChildren();
+               for(VirtualFile vf : children)
                {
-                  VFSDeployment ctx = loadDeploymentData(vf);
-                  ModificationInfo info = new ModificationInfo(ctx, vf.getLastModified(), ModifyStatus.ADDED);
-                  modified.add(info);
-                  applicationCtxs.put(vf.toURI().toString(), ctx);
+                  URI uri = vf.toURI();
+                  if( applicationCtxs.containsKey(uri.toString()) == false )
+                  {
+                     VFSDeployment ctx = loadDeploymentData(vf);
+                     ModificationInfo info = new ModificationInfo(ctx, vf.getLastModified(), ModifyStatus.ADDED);
+                     modified.add(info);
+                     applicationCtxs.put(vf.toURI().toString(), ctx);
+                  }
                }
             }
          }
       }
-      contentLock.readLock().unlock();
-      if( trace )
-         log.trace("Released content read lock");
+      finally
+      {
+         contentLock.readLock().unlock();
+         if( trace )
+            log.trace("Released content read lock");
+      }
 
       if(modified.size() > 0)
          lastModified = System.currentTimeMillis();

Modified: trunk/testsuite/src/main/org/jboss/test/profileservice/test/DeployUnitTestCase.java
===================================================================
--- trunk/testsuite/src/main/org/jboss/test/profileservice/test/DeployUnitTestCase.java	2008-06-18 11:33:34 UTC (rev 74790)
+++ trunk/testsuite/src/main/org/jboss/test/profileservice/test/DeployUnitTestCase.java	2008-06-18 11:54:58 UTC (rev 74791)
@@ -42,8 +42,7 @@
  * @author Scott.Stark at jboss.org
  * @version $Revision:$
  */
-public class DeployUnitTestCase extends AbstractProfileServiceTest
-   implements ProgressListener
+public class DeployUnitTestCase extends AbstractProfileServiceTest implements ProgressListener
 {
    private ProgressEvent eventInfo;
    private long eventCount = 0;
@@ -66,306 +65,146 @@
       return "profileservice";
    }
 
-   public void testWarDeployment()
-      throws Exception
+   protected void testDeployment(String name, String type, ManagedDeploymentTester tester) throws Exception
    {
       DeploymentManager deployMgr = getDeploymentManager();
-      URL contentURL = super.getDeployURL("testWarDeployment.war");
+      String[] names = {name};
+      URL contentURL = getDeployURL(name);
       assertNotNull(contentURL);
-      DeploymentProgress progress = deployMgr.distribute("testWarDeployment.war", DeploymentPhase.APPLICATION, contentURL);
-      progress.addProgressListener(this);
-      progress.run();
-      DeploymentStatus status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      // It should not be running yet
-      assertFalse("DeploymentStatus.isRunning", status.isRunning());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
+      log.debug(contentURL);
+      // TODO - hack to get off JDK's url handling
+      String urlString = contentURL.toExternalForm();
+      int p = urlString.indexOf(":/");
+      contentURL = new URL("vfszip" + urlString.substring(p));
+      log.debug(contentURL);
 
-      // Now start the deployment
-      String[] names = {"testWarDeployment.war"};
-      progress = deployMgr.start(DeploymentPhase.APPLICATION, names);
+      DeploymentStatus status;
+      DeploymentProgress progress = deployMgr.distribute(name, DeploymentPhase.APPLICATION, contentURL);
       progress.addProgressListener(this);
       progress.run();
-      status = progress.getDeploymentStatus();
-      log.info(status);
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertTrue("DeploymentStatus.isRunning", status.isRunning());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-      // Check for a ManagedDeployment with a war deployment type
-      ManagementView mgtView = super.getManagementView();
-      ManagedDeployment war = mgtView.getDeployment("testWarDeployment.war", DeploymentPhase.APPLICATION);
-      assertNotNull(war);
-      log.info("Found war deployment: "+war);
-      assertTrue(war.getTypes().contains("war"));
-      // Validate the servlet, TODO...
+      try
+      {
+         status = progress.getDeploymentStatus();
+         assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
+         // It should not be running yet
+         assertFalse("DeploymentStatus.isRunning", status.isRunning());
+         assertFalse("DeploymentStatus.isFailed", status.isFailed());
 
-      // Stop/remove the deployment
-      progress = deployMgr.stop(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-      
-      progress = deployMgr.undeploy(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
+         // Now start the deployment
+         progress = deployMgr.start(DeploymentPhase.APPLICATION, names);
+         progress.addProgressListener(this);
+         progress.run();
+         try
+         {
+            status = progress.getDeploymentStatus();
+            assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
+            assertTrue("DeploymentStatus.isRunning", status.isRunning());
+            assertFalse("DeploymentStatus.isFailed", status.isFailed());
+            // Check for a
+            ManagementView mgtView = getManagementView();
+            ManagedDeployment deployment = mgtView.getDeployment(name, DeploymentPhase.APPLICATION);
+            assertNotNull(deployment);
+            log.info("Found " + type + " deployment: " + deployment);
+            assertTrue(deployment.getTypes().contains(type));
+            if (tester != null)
+            {
+               tester.testManagedDeployment();
+            }
+         }
+         finally
+         {
+            // Stop/remove the deployment
+            progress = deployMgr.stop(DeploymentPhase.APPLICATION, names);
+            progress.addProgressListener(this);
+            progress.run();
+            status = progress.getDeploymentStatus();
+            assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
+            assertFalse("DeploymentStatus.isFailed", status.isFailed());
+         }
+      }
+      finally
+      {
+         progress = deployMgr.undeploy(DeploymentPhase.APPLICATION, names);
+         progress.addProgressListener(this);
+         progress.run();
+         status = progress.getDeploymentStatus();
+         assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
+         assertFalse("DeploymentStatus.isFailed", status.isFailed());
+      }
    }
-   public void testEjb3xDeployment()
-      throws Exception
-   {
-      DeploymentManager deployMgr = getDeploymentManager();
-      URL contentURL = super.getDeployURL("testEjb3xDeployment.jar");
-      assertNotNull(contentURL);
-      DeploymentProgress progress = deployMgr.distribute("testEjb3xDeployment.jar", DeploymentPhase.APPLICATION, contentURL);
-      progress.addProgressListener(this);
-      progress.run();
-      DeploymentStatus status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      // It should not be running yet
-      assertFalse("DeploymentStatus.isRunning", status.isRunning());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
 
-      // Now start the deployment
-      String[] names = {"testEjb3xDeployment.jar"};
-      progress = deployMgr.start(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertTrue("DeploymentStatus.isRunning", status.isRunning());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-      // Check for a 
-      ManagementView mgtView = super.getManagementView();
-      ManagedDeployment ejb3x = mgtView.getDeployment("testEjb3xDeployment.jar", DeploymentPhase.APPLICATION);
-      assertNotNull(ejb3x);
-      log.info("Found ejb deployment: "+ejb3x);
-      assertTrue(ejb3x.getTypes().contains("ejb3x"));
-      // Validate the ejb
-      InitialContext ic = new InitialContext();
-      BeanRemote3x bean = (BeanRemote3x) ic.lookup("BeanImpl3x/remote");
-      String entry1 = (String) bean.getEnvEntry("entry1");
-      assertEquals("entry1Value", entry1);
-
-      // Stop/remove the deployment
-      progress = deployMgr.stop(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-      
-      progress = deployMgr.undeploy(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-   }
-   public void testEjb2xDeployment()
-      throws Exception
+   public void testWarDeployment() throws Exception
    {
-      DeploymentManager deployMgr = getDeploymentManager();
-      URL contentURL = super.getDeployURL("testEjb2xDeployment.jar");
-      assertNotNull(contentURL);  
-      DeploymentProgress progress = deployMgr.distribute("testEjb2xDeployment.jar", DeploymentPhase.APPLICATION, contentURL);
-      progress.addProgressListener(this);
-      progress.run();
-      DeploymentStatus status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      // It should not be running yet
-      assertFalse("DeploymentStatus.isRunning", status.isRunning());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-
-      // Now start the deployment
-      String[] names = {"testEjb2xDeployment.jar"};
-      progress = deployMgr.start(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertTrue("DeploymentStatus.isRunning", status.isRunning());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-      // Check for a 
-      ManagementView mgtView = super.getManagementView();
-      ManagedDeployment ejb2x = mgtView.getDeployment("testEjb2xDeployment.jar", DeploymentPhase.APPLICATION);
-      assertNotNull(ejb2x);
-      log.info("Found ejb deployment: "+ejb2x);
-      assertTrue(ejb2x.getTypes().contains("ejb2x"));
-      // Validate the ejb
-      InitialContext ic = new InitialContext();
-      BeanHome home = (BeanHome) ic.lookup("DeployUnitTestCase-testEjb2xDeployment");
-      BeanRemote bean = home.create();
-      String entry1 = (String) bean.getEnvEntry("entry1");
-      assertEquals("entry1Value", entry1);
-
-      // Stop/remove the deployment
-      progress = deployMgr.stop(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-      
-      progress = deployMgr.undeploy(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
+      String name = "testWarDeployment.war";
+      testDeployment(name, "war", null);
    }
 
-   public void testEarDeployment()
-      throws Exception
+   public void testEjb3xDeployment() throws Exception
    {
-      URL contentURL = super.getDeployURL("testEarDeployment.ear");
+      String name = "testEjb3xDeployment.jar";
+      ManagedDeploymentTester tester = new ManagedDeploymentTester()
+      {
+         public void testManagedDeployment() throws Exception
+         {
+            InitialContext ic = new InitialContext();
+            BeanRemote3x bean = (BeanRemote3x) ic.lookup("BeanImpl3x/remote");
+            String entry1 = (String) bean.getEnvEntry("entry1");
+            assertEquals("entry1Value", entry1);
+         }
+      };
+      testDeployment(name, "ejb3x", tester);
+   }
 
-      // Distribute the content
-      DeploymentManager deployMgr = getDeploymentManager();
-      DeploymentProgress progress = deployMgr.distribute("testEarDeployment.ear", DeploymentPhase.APPLICATION, contentURL);
-      progress.addProgressListener(this);
-      progress.run();
-      DeploymentStatus status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      // It should not be running yet
-      assertFalse("DeploymentStatus.isRunning", status.isRunning());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-
-      // Now start the deployment
-      String[] names = {"testEarDeployment.ear"};
-      progress = deployMgr.start(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      log.info(status);
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertTrue("DeploymentStatus.isRunning", status.isRunning());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-      // Check for a ManagedDeployment
-      ManagementView mgtView = super.getManagementView();
-      ManagedDeployment ear = mgtView.getDeployment("testEarDeployment.ear", DeploymentPhase.APPLICATION);
-      assertNotNull(ear);
-      assertTrue(ear.getTypes().contains("ear"));
-
-      // Validate the ejb
-      InitialContext ic = new InitialContext();
-      BeanHome home = (BeanHome) ic.lookup("DeployUnitTestCase-testEjb2xDeployment");
-      BeanRemote bean = home.create();
-      String entry1 = (String) bean.getEnvEntry("entry1");
-      assertEquals("entry1Value", entry1);
-      // TODO, validate the war
-
-      // Stop/remove the deployment
-      progress = deployMgr.stop(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-      
-      progress = deployMgr.undeploy(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());      
+   public void testEjb2xDeployment() throws Exception
+   {
+      String name = "testEjb2xDeployment.jar";
+      ManagedDeploymentTester tester = new ManagedDeploymentTester()
+      {
+         public void testManagedDeployment() throws Exception
+         {
+            InitialContext ic = new InitialContext();
+            BeanHome home = (BeanHome) ic.lookup("DeployUnitTestCase-testEjb2xDeployment");
+            BeanRemote bean = home.create();
+            String entry1 = (String) bean.getEnvEntry("entry1");
+            assertEquals("entry1Value", entry1);
+         }
+      };
+      testDeployment(name, "ejb2x", tester);
    }
 
-   public void testMCBeansDeployment()
-      throws Exception
+   public void testEarDeployment() throws Exception
    {
-      URL contentURL = super.getDeployURL("testMCBeansDeployment.beans");
+      String name = "testEarDeployment.ear";
+      ManagedDeploymentTester tester = new ManagedDeploymentTester()
+      {
+         public void testManagedDeployment() throws Exception
+         {
+            // Validate the ejb
+            InitialContext ic = new InitialContext();
+            BeanHome home = (BeanHome) ic.lookup("DeployUnitTestCase-testEjb2xDeployment");
+            BeanRemote bean = home.create();
+            String entry1 = (String) bean.getEnvEntry("entry1");
+            assertEquals("entry1Value", entry1);
+            // TODO, validate the war
+         }
+      };
+      testDeployment(name, "ear", tester);
+   }
 
-      // Distribute the content
-      DeploymentManager deployMgr = getDeploymentManager();
-      DeploymentProgress progress = deployMgr.distribute("testMCBeansDeployment.beans", DeploymentPhase.APPLICATION, contentURL);
-      progress.addProgressListener(this);
-      progress.run();
-      DeploymentStatus status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      // It should not be running yet
-      assertFalse("DeploymentStatus.isRunning", status.isRunning());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-
-      // Now start the deployment
-      String[] names = {"testMCBeansDeployment.beans"};
-      progress = deployMgr.start(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      log.info(status);
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertTrue("DeploymentStatus.isRunning", status.isRunning());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-      // Check for a ManagedDeployment
-      ManagementView mgtView = super.getManagementView();
-      ManagedDeployment beans = mgtView.getDeployment("testMCBeansDeployment.beans", DeploymentPhase.APPLICATION);
-      assertNotNull(beans);
-      assertTrue(beans.getTypes().contains("beans"));
-
-      // Stop/remove the deployment
-      progress = deployMgr.stop(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-      
-      progress = deployMgr.undeploy(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());      
+   public void testMCBeansDeployment() throws Exception
+   {
+      String name = "testMCBeansDeployment.beans";
+      testDeployment(name, "beans", null);
    }
-   public void testSarDeployment()
-      throws Exception
+
+   public void testSarDeployment() throws Exception
    {
-      URL contentURL = super.getDeployURL("testSarDeployment.sar");
+      String name = "testSarDeployment.sar";
+      testDeployment(name, "sar", null);
+   }
 
-      // Distribute the content
-      DeploymentManager deployMgr = getDeploymentManager();
-      DeploymentProgress progress = deployMgr.distribute("testSarDeployment.sar", DeploymentPhase.APPLICATION, contentURL);
-      progress.addProgressListener(this);
-      progress.run();
-      DeploymentStatus status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      // It should not be running yet
-      assertFalse("DeploymentStatus.isRunning", status.isRunning());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-
-      // Now start the deployment
-      String[] names = {"testSarDeployment.sar"};
-      progress = deployMgr.start(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      log.info(status);
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertTrue("DeploymentStatus.isRunning", status.isRunning());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-      // Check for a ManagedDeployment
-      ManagementView mgtView = super.getManagementView();
-      ManagedDeployment sar = mgtView.getDeployment("testSarDeployment.sar", DeploymentPhase.APPLICATION);
-      assertNotNull(sar);
-      assertTrue(sar.getTypes().contains("sar"));
-
-      // Stop/remove the deployment
-      progress = deployMgr.stop(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());
-      
-      progress = deployMgr.undeploy(DeploymentPhase.APPLICATION, names);
-      progress.addProgressListener(this);
-      progress.run();
-      status = progress.getDeploymentStatus();
-      assertTrue("DeploymentStatus.isCompleted", status.isCompleted());
-      assertFalse("DeploymentStatus.isFailed", status.isFailed());      
+   private interface ManagedDeploymentTester
+   {
+      void testManagedDeployment() throws Exception;
    }
 }




More information about the jboss-cvs-commits mailing list