[jboss-cvs] JBossAS SVN: r75688 - in projects/microcontainer/trunk/dependency/src: tests/org/jboss/test/dependency/controller/support and 1 other directories.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Fri Jul 11 09:17:24 EDT 2008
Author: alesj
Date: 2008-07-11 09:17:24 -0400 (Fri, 11 Jul 2008)
New Revision: 75688
Added:
projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/support/ProxyDependencyInfo.java
projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/support/ProxyDependencyItem.java
projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/test/BadDependencyInfoTestCase.java
Modified:
projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java
projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/test/AbstractDependencyTest.java
projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/test/ControllerTestSuite.java
Log:
[JBMICROCONT-313]; adding tests for bad DependencyInfo/Item usage.
Modified: projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java 2008-07-11 13:14:35 UTC (rev 75687)
+++ projects/microcontainer/trunk/dependency/src/main/org/jboss/dependency/plugins/AbstractController.java 2008-07-11 13:17:24 UTC (rev 75688)
@@ -664,14 +664,23 @@
DependencyInfo dependencies = context.getDependencyInfo();
if (trace)
{
- String dependsOn = null;
+ String dependsOn = "[]";
if (dependencies != null)
{
- Set<DependencyItem> set = dependencies.getIDependOn(null);
- if (set != null)
- dependsOn = set.toString();
+ try
+ {
+ Set<DependencyItem> set = dependencies.getIDependOn(null);
+ if (set != null)
+ dependsOn = set.toString();
+ }
+ catch (Throwable t)
+ {
+ log.warn("Exception getting dependencies: " + t);
+ dependsOn = null;
+ }
}
- log.trace("Dependencies for " + name + ": " + dependsOn);
+ if (dependsOn != null)
+ log.trace("Dependencies for " + name + ": " + dependsOn);
}
boolean ok = incrementState(context, trace);
@@ -1019,7 +1028,7 @@
DependencyInfo dependencies = ctx.getDependencyInfo();
try
{
- if (dependencies.resolveDependencies(this, state))
+ if (dependencies != null && dependencies.resolveDependencies(this, state))
result.add(ctx);
}
catch (Throwable error)
@@ -1090,31 +1099,44 @@
throw new Error("INTERNAL ERROR: context not found in previous state " + fromState.getStateString() + " context=" + context.toShortString(), new Exception("STACKTRACE"));
DependencyInfo dependencies = context.getDependencyInfo();
- Set<DependencyItem> dependsOnMe = dependencies.getDependsOnMe(null);
- if (dependsOnMe.isEmpty() == false)
+ if (dependencies != null)
{
- for (DependencyItem item : dependsOnMe)
+ try
{
- if (item.isResolved())
+ Set<DependencyItem> dependsOnMe = dependencies.getDependsOnMe(null);
+ if (dependsOnMe.isEmpty() == false)
{
- ControllerState dependentState = item.getDependentState();
- if (dependentState == null || dependentState.equals(fromState))
+ for (DependencyItem item : dependsOnMe)
{
- if (item.unresolved(this))
+ if (item.isResolved())
{
- ControllerContext dependent = getContext(item.getName(), null);
- if (dependent != null)
+ ControllerState dependentState = item.getDependentState();
+ if (dependentState == null || dependentState.equals(fromState))
{
- ControllerState whenRequired = item.getWhenRequired();
- if (whenRequired == null)
- whenRequired = ControllerState.NOT_INSTALLED;
- if (isBeforeState(dependent.getState(), whenRequired) == false)
- uninstallContext(dependent, whenRequired, trace);
+ if (item.unresolved(this))
+ {
+ ControllerContext dependent = getContext(item.getName(), null);
+ if (dependent != null)
+ {
+ ControllerState whenRequired = item.getWhenRequired();
+ if (whenRequired == null)
+ whenRequired = ControllerState.NOT_INSTALLED;
+ if (isBeforeState(dependent.getState(), whenRequired) == false)
+ uninstallContext(dependent, whenRequired, trace);
+ }
+ }
}
}
}
}
}
+ catch (Throwable error)
+ {
+ log.error("Error resolving dependencies for " + fromState.getStateString() + ": " + context.toShortString(), error);
+ // Not much else we can do - no uninstall, since we are at uninstall ;-)
+ errorContexts.put(context.getName(), context);
+ context.setError(error);
+ }
}
// The state could have changed while calling out to dependents
@@ -1396,15 +1418,18 @@
protected void handleLifecycleCallbacks(ControllerContext context, ControllerState state, boolean install) throws Throwable
{
DependencyInfo di = context.getDependencyInfo();
- List<LifecycleCallbackItem> callbacks = di.getLifecycleCallbacks();
- for (LifecycleCallbackItem callback : callbacks)
+ if (di != null)
{
- if (callback.getWhenRequired().equals(state))
+ List<LifecycleCallbackItem> callbacks = di.getLifecycleCallbacks();
+ for (LifecycleCallbackItem callback : callbacks)
{
- if (install)
- callback.install(context);
- else
- callback.uninstall(context);
+ if (callback.getWhenRequired().equals(state))
+ {
+ if (install)
+ callback.install(context);
+ else
+ callback.uninstall(context);
+ }
}
}
}
Added: projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/support/ProxyDependencyInfo.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/support/ProxyDependencyInfo.java (rev 0)
+++ projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/support/ProxyDependencyInfo.java 2008-07-11 13:17:24 UTC (rev 75688)
@@ -0,0 +1,65 @@
+/*
+* 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.dependency.controller.support;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.jboss.dependency.plugins.AbstractDependencyInfo;
+import org.jboss.dependency.spi.DependencyInfo;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ProxyDependencyInfo extends AbstractDependencyInfo implements InvocationHandler
+{
+ private Method method;
+ private int allowedHits;
+
+ public ProxyDependencyInfo(Method method, int allowedHits)
+ {
+ this.method = method;
+ this.allowedHits = allowedHits;
+ }
+
+ public static DependencyInfo createDependencyInfo(Method method, int allowedHits)
+ {
+ return (DependencyInfo)Proxy.newProxyInstance(
+ DependencyInfo.class.getClassLoader(),
+ new Class<?>[]{DependencyInfo.class},
+ new ProxyDependencyInfo(method, allowedHits));
+ }
+
+ public Object invoke(Object proxy, Method m, Object[] args) throws Throwable
+ {
+ if (m.equals(method))
+ {
+ if (allowedHits <= 0)
+ throw new RuntimeException("Failed");
+
+ allowedHits--;
+ }
+
+ return m.invoke(this, args);
+ }
+}
Added: projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/support/ProxyDependencyItem.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/support/ProxyDependencyItem.java (rev 0)
+++ projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/support/ProxyDependencyItem.java 2008-07-11 13:17:24 UTC (rev 75688)
@@ -0,0 +1,67 @@
+/*
+* 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.dependency.controller.support;
+
+import java.lang.reflect.InvocationHandler;
+import java.lang.reflect.Method;
+import java.lang.reflect.Proxy;
+
+import org.jboss.dependency.plugins.AbstractDependencyItem;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyItem;
+
+/**
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class ProxyDependencyItem extends AbstractDependencyItem implements InvocationHandler
+{
+ private Method method;
+ private int allowedHits;
+
+ public ProxyDependencyItem(Method method, int allowedHits, ControllerState whenRequired)
+ {
+ super(method.getName(), "bean", whenRequired, null);
+ this.method = method;
+ this.allowedHits = allowedHits;
+ }
+
+ public static DependencyItem createDependencyInfo(Method method, int allowedHits, ControllerState whenRequired)
+ {
+ return (DependencyItem)Proxy.newProxyInstance(
+ DependencyItem.class.getClassLoader(),
+ new Class<?>[]{DependencyItem.class},
+ new ProxyDependencyItem(method, allowedHits, whenRequired));
+ }
+
+ public Object invoke(Object proxy, Method m, Object[] args) throws Throwable
+ {
+ if (m.equals(method))
+ {
+ if (allowedHits <= 0)
+ throw new RuntimeException("Failed");
+
+ allowedHits--;
+ }
+
+ return m.invoke(this, args);
+ }
+}
\ No newline at end of file
Modified: projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/test/AbstractDependencyTest.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/test/AbstractDependencyTest.java 2008-07-11 13:14:35 UTC (rev 75687)
+++ projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/test/AbstractDependencyTest.java 2008-07-11 13:17:24 UTC (rev 75688)
@@ -23,12 +23,14 @@
import java.util.HashSet;
import java.util.Set;
+import java.util.Arrays;
import org.jboss.dependency.plugins.AbstractController;
import org.jboss.dependency.plugins.AbstractControllerContext;
import org.jboss.dependency.spi.Controller;
import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.ControllerStateModel;
import org.jboss.test.AbstractTestCaseWithSetup;
import org.jboss.test.AbstractTestDelegate;
import org.jboss.test.dependency.controller.support.MockControllerContextActions;
@@ -90,6 +92,16 @@
controller.install(context);
}
+ protected void uninstall(ControllerContext context) throws Throwable
+ {
+ controller.uninstall(context.getName());
+ }
+
+ protected ControllerStateModel getStateModel()
+ {
+ return controller.getStates();
+ }
+
protected void assertInstall(ControllerContext context, ControllerState expected) throws Throwable
{
controller.install(context);
@@ -145,8 +157,7 @@
if (aliases == null)
return null;
HashSet<Object> result = new HashSet<Object>(aliases.length);
- for (int i = 0; i < aliases.length; ++i)
- result.add(aliases[i]);
+ result.addAll(Arrays.asList(aliases));
return result;
}
Added: projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/test/BadDependencyInfoTestCase.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/test/BadDependencyInfoTestCase.java (rev 0)
+++ projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/test/BadDependencyInfoTestCase.java 2008-07-11 13:17:24 UTC (rev 75688)
@@ -0,0 +1,139 @@
+/*
+* 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.dependency.controller.test;
+
+import java.lang.reflect.Method;
+
+import junit.framework.Test;
+import org.jboss.dependency.plugins.AbstractControllerContext;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.DependencyInfo;
+import org.jboss.dependency.spi.DependencyItem;
+import org.jboss.test.dependency.controller.support.MockControllerContextActions;
+import org.jboss.test.dependency.controller.support.ProxyDependencyInfo;
+import org.jboss.test.dependency.controller.support.ProxyDependencyItem;
+
+/**
+ * Test bad DependencyInfo/Item.
+ *
+ * @author <a href="mailto:ales.justin at jboss.com">Ales Justin</a>
+ */
+public class BadDependencyInfoTestCase extends AbstractDependencyTest
+{
+ public BadDependencyInfoTestCase(String name)
+ {
+ super(name);
+ }
+
+ public static Test suite()
+ {
+ return suite(BadDependencyInfoTestCase.class);
+ }
+
+ public void testDependencyInfoMethods() throws Throwable
+ {
+ Method[] methods = DependencyInfo.class.getDeclaredMethods();
+ for(int i = 5; i >= 0; i--)
+ {
+ for (Method method : methods)
+ {
+ // Should we suppress this?
+ if ("getLifecycleCallbacks".equals(method.getName()))
+ continue;
+
+ AbstractControllerContext context = new AbstractControllerContext(
+ method.getName(),
+ new MockControllerContextActions(),
+ ProxyDependencyInfo.createDependencyInfo(method, i)
+ );
+ install(context);
+ assertTrue(context.getName().toString(), ControllerState.ERROR.equals(context.getState()) || ControllerState.INSTALLED.equals(context.getState()));
+ uninstall(context);
+ }
+ }
+ }
+
+ public void testDependencyItemMethodsOnMe() throws Throwable
+ {
+ Method[] methods = DependencyItem.class.getDeclaredMethods();
+ for(int i = 5; i >= 0; i--)
+ {
+ for (Method method : methods)
+ {
+ for(ControllerState whenRequired : getStateModel())
+ {
+ ControllerContext context = createControllerContext(method.getName());
+ DependencyInfo info = context.getDependencyInfo();
+ info.addDependsOnMe(ProxyDependencyItem.createDependencyInfo(method, i, whenRequired));
+ install(context);
+ assertTrue(context.getName().toString(), ControllerState.ERROR.equals(context.getState()) || ControllerState.INSTALLED.equals(context.getState()));
+ uninstall(context);
+ }
+ }
+ }
+ }
+
+ public void testDependencyItemMethodsOnThem() throws Throwable
+ {
+ Method[] methods = DependencyItem.class.getDeclaredMethods();
+ for(int i = 5; i >= 0; i--)
+ {
+ for (Method method : methods)
+ {
+ for(ControllerState whenRequired : getStateModel())
+ {
+ ControllerContext context = createControllerContext(method.getName());
+ DependencyInfo info = context.getDependencyInfo();
+ info.addIDependOn(ProxyDependencyItem.createDependencyInfo(method, i, whenRequired));
+ install(context);
+ ControllerState previous = getStateModel().getPreviousState(whenRequired);
+ assertTrue(context.getName().toString(), ControllerState.ERROR.equals(context.getState()) || previous == null || previous.equals(context.getState()));
+ uninstall(context);
+ }
+ }
+ }
+ }
+
+ public void testDependencyItemMethodsOnThemResolved() throws Throwable
+ {
+ Method[] methods = DependencyItem.class.getDeclaredMethods();
+ for(int i = 5; i >= 0; i--)
+ {
+ for (Method method : methods)
+ {
+ for(ControllerState whenRequired : getStateModel())
+ {
+ ControllerContext context = createControllerContext(method.getName());
+ DependencyInfo info = context.getDependencyInfo();
+ info.addIDependOn(ProxyDependencyItem.createDependencyInfo(method, i, whenRequired));
+ install(context);
+ ControllerContext bean = createControllerContext("bean");
+ install(bean);
+ assertTrue(context.getName().toString(), ControllerState.ERROR.equals(context.getState()) || ControllerState.INSTALLED.equals(context.getState()));
+ uninstall(bean);
+ uninstall(context);
+ }
+ }
+ }
+ }
+}
Modified: projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/test/ControllerTestSuite.java
===================================================================
--- projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/test/ControllerTestSuite.java 2008-07-11 13:14:35 UTC (rev 75687)
+++ projects/microcontainer/trunk/dependency/src/tests/org/jboss/test/dependency/controller/test/ControllerTestSuite.java 2008-07-11 13:17:24 UTC (rev 75688)
@@ -56,6 +56,7 @@
suite.addTest(AliasDependencyTestCase.suite());
suite.addTest(AliasUnitTestCase.suite());
suite.addTest(ShutdownControllerTestCase.suite());
+ suite.addTest(BadDependencyInfoTestCase.suite());
return suite;
}
More information about the jboss-cvs-commits
mailing list