[jboss-cvs] JBossAS SVN: r67299 - in projects/microcontainer/trunk: deployers-impl/src/main/org/jboss/deployers/plugins/deployers and 5 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Nov 20 09:51:06 EST 2007


Author: alesj
Date: 2007-11-20 09:51:06 -0500 (Tue, 20 Nov 2007)
New Revision: 67299

Added:
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/DependencyDeployer.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestAttachment.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestSimpleDeployer.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/AbstractMainDeployerTest.java
Modified:
   projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/loader/reflection/ClassMetaDataRetrievalFactory.java
   projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java
   projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerCheckCompleteTestCase.java
   projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerSingleDeploymentTestCase.java
   projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java
   projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java
Log:
SingleDeployment API and checkComplete tests.

Modified: projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/loader/reflection/ClassMetaDataRetrievalFactory.java
===================================================================
--- projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/loader/reflection/ClassMetaDataRetrievalFactory.java	2007-11-20 14:36:19 UTC (rev 67298)
+++ projects/microcontainer/trunk/container/src/main/org/jboss/metadata/plugins/loader/reflection/ClassMetaDataRetrievalFactory.java	2007-11-20 14:51:06 UTC (rev 67299)
@@ -50,7 +50,6 @@
          return null;
       
       Class<?> clazz = Class.class.cast(qualifier);
-      AnnotatedElementMetaDataLoader result = new AnnotatedElementMetaDataLoader(clazz);
-      return result;
+      return new AnnotatedElementMetaDataLoader(clazz);
    }
 }

Modified: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java	2007-11-20 14:36:19 UTC (rev 67298)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/deployers/DeployersImpl.java	2007-11-20 14:51:06 UTC (rev 67299)
@@ -669,7 +669,7 @@
          if (problem != null)
             deploymentsInError.put(context.getName(), problem);
 
-         if (context.isDeployed() == false)
+         if (isDeployed(context) == false)
             deploymentsMissingDeployer.add(context.getName());
 
          if (checkContexts)
@@ -696,6 +696,17 @@
    }
 
    /**
+    * Is context deployed.
+    *
+    * @param context the deployment context
+    * @return true if context deployed, false otherwise
+    */
+   protected boolean isDeployed(DeploymentContext context)
+   {
+      return context.isDeployed() || DeploymentState.DEPLOYED.equals(context.getState());
+   }
+
+   /**
     * Check complete on deployment context.
     *
     * @param context the deployment context

Modified: projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java	2007-11-20 14:36:19 UTC (rev 67298)
+++ projects/microcontainer/trunk/deployers-impl/src/main/org/jboss/deployers/plugins/main/MainDeployerImpl.java	2007-11-20 14:51:06 UTC (rev 67299)
@@ -26,6 +26,7 @@
 import java.util.Collections;
 import java.util.List;
 import java.util.Map;
+import java.util.Arrays;
 import java.util.concurrent.ConcurrentHashMap;
 import java.util.concurrent.CopyOnWriteArrayList;
 import java.util.concurrent.atomic.AtomicBoolean;
@@ -274,8 +275,8 @@
 
          DeploymentContext context = null;
          try
-      {
-         context = determineStructure(deployment);
+         {
+            context = determineStructure(deployment);
             if (DeploymentState.ERROR.equals(context.getState()))
                errorDeployments.put(name, context);
 
@@ -386,9 +387,9 @@
             }
             catch(Throwable t)
             {
-               Deployment[] deployedDeployments = new Deployment[i];
-               System.arraycopy(deployments, 0, deployedDeployments, 0, i);
-               undeploy(deployedDeployments);
+               DeploymentContext[] deployedContexts = new DeploymentContext[i];
+               System.arraycopy(contexts, 0, deployedContexts, 0, i);
+               deployers.process(null, Arrays.asList(deployedContexts));
                throw DeploymentException.rethrowAsDeploymentException("Unable to deploy deployments.", t);
             }
          }
@@ -398,11 +399,7 @@
          }
          catch (DeploymentException e)
          {
-            Deployment[] deployedDeployments = new Deployment[contexts.length];
-            for(int i = 0; i < contexts.length; i++)
-               deployedDeployments[i] = contexts[i].getDeployment();
-
-            undeploy(deployedDeployments);
+            deployers.process(null, Arrays.asList(contexts));
             throw e;
          }
       }

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/DependencyDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/DependencyDeployer.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/DependencyDeployer.java	2007-11-20 14:51:06 UTC (rev 67299)
@@ -0,0 +1,110 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.main.support;
+
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContextActions;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.plugins.AbstractControllerContext;
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class DependencyDeployer extends AbstractRealDeployer
+{
+   private Controller controller;
+   private ControllerContextActions actions = new TestControllerContextActions();
+
+   public DependencyDeployer(Controller controller)
+   {
+      this.controller = controller;
+      setUseUnitName(true);
+   }
+
+   protected boolean isControllerContextNameCandidate(DeploymentUnit unit)
+   {
+      return true;
+   }
+
+   protected void addControllerContextName(DeploymentUnit unit)
+   {
+      unit.addControllerContextName("x" + unit.getName());
+   }
+
+   protected void removeControllerContextName(DeploymentUnit unit)
+   {
+      unit.removeControllerContextName("x" + unit.getName());
+   }
+
+   protected void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      TestAttachment attachment = unit.getAttachment(TestAttachment.class);
+      if (attachment != null)
+      {
+         Object name = attachment.getName();
+         AbstractControllerContext context = new AbstractControllerContext(name, actions);
+         DependencyInfo dependencyInfo = context.getDependencyInfo();
+         Object dependency = attachment.getDependency();
+         if (dependency != null)
+         {
+            AbstractDependencyItem item = new AbstractDependencyItem(name, dependency, ControllerState.INSTALLED, null);
+            dependencyInfo.addIDependOn(item);
+         }
+         try
+         {
+            controller.install(context);
+         }
+         catch (Throwable t)
+         {
+            throw DeploymentException.rethrowAsDeploymentException("Unexpected.", t);
+         }
+      }
+   }
+
+   protected void internalUndeploy(DeploymentUnit unit)
+   {
+      TestAttachment attachment = unit.getAttachment(TestAttachment.class);
+      if (attachment != null)
+      {
+         controller.uninstall(attachment.getName());
+      }
+   }
+
+   private class TestControllerContextActions implements ControllerContextActions
+   {
+      public void install(ControllerContext context, ControllerState fromState, ControllerState toState) throws Throwable
+      {
+         context.setState(toState);
+      }
+
+      public void uninstall(ControllerContext context, ControllerState fromState, ControllerState toState)
+      {
+         context.setState(toState);
+      }
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestAttachment.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestAttachment.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestAttachment.java	2007-11-20 14:51:06 UTC (rev 67299)
@@ -0,0 +1,51 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.main.support;
+
+import java.io.Serializable;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TestAttachment implements Serializable
+{
+   private static final long serialVersionUID = -1034970512310610762L;
+
+   private Object name;
+   private Object dependency;
+
+   public TestAttachment(Object name, Object dependency)
+   {
+      this.name = name;
+      this.dependency = dependency;
+   }
+
+   public Object getName()
+   {
+      return name;
+   }
+
+   public Object getDependency()
+   {
+      return dependency;
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestSimpleDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestSimpleDeployer.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/support/TestSimpleDeployer.java	2007-11-20 14:51:06 UTC (rev 67299)
@@ -0,0 +1,116 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.main.support;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.deployer.DeploymentStage;
+import org.jboss.deployers.spi.deployer.helpers.AbstractRealDeployer;
+import org.jboss.deployers.structure.spi.DeploymentUnit;
+
+/**
+ * TestSimpleDeployer.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @author <a href="ales.justin at jboss.com">Ales Justin</a>
+ */
+public class TestSimpleDeployer extends AbstractRealDeployer
+{
+   private List<String> deployed = new ArrayList<String>();
+   private List<String> undeployed = new ArrayList<String>();
+   private List<String> failed = new ArrayList<String>();
+
+   private String name;
+
+   public TestSimpleDeployer()
+   {
+      this(Integer.MAX_VALUE);
+      name = super.toString();
+   }
+
+   public TestSimpleDeployer(String name)
+   {
+      this(Integer.MAX_VALUE);
+      this.name = name;
+   }
+
+   public TestSimpleDeployer(int relativeOrder)
+   {
+      setRelativeOrder(relativeOrder);
+      this.setType("test");
+      name = "TestSimpleDeployer" + relativeOrder;
+   }
+
+   public TestSimpleDeployer(DeploymentStage stage)
+   {
+      setStage(stage);
+      this.setType("test");
+      name = super.toString();
+   }
+
+   public String toString()
+   {
+      return name;
+   }
+
+   public void clear()
+   {
+      deployed.clear();
+      undeployed.clear();
+      failed.clear();
+   }
+
+   public List<String> getDeployedUnits()
+   {
+      return deployed;
+   }
+
+   public List<String> getUndeployedUnits()
+   {
+      return undeployed;
+   }
+
+   public List<String> getFailed()
+   {
+      return failed;
+   }
+
+   public void internalDeploy(DeploymentUnit unit) throws DeploymentException
+   {
+      log.debug(this + " deploy  : " + unit.getName());
+      unit.getTypes().add(getType());
+      deployed.add(unit.getName());
+      if (this.equals(unit.getAttachment("fail")))
+      {
+         failed.add(unit.getName());
+         throw new DeploymentException("Asked to fail");
+      }
+   }
+
+   public void internalUndeploy(DeploymentUnit unit)
+   {
+      log.debug(this + " undeploy: " + unit.getName());
+      undeployed.add(unit.getName());
+   }
+}

Added: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/AbstractMainDeployerTest.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/AbstractMainDeployerTest.java	                        (rev 0)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/AbstractMainDeployerTest.java	2007-11-20 14:51:06 UTC (rev 67299)
@@ -0,0 +1,55 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2006, JBoss Inc., and individual contributors as indicated
+* by the @authors tag. See the copyright.txt 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.deployers.main.test;
+
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.spi.attachments.PredeterminedManagedObjectAttachments;
+import org.jboss.deployers.spi.deployer.Deployer;
+import org.jboss.test.deployers.AbstractDeployerTest;
+import org.jboss.test.deployers.main.support.TestSimpleDeployer;
+
+/**
+ * Abstract main deployer test.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public abstract class AbstractMainDeployerTest extends AbstractDeployerTest
+{
+   protected TestSimpleDeployer deployer = new TestSimpleDeployer(1);
+
+   protected AbstractMainDeployerTest(String name)
+   {
+      super(name);
+   }
+
+   protected DeployerClient getMainDeployer()
+   {
+      return createMainDeployer(deployer);
+   }
+
+   protected static void makeFail(PredeterminedManagedObjectAttachments attachments, Deployer deployer)
+   {
+      MutableAttachments mutable = (MutableAttachments) attachments.getPredeterminedManagedObjects();
+      mutable.addAttachment("fail", deployer);
+   }
+}

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerCheckCompleteTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerCheckCompleteTestCase.java	2007-11-20 14:36:19 UTC (rev 67298)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerCheckCompleteTestCase.java	2007-11-20 14:51:06 UTC (rev 67299)
@@ -21,15 +21,26 @@
 */
 package org.jboss.test.deployers.main.test;
 
-import org.jboss.test.deployers.AbstractDeployerTest;
 import junit.framework.Test;
+import org.jboss.dependency.plugins.AbstractController;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.IncompleteDeploymentException;
+import org.jboss.deployers.plugins.deployers.DeployersImpl;
+import org.jboss.deployers.plugins.main.MainDeployerImpl;
+import org.jboss.deployers.spi.DeploymentException;
+import org.jboss.deployers.spi.attachments.MutableAttachments;
+import org.jboss.deployers.structure.spi.DeploymentContext;
+import org.jboss.deployers.structure.spi.StructuralDeployers;
+import org.jboss.test.deployers.main.support.DependencyDeployer;
+import org.jboss.test.deployers.main.support.TestAttachment;
 
 /**
  * Check complete deployment test case.
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public class DeployerCheckCompleteTestCase extends AbstractDeployerTest
+public class DeployerCheckCompleteTestCase extends AbstractMainDeployerTest
 {
    public DeployerCheckCompleteTestCase(String name)
    {
@@ -41,8 +52,144 @@
       return suite(DeployerCheckCompleteTestCase.class);
    }
 
-   public void testCheckComplete() throws Exception
+   public void testAllFailure() throws Exception
    {
-      // todo
+      DeployerClient main = getMainDeployer();
+      Deployment deployment = createSimpleDeployment("failure");
+      makeFail(deployment, deployer);
+      main.addDeployment(deployment);
+      main.process();
+      try
+      {
+         main.checkComplete(deployment);
+         fail("Should not be here.");
+      }
+      catch (DeploymentException e)
+      {
+         assertInstanceOf(e, IncompleteDeploymentException.class);
+      }
    }
+
+   public void testAllSuccess() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+      Deployment deployment = createSimpleDeployment("failure");
+      main.addDeployment(deployment);
+      main.process();
+      main.checkComplete(deployment);
+   }
+
+   public void testStructureFailure() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+      MainDeployerImpl mainImpl = (MainDeployerImpl)main;
+      StructuralDeployers sd = new StructuralDeployers()
+      {
+         public DeploymentContext determineStructure(Deployment deployment) throws DeploymentException
+         {
+            throw new DeploymentException("No such structure deployers.");
+         }
+      };
+      mainImpl.setStructuralDeployers(sd);
+      Deployment deployment = createSimpleDeployment("failure");
+      makeFail(deployment, deployer);
+      try
+      {
+         main.addDeployment(deployment);
+      }
+      catch (DeploymentException ignored)
+      {
+      }
+      main.process();
+      try
+      {
+         main.checkComplete();
+         fail("Should not be here.");
+      }
+      catch (DeploymentException e)
+      {
+         assertInstanceOf(e, IncompleteDeploymentException.class);
+      }
+   }
+
+   public void testStructureSuccess() throws Exception
+   {
+      DeployerClient main = getMainDeployer();
+      Deployment deployment = createSimpleDeployment("failure");
+      main.addDeployment(deployment);
+      main.process();
+      main.checkStructureComplete(deployment);
+   }
+
+   public void testHalfThenAll() throws Exception
+   {
+      DeployerClient main = getDependencyMainDeployer();
+
+      Deployment dA = createSimpleDeployment("A");
+      addAttachment(dA, "xB");
+
+      main.addDeployment(dA);
+      main.process();
+      try
+      {
+         main.checkComplete(dA);
+         fail("Should not be here.");
+      }
+      catch (DeploymentException e)
+      {
+         assertInstanceOf(e, IncompleteDeploymentException.class);
+      }
+
+      Deployment dB = createSimpleDeployment("B");
+      addAttachment(dB, null);
+      main.deploy(dB);
+
+      main.checkComplete(dA);
+   }
+
+   public void testAllThenHalf() throws Exception
+   {
+      DeployerClient main = getDependencyMainDeployer();
+
+      Deployment dA = createSimpleDeployment("A");
+      addAttachment(dA, "xB");
+
+      main.addDeployment(dA);
+      main.process();
+
+      Deployment dB = createSimpleDeployment("B");
+      addAttachment(dB, null);
+      main.deploy(dB);
+
+      main.checkComplete(dA);
+
+      main.undeploy(dB);
+
+      try
+      {
+         main.checkComplete(dA);
+         fail("Should not be here.");
+      }
+      catch (DeploymentException e)
+      {
+         assertInstanceOf(e, IncompleteDeploymentException.class);
+      }
+   }
+
+   protected DeployerClient getDependencyMainDeployer()
+   {
+      MainDeployerImpl main = new MainDeployerImpl();
+      main.setStructuralDeployers(createStructuralDeployers());
+      AbstractController controller = new AbstractController();
+      DeployersImpl deployers = new DeployersImpl(controller);
+      deployers.addDeployer(new DependencyDeployer(controller));
+      main.setDeployers(deployers);
+      return main;
+   }
+
+   protected void addAttachment(Deployment deployment, Object dependency)
+   {
+      MutableAttachments mutableAttachments = (MutableAttachments)deployment.getPredeterminedManagedObjects();
+      mutableAttachments.addAttachment(TestAttachment.class, new TestAttachment("x" + deployment.getName(), dependency));
+   }
 }

Modified: projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerSingleDeploymentTestCase.java
===================================================================
--- projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerSingleDeploymentTestCase.java	2007-11-20 14:36:19 UTC (rev 67298)
+++ projects/microcontainer/trunk/deployers-impl/src/tests/org/jboss/test/deployers/main/test/DeployerSingleDeploymentTestCase.java	2007-11-20 14:51:06 UTC (rev 67299)
@@ -21,15 +21,22 @@
 */
 package org.jboss.test.deployers.main.test;
 
-import org.jboss.test.deployers.AbstractDeployerTest;
+import java.util.ArrayList;
+import java.util.Collections;
+import java.util.List;
+
 import junit.framework.Test;
+import org.jboss.deployers.client.spi.DeployerClient;
+import org.jboss.deployers.client.spi.Deployment;
+import org.jboss.deployers.client.spi.main.MainDeployer;
+import org.jboss.deployers.spi.DeploymentException;
 
 /**
  * Single deployment API test case.
  *
  * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
  */
-public class DeployerSingleDeploymentTestCase extends AbstractDeployerTest
+public class DeployerSingleDeploymentTestCase extends AbstractMainDeployerTest
 {
    public DeployerSingleDeploymentTestCase(String name)
    {
@@ -41,12 +48,160 @@
       return suite(DeployerSingleDeploymentTestCase.class);
    }
 
-   public void testSingleDeployment() throws Exception
+   protected void checkFailedDeploy(DeployerClient mainDeployer, int failed, int size) throws Throwable
    {
+      Deployment[] deployments = new Deployment[size];
+      for(int i = 0; i < size; i++)
+      {
+         deployments[i] = createSimpleDeployment("deployment" + i);
+         if (i == failed)
+            makeFail(deployments[i], deployer);
+      }
+      try
+      {
+         mainDeployer.deploy(deployments);
+         fail("Should not be here.");
+      }
+      catch (DeploymentException e)
+      {
+         assertEquals(size, deployer.getUndeployedUnits().size() + deployer.getFailed().size());
+         assertEquals(Collections.singletonList("deployment" + failed), deployer.getFailed());
+      }
+      deployer.clear();
+   }
+
+   public void testFailedDeploy() throws Throwable
+   {
+      DeployerClient main = getMainDeployer();
+      checkFailedDeploy(main, 0, 3);
+      checkFailedDeploy(main, 1, 3);
+      checkFailedDeploy(main, 2, 3);
+   }
+
+   public void testRedeploy() throws Throwable
+   {
+      DeployerClient main = getMainDeployer();
+
+      Deployment context = createSimpleDeployment("redeploy");
+      main.deploy(context);
+      List<String> expected = new ArrayList<String>();
+      expected.add(context.getName());
+      assertEquals(expected, deployer.getDeployedUnits());
+
+      main.undeploy(context);
+      assertEquals(expected, deployer.getUndeployedUnits());
+
+      deployer.clear();
+      main.deploy(context);
+      expected.clear();
+      expected.add(context.getName());
+      assertEquals(expected, deployer.getDeployedUnits());
+   }
+
+   public void testDeployRemoveProcess() throws Throwable
+   {
+      DeployerClient main = getMainDeployer();
+
+      Deployment context = createSimpleDeployment("drp");
+      main.deploy(context);
+      List<String> expected = new ArrayList<String>();
+      expected.add(context.getName());
+      assertEquals(expected, deployer.getDeployedUnits());
+
+      main.removeDeployment(context);
+      main.process();
+      assertEquals(expected, deployer.getUndeployedUnits());
+   }
+
+   public void testAddProcessUndeploy() throws Throwable
+   {
+      DeployerClient main = getMainDeployer();
+
+      Deployment context = createSimpleDeployment("apu");
+      main.addDeployment(context);
+      main.process();
+      List<String> expected = new ArrayList<String>();
+      expected.add(context.getName());
+      assertEquals(expected, deployer.getDeployedUnits());
+
+      main.undeploy(context);
+      assertEquals(expected, deployer.getUndeployedUnits());
+   }
+
+   public void testDeployShutdown() throws Throwable
+   {
+      MainDeployer main = (MainDeployer)getMainDeployer();
+
+      Deployment context = createSimpleDeployment("shutdown");
+      main.deploy(context);
+      List<String> expected = new ArrayList<String>();
+      expected.add(context.getName());
+      assertEquals(expected, deployer.getDeployedUnits());
+
+      main.shutdown();
+      assertEquals(expected, deployer.getUndeployedUnits());
+   }
+
+   public void testSingleAndMultipleMix() throws Throwable
+   {
+      DeployerClient main = getMainDeployer();
+
+      Deployment single = createSimpleDeployment("single");
+      main.deploy(single);
+      List<String> expected = new ArrayList<String>();
+      expected.add(single.getName());
+      assertEquals(expected, deployer.getDeployedUnits());
+
+      Deployment normal = createSimpleDeployment("normal");
+      main.addDeployment(normal);
+      main.process();
+      expected.add(normal.getName());
+      assertEquals(expected, deployer.getDeployedUnits());
+
+      main.undeploy(single);
+      expected.clear();
+      expected.add(single.getName());
+      assertEquals(expected, deployer.getUndeployedUnits());
+
+      main.removeDeployment(normal.getName());
+      main.process();
+      expected.add(normal.getName());
+      assertEquals(expected, deployer.getUndeployedUnits());
+   }
+
+   public void testSingleAndMultipleMix2() throws Throwable
+   {
+      DeployerClient main = getMainDeployer();
+
+      Deployment single = createSimpleDeployment("single");
+      main.deploy(single);
+      List<String> expected = new ArrayList<String>();
+      expected.add(single.getName());
+      assertEquals(expected, deployer.getDeployedUnits());
+
+      Deployment normal = createSimpleDeployment("normal");
+      main.addDeployment(normal);
+      main.process();
+      expected.add(normal.getName());
+      assertEquals(expected, deployer.getDeployedUnits());
+
+      main.removeDeployment(normal.getName());
+      main.process();
+      expected.clear();
+      expected.add(normal.getName());
+      assertEquals(expected, deployer.getUndeployedUnits());
+
+      main.undeploy(single);
+      expected.add(single.getName());
+      assertEquals(expected, deployer.getUndeployedUnits());
+   }
+
+   public void testMultiThreads() throws Exception
+   {
       // todo
    }
 
-   public void testThreadUsage() throws Exception
+   public void testMultiThreadsAndShutdown() throws Exception
    {
       // todo
    }

Modified: projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java
===================================================================
--- projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java	2007-11-20 14:36:19 UTC (rev 67298)
+++ projects/microcontainer/trunk/deployers-spi/src/main/org/jboss/deployers/spi/deployer/helpers/AbstractRealDeployer.java	2007-11-20 14:51:06 UTC (rev 67299)
@@ -92,15 +92,18 @@
 
    public final void undeploy(DeploymentUnit unit)
    {
-      try
+      if (isControllerContextNameCandidate(unit))
       {
-         removeControllerContextName(unit);
+         try
+         {
+            removeControllerContextName(unit);
+         }
+         catch (Throwable t)
+         {
+            if (log.isTraceEnabled())
+               log.trace("Exception while removing unit name: " + t);
+         }
       }
-      catch (Throwable t)
-      {
-         if (log.isTraceEnabled())
-            log.trace("Exception while removing unit name: " + t);
-      }
 
       internalUndeploy(unit);
    }

Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java	2007-11-20 14:36:19 UTC (rev 67298)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/AbstractDeploymentContext.java	2007-11-20 14:51:06 UTC (rev 67299)
@@ -270,6 +270,7 @@
    /**
     * Initialise the metadata retrieval for a deployment context
     * 
+    * @param repository the meta data repository
     * @param deploymentContext the deployment context
     */
    private static void initMetaDataRetrieval(MutableMetaDataRepository repository, DeploymentContext deploymentContext)
@@ -285,7 +286,8 @@
 
    /**
     * Initialise the metadata retrieval for a deployment context
-    * 
+    *
+    * @param repository the meta data repository
     * @param deploymentContext the deployment context
     */
    private static void initMutableMetaDataRetrieval(MutableMetaDataRepository repository, DeploymentContext deploymentContext)
@@ -346,7 +348,7 @@
 
    public Set<Object> getControllerContextNames()
    {
-      return controllerContextNames != null ? Collections.unmodifiableSet(getControllerContextNames()) : null;
+      return controllerContextNames != null ? Collections.unmodifiableSet(controllerContextNames) : null;
    }
 
    public synchronized void addControllerContextName(Object name)

Modified: projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java
===================================================================
--- projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java	2007-11-20 14:36:19 UTC (rev 67298)
+++ projects/microcontainer/trunk/deployers-structure-spi/src/main/org/jboss/deployers/structure/spi/helpers/ComponentDeploymentContext.java	2007-11-20 14:51:06 UTC (rev 67299)
@@ -119,7 +119,7 @@
 
    public Set<Object> getControllerContextNames()
    {
-      return controllerContextNames != null ? Collections.unmodifiableSet(getControllerContextNames()) : null;
+      return controllerContextNames != null ? Collections.unmodifiableSet(controllerContextNames) : null;
    }
 
    public synchronized void addControllerContextName(Object name)




More information about the jboss-cvs-commits mailing list