[jboss-cvs] JBossAS SVN: r96589 - in projects/microcontainer/branches/Branch_2_0/dependency/src: test/java/org/jboss/test/dependency/controller/support and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Thu Nov 19 12:17:23 EST 2009


Author: adrian at jboss.org
Date: 2009-11-19 12:17:22 -0500 (Thu, 19 Nov 2009)
New Revision: 96589

Added:
   projects/microcontainer/branches/Branch_2_0/dependency/src/test/java/org/jboss/test/dependency/controller/support/RecursiveDependencyItem.java
   projects/microcontainer/branches/Branch_2_0/dependency/src/test/java/org/jboss/test/dependency/controller/test/RecursiveResolutionTestCase.java
Modified:
   projects/microcontainer/branches/Branch_2_0/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
   projects/microcontainer/branches/Branch_2_0/dependency/src/test/java/org/jboss/test/dependency/controller/test/ControllerTestSuite.java
Log:
[JBKERNEL-62] - Fix recursive resolution

Modified: projects/microcontainer/branches/Branch_2_0/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
===================================================================
--- projects/microcontainer/branches/Branch_2_0/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java	2009-11-19 17:16:28 UTC (rev 96588)
+++ projects/microcontainer/branches/Branch_2_0/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java	2009-11-19 17:17:22 UTC (rev 96589)
@@ -84,7 +84,7 @@
    /** The error contexts Map<Name, ControllerContext> */
    private Map<Object, ControllerContext> errorContexts = new ConcurrentHashMap<Object, ControllerContext>();
 
-   /** The contexts that are currently being installed */
+   /** The contexts that are currently being resolved/installed */
    private Set<ControllerContext> installing = new CopyOnWriteArraySet<ControllerContext>();
 
    /** The parent controller */
@@ -1040,7 +1040,7 @@
    {
       boolean resolutions = false;
       Set<ControllerContext> unresolved = contextsByState.get(fromState);
-      Set<ControllerContext> resolved = resolveContexts(unresolved, toState, trace);
+      Set<ControllerContext> resolved = resolveContexts(unresolved, fromState, toState, trace);
       if (resolved.isEmpty() == false)
       {
          Set<ControllerContext> toProcess = new HashSet<ControllerContext>();
@@ -1051,12 +1051,8 @@
             {
                if (trace)
                   log.trace("Skipping already installed " + name + " for " + toState.getStateString());
+               installing.remove(context);
             }
-            else if (installing.add(context) == false)
-            {
-               if (trace)
-                  log.trace("Already installing " + name + " for " + toState.getStateString());
-            }
             else
             {
                toProcess.add(context);
@@ -1110,7 +1106,7 @@
             }
          }
       }
-
+      
       return resolutions;
    }
 
@@ -1120,11 +1116,12 @@
     * This method must be invoked with the write lock taken
     *
     * @param contexts the contexts
-    * @param state    the state
+    * @param fromState the from state
+    * @param toState   the to state
     * @param trace    whether trace is enabled
     * @return the set of resolved contexts
     */
-   protected Set<ControllerContext> resolveContexts(Set<ControllerContext> contexts, ControllerState state, boolean trace)
+   protected Set<ControllerContext> resolveContexts(Set<ControllerContext> contexts, ControllerState fromState, ControllerState toState, boolean trace)
    {
       HashSet<ControllerContext> result = new HashSet<ControllerContext>();
 
@@ -1132,22 +1129,40 @@
       {
          for (ControllerContext ctx : contexts)
          {
-            if (advance(ctx))
+            Object name = ctx.getName();
+            if (fromState.equals(ctx.getState()) == false)
             {
+               if (trace)
+                  log.trace("Skipping already installed " + name + " for " + toState.getStateString());
+            }
+            else if (installing.add(ctx) == false)
+            {
+               if (trace)
+                  log.trace("Already installing " + name + " for " + toState.getStateString());
+            }
+            else if (advance(ctx))
+            {
                DependencyInfo dependencies = ctx.getDependencyInfo();
                try
                {
-                  if (dependencies == null || dependencies.resolveDependencies(this, state))
+                  if (dependencies == null || dependencies.resolveDependencies(this, toState))
                      result.add(ctx);
+                  else
+                     installing.remove(ctx);
                }
                catch (Throwable error)
                {
-                  log.error("Error resolving dependencies for " + state.getStateString() + ": " + ctx.toShortString(), error);
+                  installing.remove(ctx);
+                  log.error("Error resolving dependencies for " + toState.getStateString() + ": " + ctx.toShortString(), error);
                   uninstallContext(ctx, ControllerState.NOT_INSTALLED, trace);
                   errorContexts.put(ctx.getName(), ctx);
                   ctx.setError(error);
                }
             }
+            else
+            {
+               installing.remove(ctx);
+            }
          }
       }
 

Added: projects/microcontainer/branches/Branch_2_0/dependency/src/test/java/org/jboss/test/dependency/controller/support/RecursiveDependencyItem.java
===================================================================
--- projects/microcontainer/branches/Branch_2_0/dependency/src/test/java/org/jboss/test/dependency/controller/support/RecursiveDependencyItem.java	                        (rev 0)
+++ projects/microcontainer/branches/Branch_2_0/dependency/src/test/java/org/jboss/test/dependency/controller/support/RecursiveDependencyItem.java	2009-11-19 17:17:22 UTC (rev 96589)
@@ -0,0 +1,66 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* as indicated by the @author tags. See the copyright.txt file in the
+* distribution for a full listing of individual contributors.
+*
+* This is free software; you can redistribute it and/or modify it
+* under the terms of the GNU Lesser General Public License as
+* published by the Free Software Foundation; either version 2.1 of
+* the License, or (at your option) any later version.
+*
+* This software is distributed in the hope that it will be useful,
+* but WITHOUT ANY WARRANTY; without even the implied warranty of
+* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
+* Lesser General Public License for more details.
+*
+* You should have received a copy of the GNU Lesser General Public
+* License along with this software; if not, write to the Free
+* Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
+* 02110-1301 USA, or see the FSF site: http://www.fsf.org.
+*/
+package org.jboss.test.dependency.controller.support;
+
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+import org.jboss.dependency.spi.Controller;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.ControllerStateModel;
+
+/**
+ * RecursiveDependencyItem.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class RecursiveDependencyItem extends AbstractDependencyItem
+{
+   public RecursiveDependencyItem(Object name, Object iDependOn, ControllerState whenRequired, ControllerState dependentState)
+   {
+      super(name, iDependOn, whenRequired, dependentState);
+   }
+
+   @Override
+   public boolean resolve(Controller controller)
+   {
+      ControllerStateModel stateModel = controller.getStates();
+      ControllerContext other = controller.getContext(getIDependOn(), null);
+      ControllerState otherState = getDependentState();
+      if (stateModel.isBeforeState(other.getState(), otherState))
+      {
+         try
+         {
+            controller.change(other, otherState);
+         }
+         catch (Throwable t)
+         {
+            log.warn("Error", t);
+            return false;
+         }
+         if (stateModel.isBeforeState(other.getState(), otherState))
+            return false;
+      }
+      addDependsOnMe(controller, other);
+      return true;
+   }
+}

Modified: projects/microcontainer/branches/Branch_2_0/dependency/src/test/java/org/jboss/test/dependency/controller/test/ControllerTestSuite.java
===================================================================
--- projects/microcontainer/branches/Branch_2_0/dependency/src/test/java/org/jboss/test/dependency/controller/test/ControllerTestSuite.java	2009-11-19 17:16:28 UTC (rev 96588)
+++ projects/microcontainer/branches/Branch_2_0/dependency/src/test/java/org/jboss/test/dependency/controller/test/ControllerTestSuite.java	2009-11-19 17:17:22 UTC (rev 96589)
@@ -62,6 +62,7 @@
       suite.addTest(SelfDependencyTestCase.suite());
       suite.addTest(ShutdownControllerTestCase.suite());
       suite.addTest(StateConsistencyUnitTestCase.suite());
+      suite.addTest(RecursiveResolutionTestCase.suite());
 
       return suite;
    }

Added: projects/microcontainer/branches/Branch_2_0/dependency/src/test/java/org/jboss/test/dependency/controller/test/RecursiveResolutionTestCase.java
===================================================================
--- projects/microcontainer/branches/Branch_2_0/dependency/src/test/java/org/jboss/test/dependency/controller/test/RecursiveResolutionTestCase.java	                        (rev 0)
+++ projects/microcontainer/branches/Branch_2_0/dependency/src/test/java/org/jboss/test/dependency/controller/test/RecursiveResolutionTestCase.java	2009-11-19 17:17:22 UTC (rev 96589)
@@ -0,0 +1,77 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2008, Red Hat Middleware LLC, and individual contributors
+* 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.dependency.controller.test;
+
+import java.util.Collections;
+import java.util.Map;
+
+import junit.framework.Test;
+
+import org.jboss.dependency.plugins.AbstractControllerContext;
+import org.jboss.dependency.plugins.AbstractControllerContextActions;
+import org.jboss.dependency.plugins.action.ControllerContextAction;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerContextActions;
+import org.jboss.dependency.spi.ControllerMode;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.test.dependency.controller.support.RecursiveDependencyItem;
+
+/**
+ * RecursiveResolutionTestCase.
+ * 
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 1.1 $
+ */
+public class RecursiveResolutionTestCase extends AbstractDependencyTest
+{
+   public static Test suite()
+   {
+      return suite(RecursiveResolutionTestCase.class);
+   }
+   
+   public RecursiveResolutionTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testRecursiveResolve() throws Throwable
+   {
+      Map<ControllerState, ControllerContextAction> actionsMap = Collections.emptyMap();
+      ControllerContextActions actions = new AbstractControllerContextActions(actionsMap);
+
+      ControllerContext ctx1 = new AbstractControllerContext("1", actions);
+      ctx1.setMode(ControllerMode.MANUAL);
+      assertInstall(ctx1, ControllerState.NOT_INSTALLED);
+      
+      ControllerContext ctx2 = new AbstractControllerContext("2", actions); 
+      ctx2.setMode(ControllerMode.MANUAL);
+      DependencyInfo ctx2dependencies = ctx2.getDependencyInfo();
+      ctx2dependencies.addIDependOn(new RecursiveDependencyItem("2", "1", ControllerState.INSTALLED, ControllerState.INSTALLED));
+      assertInstall(ctx2, ControllerState.NOT_INSTALLED);
+      
+      enableTrace("org.jboss.dependency");
+      
+      assertChange(ctx2, ControllerState.INSTALLED);
+      assertContext(ctx1, ControllerState.INSTALLED);
+   }
+}




More information about the jboss-cvs-commits mailing list