[jboss-cvs] JBossAS SVN: r96588 - in projects/kernel/trunk/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:16:29 EST 2009
Author: adrian at jboss.org
Date: 2009-11-19 12:16:28 -0500 (Thu, 19 Nov 2009)
New Revision: 96588
Added:
projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/RecursiveDependencyItem.java
projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/RecursiveResolutionTestCase.java
Modified:
projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/ControllerTestSuite.java
Log:
[JBKERNEL-62] - Fix recursive resolution
Modified: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java 2009-11-19 16:35:17 UTC (rev 96587)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java 2009-11-19 17:16:28 UTC (rev 96588)
@@ -90,7 +90,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 contexts that are currently being installed by the executor */
@@ -1077,7 +1077,7 @@
{
boolean resolutions = false;
Set<ControllerContext> unresolved = getContextsByState(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>();
@@ -1088,17 +1088,8 @@
{
if (trace)
log.trace("Skipping already installed " + name + " for " + toState.getStateString());
+ installing.remove(context);
}
- else if (contextsInstalledByExecutor.isInstalledByOtherThread(context))
- {
- if (trace)
- log.trace("Installed by other thread " + name);
- }
- else if (installing.add(context) == false || contextsInstalledByExecutor.isBeingInstalled(context) == true)
- {
- if (trace)
- log.trace("Already installing " + name + " for " + toState.getStateString());
- }
else
{
toProcess.add(context);
@@ -1238,11 +1229,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>();
@@ -1250,21 +1242,50 @@
{
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 (contextsInstalledByExecutor.isInstalledByOtherThread(ctx))
+ {
+ if (trace)
+ log.trace("Installed by other thread " + name);
+ }
+ else if (installing.add(ctx) == false)
+ {
+ if (trace)
+ log.trace("Already installing " + name + " for " + toState.getStateString());
+ }
+ else if (contextsInstalledByExecutor.isBeingInstalled(ctx) == true)
+ {
+ if (trace)
+ log.trace("Already installing " + name + " for " + toState.getStateString());
+ installing.remove(ctx);
+ }
+ else if (advance(ctx))
+ {
try
{
- if (resolveDependencies(ctx, state))
+ if (resolveDependencies(ctx, 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, stateModel.getInitialState(), trace);
errorContexts.put(ctx.getName(), ctx);
ctx.setError(error);
}
}
+ else
+ {
+ installing.remove(ctx);
+ }
}
}
Added: projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/RecursiveDependencyItem.java
===================================================================
--- projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/RecursiveDependencyItem.java (rev 0)
+++ projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/support/RecursiveDependencyItem.java 2009-11-19 17:16:28 UTC (rev 96588)
@@ -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/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/ControllerTestSuite.java
===================================================================
--- projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/ControllerTestSuite.java 2009-11-19 16:35:17 UTC (rev 96587)
+++ projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/ControllerTestSuite.java 2009-11-19 17:16:28 UTC (rev 96588)
@@ -29,7 +29,6 @@
* Controller Test Suite.
*
* @author <a href="adrian at jboss.com">Adrian Brock</a>
- * @author <a href="ales.justin at jboss.com">Ales Justin</a>
* @version $Revision$
*/
public class ControllerTestSuite extends TestSuite
@@ -45,7 +44,6 @@
suite.addTest(AliasDependencyTestCase.suite());
suite.addTest(AliasUnitTestCase.suite());
- suite.addTest(AsynchronousTestCase.suite());
suite.addTest(BadDependencyInfoTestCase.suite());
suite.addTest(BasicControllerTestCase.suite());
suite.addTest(BasicDependencyTestCase.suite());
@@ -64,10 +62,7 @@
suite.addTest(SelfDependencyTestCase.suite());
suite.addTest(ShutdownControllerTestCase.suite());
suite.addTest(StateConsistencyUnitTestCase.suite());
- suite.addTest(StatelessControllerTestCase.suite());
- suite.addTest(ControllerReportingTestCase.suite());
- suite.addTest(ControllerStateModelTestCase.suite());
- suite.addTest(InitialStateTestCase.suite());
+ suite.addTest(RecursiveResolutionTestCase.suite());
return suite;
}
Added: projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/RecursiveResolutionTestCase.java
===================================================================
--- projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/RecursiveResolutionTestCase.java (rev 0)
+++ projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/RecursiveResolutionTestCase.java 2009-11-19 17:16:28 UTC (rev 96588)
@@ -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