[jboss-cvs] JBossAS SVN: r95837 - in projects/kernel/trunk/dependency/src: test/java/org/jboss/test/dependency/controller/test and 1 other directory.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Oct 30 11:43:27 EDT 2009


Author: kabir.khan at jboss.com
Date: 2009-10-30 11:43:27 -0400 (Fri, 30 Oct 2009)
New Revision: 95837

Added:
   projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/InitialStateTestCase.java
Modified:
   projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java
Log:
[JBKERNEL-58] Enable states before NOT_INSTALLED

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-10-30 15:09:19 UTC (rev 95836)
+++ projects/kernel/trunk/dependency/src/main/java/org/jboss/dependency/plugins/AbstractController.java	2009-10-30 15:43:27 UTC (rev 95837)
@@ -676,7 +676,7 @@
             // get a hold on possible parent before its nullified in uninstall
             AbstractController parent = getParentController();
 
-            uninstallContext(context, ControllerState.NOT_INSTALLED, trace);
+            uninstallContext(context, stateModel.getInitialState(), trace);
 
             try
             {
@@ -929,12 +929,13 @@
       ControllerState toState = null;
       if (ControllerState.ERROR.equals(fromState))
       {
+         ControllerState initialState = stateModel.getInitialState();
          errorContexts.remove(context);
          Throwable error = null;
          unlockWrite();
          try
          {
-            install(context, ControllerState.ERROR, ControllerState.NOT_INSTALLED);
+            install(context, ControllerState.ERROR, initialState);
          }
          catch (Throwable t)
          {
@@ -951,9 +952,9 @@
                return false;
             }
          }
-         Set<ControllerContext> notInstalled = fromController.getContextsByState(ControllerState.NOT_INSTALLED);
+         Set<ControllerContext> notInstalled = fromController.getContextsByState(initialState);
          notInstalled.add(context);
-         context.setState(ControllerState.NOT_INSTALLED);
+         context.setState(initialState);
          return true;
       }
       else
@@ -993,7 +994,7 @@
          if (error != null)
          {
             log.error("Error installing to " + toState.getStateString() + ": " + context.toShortString(), error);
-            uninstallContext(context, ControllerState.NOT_INSTALLED, trace);
+            uninstallContext(context, stateModel.getInitialState(), trace);
             errorContexts.put(context.getName(), context);
             context.setError(error);
             return false;
@@ -1257,7 +1258,7 @@
                catch (Throwable error)
                {
                   log.error("Error resolving dependencies for " + state.getStateString() + ": " + ctx.toShortString(), error);
-                  uninstallContext(ctx, ControllerState.NOT_INSTALLED, trace);
+                  uninstallContext(ctx, stateModel.getInitialState(), trace);
                   errorContexts.put(ctx.getName(), ctx);
                   ctx.setError(error);
                }
@@ -1358,7 +1359,7 @@
                            {
                               ControllerState whenRequired = item.getWhenRequired();
                               if (whenRequired == null)
-                                 whenRequired = ControllerState.NOT_INSTALLED;
+                                 whenRequired = stateModel.getInitialState();
 
                               for (ControllerContext dependent : dependents)
                               {
@@ -2355,7 +2356,7 @@
                {
                   Object ctx = trace ? context : context.getName();
                   log.error("Error resolving dependencies for " + toState.getStateString() + ": " + ctx, error);
-                  uninstallContext(context, ControllerState.NOT_INSTALLED, trace);
+                  uninstallContext(context, stateModel.getInitialState(), trace);
                   errorContexts.put(context.getName(), context);
                   context.setError(error);
                }

Added: projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/InitialStateTestCase.java
===================================================================
--- projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/InitialStateTestCase.java	                        (rev 0)
+++ projects/kernel/trunk/dependency/src/test/java/org/jboss/test/dependency/controller/test/InitialStateTestCase.java	2009-10-30 15:43:27 UTC (rev 95837)
@@ -0,0 +1,149 @@
+/*
+* 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.dependency.controller.test;
+
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.List;
+
+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.ControllerState;
+
+/**
+ * Test to try out a new ControllerStateModel implementation 
+ * 
+ * @author <a href="kabir.khan at jboss.com">Kabir Khan</a>
+ * @version $Revision: 37459 $
+ */
+public class InitialStateTestCase extends AbstractDependencyTest
+{
+   final static ControllerState INITIAL_STATE = new ControllerState("The very very first");
+
+   public static Test suite()
+   {
+      return suite(InitialStateTestCase.class);
+   }
+   
+   public InitialStateTestCase(String name)
+   {
+      super(name);
+   }
+   
+   public void testMapControllerStateModel() throws Throwable
+   {
+      //controller.addState(initialState, ControllerState.NOT_INSTALLED);
+      
+      RecordingControllerContext context = new RecordingControllerContext();
+      
+      assertInstall(context, ControllerState.INSTALLED);
+      assertList(context.states, 
+            ControllerState.NOT_INSTALLED, 
+            ControllerState.PRE_INSTALL, 
+            ControllerState.DESCRIBED, 
+            ControllerState.INSTANTIATED,
+            ControllerState.CONFIGURED,
+            ControllerState.CREATE,
+            ControllerState.START,
+            ControllerState.INSTALLED);
+      
+      context.states.clear();
+      assertUninstall(context);
+      assertList(context.states, 
+            ControllerState.START,
+            ControllerState.CREATE,
+            ControllerState.CONFIGURED,
+            ControllerState.INSTANTIATED,
+            ControllerState.DESCRIBED, 
+            ControllerState.PRE_INSTALL, 
+            ControllerState.NOT_INSTALLED, 
+            ControllerState.ERROR);
+      
+      context.states.clear();
+    
+      controller.addState(INITIAL_STATE, ControllerState.NOT_INSTALLED);
+
+      assertInstall(context, ControllerState.INSTALLED);
+      assertList(context.states, 
+            INITIAL_STATE, 
+            ControllerState.NOT_INSTALLED, 
+            ControllerState.PRE_INSTALL, 
+            ControllerState.DESCRIBED, 
+            ControllerState.INSTANTIATED,
+            ControllerState.CONFIGURED,
+            ControllerState.CREATE,
+            ControllerState.START,
+            ControllerState.INSTALLED);
+
+      context.states.clear();
+      assertUninstall(context);
+      assertList(context.states, 
+            ControllerState.START,
+            ControllerState.CREATE,
+            ControllerState.CONFIGURED,
+            ControllerState.INSTANTIATED,
+            ControllerState.DESCRIBED, 
+            ControllerState.PRE_INSTALL, 
+            ControllerState.NOT_INSTALLED, 
+            INITIAL_STATE, 
+            ControllerState.ERROR);
+      
+   }
+
+   private void assertList(List<ControllerState> states, ControllerState...expected)
+   {
+      assertEquals(expected.length, states.size());
+      
+      for (int i = 0 ; i < expected.length ; i++)
+      {
+         assertEquals(expected[i], states.get(i));
+      }
+   }
+   
+   private static class MockControllerContextActions extends AbstractControllerContextActions
+   {
+      public MockControllerContextActions()
+      {
+         super(new HashMap<ControllerState, ControllerContextAction>());
+      }
+   }
+   
+   private static class RecordingControllerContext extends AbstractControllerContext
+   {
+      List<ControllerState> states = new ArrayList<ControllerState>();
+      
+      public RecordingControllerContext()
+      {
+         super("Test", new MockControllerContextActions());
+      }
+
+      @Override
+      public void setState(ControllerState state)
+      {
+         super.setState(state);
+         states.add(state);
+      }
+   }
+}




More information about the jboss-cvs-commits mailing list