[jboss-cvs] JBossAS SVN: r83658 - in projects/bootstrap/trunk/src: test/java/org/jboss/bootstrap and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jan 30 04:13:57 EST 2009


Author: ALRubinger
Date: 2009-01-30 04:13:57 -0500 (Fri, 30 Jan 2009)
New Revision: 83658

Added:
   projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/
   projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/common/
   projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/common/ServerConfigUtil.java
   projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/jboot5/
   projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/jboot5/NoInitServerImpl.java
   projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/jboot5/unit/
   projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/jboot5/unit/CleanShutdownOnIncompleteInitTestCase.java
Modified:
   projects/bootstrap/trunk/src/main/java/org/jboss/bootstrap/AbstractServerImpl.java
   projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/GetServerNativeDirPropertyTestCase.java
Log:
[JBBOOT-5] Tests and fixes for clean startup/shutdown w/ incomplete initialization

Modified: projects/bootstrap/trunk/src/main/java/org/jboss/bootstrap/AbstractServerImpl.java
===================================================================
--- projects/bootstrap/trunk/src/main/java/org/jboss/bootstrap/AbstractServerImpl.java	2009-01-30 09:11:56 UTC (rev 83657)
+++ projects/bootstrap/trunk/src/main/java/org/jboss/bootstrap/AbstractServerImpl.java	2009-01-30 09:13:57 UTC (rev 83658)
@@ -21,7 +21,6 @@
  */
 package org.jboss.bootstrap;
 
-import java.io.File;
 import java.lang.reflect.Method;
 import java.net.URL;
 import java.util.Date;
@@ -56,7 +55,7 @@
    implements ServerProcess, NotificationEmitter
 {
    /** Instance logger. */
-   protected Logger log;
+   protected Logger log = Logger.getLogger(AbstractServerImpl.class.getName() + " - [DEFAULT]");
 
    /** Container for version information. */
    private final Version version = Version.getInstance();
@@ -314,6 +313,12 @@
 
       return config;
    }
+   
+   protected void setConfig(BaseServerConfig config)
+   {
+      assert config!=null:"Specified " + ServerConfig.class.getSimpleName() + " was null";
+      this.config = config;
+   }
 
    /**
     * Check if the server is started.
@@ -473,7 +478,7 @@
     */
    protected void shutdownServer()
    {
-      if (log.isTraceEnabled())
+      if (log!=null && log.isTraceEnabled())
          log.trace("Shutdown caller:", new Throwable("Here"));
       
       // avoid entering twice; may happen when called directly

Modified: projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/GetServerNativeDirPropertyTestCase.java
===================================================================
--- projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/GetServerNativeDirPropertyTestCase.java	2009-01-30 09:11:56 UTC (rev 83657)
+++ projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/GetServerNativeDirPropertyTestCase.java	2009-01-30 09:13:57 UTC (rev 83658)
@@ -21,13 +21,12 @@
  */
 package org.jboss.bootstrap;
 
-import java.io.File;
-import java.net.URL;
 import java.util.Properties;
 
 import junit.framework.TestCase;
 
 import org.jboss.bootstrap.spi.ServerConfig;
+import org.jboss.bootstrap.test.common.ServerConfigUtil;
 import org.junit.Test;
 
 /**
@@ -58,27 +57,16 @@
       // Initialize
       String expectedNativeDir = "expected";
       String wrongNativeDir = "wrong";
-      URL currentUrl = this.getClass().getProtectionDomain().getCodeSource().getLocation();
-      File currentFile = new File(currentUrl.toURI());
-      File homeFile = new File(currentFile, "jbosshome");
-      File serverFile = new File(homeFile, "server/default");
 
-      // Make server dir
-      if (!serverFile.isDirectory() && !serverFile.mkdirs())
-      {
-         throw new RuntimeException("Could not create/get server directory " + serverFile);
-      }
-
       // Create properties for the server config
       Properties configProps = new Properties();
-      configProps.put(ServerConfig.HOME_DIR, homeFile.toURL().toString());
       configProps.put(ServerConfig.NATIVE_DIR_PROPERTY, expectedNativeDir);
 
       // Set a system property for native dir
       System.getProperties().put(ServerConfig.NATIVE_DIR_PROPERTY, wrongNativeDir);
 
       // Create the config
-      BaseServerConfig config = new BaseServerConfig(configProps);
+      BaseServerConfig config = ServerConfigUtil.getConfig(configProps);
 
       // Test the native dir is expected
       TestCase.assertEquals("NATIVE_DIR was not as passed in properties to config", expectedNativeDir, config

Added: projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/common/ServerConfigUtil.java
===================================================================
--- projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/common/ServerConfigUtil.java	                        (rev 0)
+++ projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/common/ServerConfigUtil.java	2009-01-30 09:13:57 UTC (rev 83658)
@@ -0,0 +1,135 @@
+/*
+ * 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.bootstrap.test.common;
+
+import java.io.File;
+import java.net.MalformedURLException;
+import java.net.URISyntaxException;
+import java.net.URL;
+import java.util.Properties;
+
+import org.jboss.bootstrap.BaseServerConfig;
+import org.jboss.bootstrap.spi.ServerConfig;
+
+/**
+ * ServerConfigUtil
+ * 
+ * Helper methods for dealing with ServerConfig objects
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ServerConfigUtil
+{
+
+   /**
+    * Non-instanciable
+    */
+   private ServerConfigUtil()
+   {
+
+   }
+
+   //--------------------------------------------------------------------||
+   // Utilities ---------------------------------------------------------||
+   //--------------------------------------------------------------------||
+
+   /**
+    * Obtains a JBOSS_HOME file using the current location of the code source.
+    * The actual home will be in the directory "jbossHome" of the current location 
+    */
+   public static final File getJBossHomeFromCurrentLocation()
+   {
+      return getJBossHomeFromCurrentLocation("jbossHome");
+   }
+
+   /**
+    * Obtains a JBOSS_HOME file using the current location of the code source.
+    * The actual home will be in the specified subdirectory of the current location 
+    */
+   public static final File getJBossHomeFromCurrentLocation(String subdirectoryOfCurrent)
+   {
+      // Ensure we've been given a 
+      assert subdirectoryOfCurrent != null : "Specified JBOSS_HOME child dir from current location is unspecified";
+
+      // Obtain current URLs and build a JBOSS_HOME base
+      URL currentUrl = ServerConfigUtil.class.getProtectionDomain().getCodeSource().getLocation();
+      File currentFile = null;
+      try
+      {
+         currentFile = new File(currentUrl.toURI());
+      }
+      catch (URISyntaxException e)
+      {
+         throw new RuntimeException(e);
+      }
+      File homeFile = new File(currentFile, subdirectoryOfCurrent);
+      return homeFile;
+   }
+
+   /**
+    * Obtains a ServerConfig from the specified properties.  Will additionally:
+    * 
+    * - Add the ServerConfig.HOME_DIR property is not specified
+    * - Make the directories required for ServerConfig.HOME_DIR 
+    */
+   public static final BaseServerConfig getConfig(Properties props)
+   {
+      // Define a JBOSS_HOME and default server
+      File homeFile = getJBossHomeFromCurrentLocation();
+      File serverFile = new File(homeFile, "server/default");
+
+      // Make server dir
+      if (!serverFile.isDirectory() && !serverFile.mkdirs())
+      {
+         throw new RuntimeException("Could not create/get server directory " + serverFile);
+      }
+
+      // Add ServerConfig.HOME_DIR if not specified
+      if (props.getProperty(ServerConfig.HOME_DIR) == null)
+      {
+         try
+         {
+            props.setProperty(ServerConfig.HOME_DIR, homeFile.toURL().toString());
+         }
+         catch (MalformedURLException e)
+         {
+            throw new RuntimeException(e);
+         }
+      }
+
+      // Create the config
+      BaseServerConfig config = null;
+      try
+      {
+         config = new BaseServerConfig(props);
+      }
+      catch (Exception e)
+      {
+         throw new RuntimeException("Could not create new server config", e);
+      }
+
+      // Return
+      return config;
+   }
+
+}

Added: projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/jboot5/NoInitServerImpl.java
===================================================================
--- projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/jboot5/NoInitServerImpl.java	                        (rev 0)
+++ projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/jboot5/NoInitServerImpl.java	2009-01-30 09:13:57 UTC (rev 83658)
@@ -0,0 +1,79 @@
+/*
+ * 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.bootstrap.test.jboot5;
+
+import java.util.Properties;
+
+import org.jboss.bootstrap.AbstractServerImpl;
+import org.jboss.bootstrap.test.common.ServerConfigUtil;
+import org.jboss.util.StopWatch;
+
+/**
+ * NoInitServerImpl
+ * 
+ * An implementation of ServerImpl which does not perform initialization
+ * such that shutdown can be tested cleanly (ie. does not rely upon complete 
+ * init)
+ * 
+ * JBBOOT-5
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class NoInitServerImpl extends AbstractServerImpl
+{
+   //--------------------------------------------------------------------||
+   // Required Implementations ------------------------------------------||
+   //--------------------------------------------------------------------||
+
+   /* (non-Javadoc)
+    * @see org.jboss.bootstrap.AbstractServerImpl#doShutdown()
+    */
+   @Override
+   protected void doShutdown()
+   {
+     
+   }
+
+   /* (non-Javadoc)
+    * @see org.jboss.bootstrap.AbstractServerImpl#doStart(org.jboss.util.StopWatch)
+    */
+   @Override
+   protected void doStart(StopWatch watch) throws Throwable
+   {
+    
+   }
+
+   //--------------------------------------------------------------------||
+   // Overridden Implementations ----------------------------------------||
+   //--------------------------------------------------------------------||
+
+   /**
+    * Initialization scheme which does nothing aside set the ServerConfig
+    */
+   @Override
+   public void init(Properties props) throws IllegalStateException, Exception
+   {
+      this.setConfig(ServerConfigUtil.getConfig(props));
+   }
+
+}

Added: projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/jboot5/unit/CleanShutdownOnIncompleteInitTestCase.java
===================================================================
--- projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/jboot5/unit/CleanShutdownOnIncompleteInitTestCase.java	                        (rev 0)
+++ projects/bootstrap/trunk/src/test/java/org/jboss/bootstrap/test/jboot5/unit/CleanShutdownOnIncompleteInitTestCase.java	2009-01-30 09:13:57 UTC (rev 83658)
@@ -0,0 +1,73 @@
+/*
+ * 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.bootstrap.test.jboot5.unit;
+
+import java.util.Properties;
+
+import junit.framework.TestCase;
+
+import org.jboss.bootstrap.spi.Server;
+import org.jboss.bootstrap.test.jboot5.NoInitServerImpl;
+import org.junit.Test;
+
+/**
+ * CleanShutdownOnIncompleteInitTestCase
+ * 
+ * Tests that AbstractServerImpl can startup/shutdown cleanly
+ * even when initialization has not yet been completely 
+ * performed
+ * 
+ * JBBOOT-5
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class CleanShutdownOnIncompleteInitTestCase
+{
+
+   /**
+    * 
+    * @throws Exception
+    */
+   @Test
+   public void testCleanShutdownWithNoInit() throws Exception
+   {
+
+      // Create and perform minimal initialization upon a new server
+      Server server = new NoInitServerImpl();
+      server.init(new Properties());
+
+      // Startup and shutdown
+      try
+      {
+         server.start();
+         server.shutdown();
+      }
+      catch (Exception e)
+      {
+         throw e;
+         //TestCase.fail("Startup/shutdown sequence without proper configuration should be clean, got exception: " + e);
+      }
+
+   }
+
+}




More information about the jboss-cvs-commits mailing list