[jboss-cvs] JBossAS SVN: r104523 - in projects/kernel/trunk: kernel/src/test/java/org/jboss/test/kernel/dependency/test and 1 other directory.
jboss-cvs-commits at lists.jboss.org
jboss-cvs-commits at lists.jboss.org
Thu May 6 11:38:57 EDT 2010
Author: kabir.khan at jboss.com
Date: 2010-05-06 11:38:56 -0400 (Thu, 06 May 2010)
New Revision: 104523
Added:
projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/dependency/test/ExtraStateTestCase.java
projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/dependency/test/ScopedExtraStateTestCase.java
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/AbstractControllerContext.java
projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/MapControllerStateModel.java
projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/ScopedController.java
projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/dependency/test/DependencyTestSuite.java
Log:
[JBKERNEL-119] Make sure that ControllerContext uses the optimized states from their controller's ControllerStateModel
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 2010-05-06 14:47:31 UTC (rev 104522)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java 2010-05-06 15:38:56 UTC (rev 104523)
@@ -321,6 +321,7 @@
{
if (stateModel.addState(state, before))
{
+ log.info("Adding state " + state.getStateString() + " to " + this);
Set<ControllerContext> contexts = new CopyOnWriteArraySet<ControllerContext>();
contextsByState.put(state, contexts);
}
@@ -624,7 +625,10 @@
public Set<ControllerContext> getContextsByState(ControllerState state)
{
- return contextsByState.get(state);
+ Set<ControllerContext> contexts = contextsByState.get(state);
+ if (contexts == null)
+ log.warn("No contexts for " + state.getStateString() + " in " + this);
+ return contexts;
}
public void install(ControllerContext context) throws Throwable
@@ -847,7 +851,7 @@
// set the required state
ControllerMode mode = context.getMode();
- context.setRequiredState(indexState(mode.getRequiredState()));
+ context.setRequiredState(mode.getRequiredState());
if (trace)
log.trace("Installing " + context.toShortString());
@@ -1607,7 +1611,7 @@
if (ControllerState.ERROR.equals(fromState))
return;
- ControllerState toState = stateModel.getPreviousState(fromState);
+ ControllerState toState = context.getController().getStates().getPreviousState(fromState);
if (toState == null)
{
// This is hack, we signal true uninstalled status by putting it in the error state
Modified: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractControllerContext.java
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractControllerContext.java 2010-05-06 14:47:31 UTC (rev 104522)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractControllerContext.java 2010-05-06 15:38:56 UTC (rev 104523)
@@ -36,6 +36,7 @@
import org.jboss.dependency.spi.ControllerContextActions;
import org.jboss.dependency.spi.ControllerMode;
import org.jboss.dependency.spi.ControllerState;
+import org.jboss.dependency.spi.ControllerStateModel;
import org.jboss.dependency.spi.DependencyInfo;
import org.jboss.dependency.spi.ErrorHandlingMode;
import org.jboss.dependency.spi.ScopeInfo;
@@ -270,7 +271,7 @@
public void setRequiredState(ControllerState state)
{
- this.requiredState = state;
+ this.requiredState = indexState(state);
}
public ControllerMode getMode()
@@ -366,7 +367,8 @@
public void setState(ControllerState state)
{
- this.state = state;
+ this.state = indexState(state);
+
flushJBossObjectCache();
}
@@ -589,4 +591,17 @@
{
return JMXObjectNameFix.needsAnAlias(original);
}
+
+ /**
+ * Index and optimize the controller state for the current controller
+ *
+ * @param the state
+ * @return the indexed state
+ */
+ protected ControllerState indexState(ControllerState state)
+ {
+ if (controller == null || controller instanceof AbstractController == false || state.equals(ControllerState.ERROR))
+ return state;
+ return ((AbstractController)controller).indexState(state);
+ }
}
Modified: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/MapControllerStateModel.java
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/MapControllerStateModel.java 2010-05-06 14:47:31 UTC (rev 104522)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/MapControllerStateModel.java 2010-05-06 15:38:56 UTC (rev 104523)
@@ -28,6 +28,7 @@
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.CopyOnWriteArrayList;
+import org.jboss.dependency.spi.ControllerContext;
import org.jboss.dependency.spi.ControllerState;
import org.jboss.dependency.spi.ControllerStateModel;
@@ -47,6 +48,7 @@
/** Thread-safe list for obtaining the iterators */
private final List<ControllerState> stateList = new CopyOnWriteArrayList<ControllerState>();
+
/**
* Add a state.
* Synchronized so that only one state can be added at a time.
@@ -204,12 +206,12 @@
{
private static final long serialVersionUID = 1L;
- final ControllerStateModel owner;
+ final MapControllerStateModel owner;
volatile int index;
volatile ControllerStateWrapper before;
volatile ControllerStateWrapper after;
- public ControllerStateWrapper(ControllerStateModel owner, ControllerState state, int index, ControllerStateWrapper before, ControllerStateWrapper after)
+ public ControllerStateWrapper(MapControllerStateModel owner, ControllerState state, int index, ControllerStateWrapper before, ControllerStateWrapper after)
{
super(state.getStateString(), false);
this.owner = owner;
Modified: projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/ScopedController.java
===================================================================
--- projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/ScopedController.java 2010-05-06 14:47:31 UTC (rev 104522)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/ScopedController.java 2010-05-06 15:38:56 UTC (rev 104523)
@@ -147,7 +147,6 @@
{
unregisterControllerContext(context);
context.setController(underlyingController);
- context.setRequiredState(underlyingController.indexState(context.getRequiredState()));
underlyingController.addControllerContext(context);
}
finally
Modified: projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/dependency/test/DependencyTestSuite.java
===================================================================
--- projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/dependency/test/DependencyTestSuite.java 2010-05-06 14:47:31 UTC (rev 104522)
+++ projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/dependency/test/DependencyTestSuite.java 2010-05-06 15:38:56 UTC (rev 104523)
@@ -127,6 +127,10 @@
suite.addTest(DependsOnMeCleanupTestCase.suite());
suite.addTest(ScopedDependsOnMeCleanupTestCase.suite());
suite.addTest(ContextInControllerWithLessStatesThanParentTestCase.suite());
+ suite.addTest(ExtraStateTestCase.suite());
+ suite.addTest(ScopedExtraStateTestCase.suite());
+ suite.addTest(ConstructorClassLoaderTestCase.suite());
+ suite.addTest(ConstructorClassLoaderTestCase.suite());
return suite;
}
}
Added: projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/dependency/test/ExtraStateTestCase.java
===================================================================
--- projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/dependency/test/ExtraStateTestCase.java (rev 0)
+++ projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/dependency/test/ExtraStateTestCase.java 2010-05-06 15:38:56 UTC (rev 104523)
@@ -0,0 +1,130 @@
+/*
+* JBoss, Home of Professional Open Source
+* Copyright 2005, 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.kernel.dependency.test;
+
+import java.util.HashSet;
+
+import junit.framework.Test;
+
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.plugins.AbstractDependencyValueMetaData;
+import org.jboss.beans.metadata.plugins.AbstractPropertyMetaData;
+import org.jboss.beans.metadata.spi.BeanMetaData;
+import org.jboss.beans.metadata.spi.PropertyMetaData;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.dependency.spi.ControllerState;
+import org.jboss.test.kernel.dependency.support.SimpleBeanImpl;
+import org.jboss.test.kernel.dependency.support.SimpleBeanWithDependencyImpl;
+
+/**
+ * OnDemand Dependency Test Case.
+ *
+ * @author <a href="adrian at jboss.com">Adrian Brock</a>
+ * @version $Revision: 100812 $
+ */
+public class ExtraStateTestCase extends OldAbstractKernelDependencyTest
+{
+ public static Test suite()
+ {
+ return suite(ExtraStateTestCase.class);
+ }
+
+ public ExtraStateTestCase(String name) throws Throwable
+ {
+ super(name);
+ }
+
+ public ExtraStateTestCase(String name, boolean xmltest, boolean scoped) throws Throwable
+ {
+ super(name, xmltest, scoped);
+ }
+
+ public void testInstallAndUninstallWithExtraState() throws Throwable
+ {
+ getUtil().getKernel().getController().addState(ControllerState.newState("Extra"), ControllerState.INSTALLED);
+ installAndUninstallWithExtraState();
+
+ ControllerContext context = assertInstall(offSetNumber(0), "Name1", ControllerState.INSTALLED);
+ assertContext("Name1");
+ assertController(context);
+ assertUninstall("Name1");
+ }
+
+ public void installAndUninstallWithExtraState() throws Throwable
+ {
+ AbstractBeanMetaData metaData1 = new AbstractBeanMetaData("Name1", SimpleBeanImpl.class.getName());
+ addAnnotation(metaData1);
+
+ setBeanMetaDatas(new BeanMetaData[] { metaData1});
+ }
+
+ public void testInstallAndUninstallDependencyWithExtraState() throws Throwable
+ {
+ getUtil().getKernel().getController().addState(ControllerState.newState("Extra"), ControllerState.INSTALLED);
+ installAndUninstallDependencyWithExtraState();
+
+ ControllerContext context2 = assertInstall(offSetNumber(1), "Name2", ControllerState.INSTANTIATED);
+ ControllerContext context1 = assertInstall(offSetNumber(0), "Name1", ControllerState.INSTALLED);
+ context1 = assertContext("Name1");
+ context2 = assertContext("Name2");
+ assertSame(getUtil().getKernel().getController(), context1.getController());
+ assertController(context2);
+
+ assertUninstall("Name1");
+ assertContext("Name2", ControllerState.INSTANTIATED);
+ assertUninstall("Name2");
+
+ assertNotInstalled("Name1");
+ assertNotInstalled("Name2");
+ }
+
+ public void installAndUninstallDependencyWithExtraState() throws Throwable
+ {
+ AbstractBeanMetaData metaData1 = new AbstractBeanMetaData("Name1", SimpleBeanImpl.class.getName());
+
+ AbstractBeanMetaData metaData2 = new AbstractBeanMetaData("Name2", SimpleBeanWithDependencyImpl.class.getName());
+ HashSet<PropertyMetaData> attributes2 = new HashSet<PropertyMetaData>();
+ attributes2.add(new AbstractPropertyMetaData("simpleBean", new AbstractDependencyValueMetaData("Name1")));
+ metaData2.setProperties(attributes2);
+ addAnnotation(metaData2);
+
+ setBeanMetaDatas(new BeanMetaData[] { metaData1, metaData2});
+ }
+
+ protected void buildMetaData()
+ {
+ }
+
+ protected void addAnnotation(AbstractBeanMetaData bmd)
+ {
+ }
+
+ protected int offSetNumber(int i)
+ {
+ return i;
+ }
+
+ protected void assertController(ControllerContext context)
+ {
+ assertSame(getUtil().getKernel().getController(), context.getController());
+ }
+}
\ No newline at end of file
Added: projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/dependency/test/ScopedExtraStateTestCase.java
===================================================================
--- projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/dependency/test/ScopedExtraStateTestCase.java (rev 0)
+++ projects/kernel/trunk/kernel/src/test/java/org/jboss/test/kernel/dependency/test/ScopedExtraStateTestCase.java 2010-05-06 15:38:56 UTC (rev 104523)
@@ -0,0 +1,69 @@
+/*
+* JBoss, Home of Professional Open Source.
+* Copyright 2006, 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.kernel.dependency.test;
+
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.Test;
+
+import org.jboss.beans.metadata.plugins.AbstractAnnotationMetaData;
+import org.jboss.beans.metadata.plugins.AbstractBeanMetaData;
+import org.jboss.beans.metadata.spi.AnnotationMetaData;
+import org.jboss.dependency.spi.ControllerContext;
+import org.jboss.metadata.plugins.scope.DeploymentScope;
+
+/**
+ *
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 1.1 $
+ */
+public class ScopedExtraStateTestCase extends ExtraStateTestCase
+{
+ public static Test suite()
+ {
+ return suite(ScopedExtraStateTestCase.class);
+ }
+
+ public ScopedExtraStateTestCase(String name) throws Throwable
+ {
+ super(name, false, true);
+ }
+
+ public ScopedExtraStateTestCase(String name, boolean xmltest) throws Throwable
+ {
+ super(name, xmltest, true);
+ }
+
+ protected void addAnnotation(AbstractBeanMetaData bmd)
+ {
+ Set<AnnotationMetaData> annotations = new HashSet<AnnotationMetaData>();
+ annotations.add(new AbstractAnnotationMetaData("@" + DeploymentScope.class.getName() + "(\"somedeployment\")"));
+ bmd.setAnnotations(annotations);
+ }
+
+ @Override
+ protected void assertController(ControllerContext context)
+ {
+ assertNotSame(getUtil().getKernel().getController(), context.getController());
+ }
+}
More information about the jboss-cvs-commits
mailing list