[jboss-cvs] JBossAS SVN: r90117 - in projects/embedded/trunk/testsuite: src/test/java/org/jboss and 2 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jun 12 04:10:30 EDT 2009


Author: ALRubinger
Date: 2009-06-12 04:10:30 -0400 (Fri, 12 Jun 2009)
New Revision: 90117

Added:
   projects/embedded/trunk/testsuite/src/test/java/org/jboss/SecurityActions.java
   projects/embedded/trunk/testsuite/src/test/java/org/jboss/ServerTestCase.java
Removed:
   projects/embedded/trunk/testsuite/src/test/java/org/jboss/embedded/test/server/
Modified:
   projects/embedded/trunk/testsuite/pom.xml
   projects/embedded/trunk/testsuite/src/test/resources/log4j.xml
Log:
[EMB-29] Prototype Embedded booting in a minimal CL scenario, mimicking AS Main

Modified: projects/embedded/trunk/testsuite/pom.xml
===================================================================
--- projects/embedded/trunk/testsuite/pom.xml	2009-06-12 07:44:04 UTC (rev 90116)
+++ projects/embedded/trunk/testsuite/pom.xml	2009-06-12 08:10:30 UTC (rev 90117)
@@ -28,30 +28,17 @@
 
   </properties>
 
-  <!-- Build -->
-  <build>
-
-  </build>
-
   <!-- Dependencies -->
   <dependencies>
 
-    <!--
-      Bring in Embedded distribution
-    -->
     <dependency>
       <groupId>org.jboss.embedded</groupId>
       <artifactId>jboss-embedded-assembly</artifactId>
       <version>${version.org.jboss.embedded_jboss.embedded.assembly}</version>
-      <optional>true</optional>
       <classifier>embedded</classifier>
+      <scope>test</scope>
     </dependency>
-
-    <!-- 
-    
-    
-    
-     -->
+ 
     <dependency>
       <groupId>org.jboss.logging</groupId>
       <artifactId>jboss-logging-log4j</artifactId>
@@ -59,15 +46,16 @@
     </dependency>
 
     <dependency>
-      <groupId>org.jboss.logging</groupId>
-      <artifactId>jboss-logging-spi</artifactId>
-      <scope>test</scope>
-    </dependency>
-
-    <dependency>
       <groupId>junit</groupId>
       <artifactId>junit</artifactId>
     </dependency>
+    
+    <dependency>
+      <groupId>gnu-getopt</groupId>
+      <artifactId>getopt</artifactId>
+      <version>1.0.13</version>
+    </dependency>
+    
   </dependencies>
 
 </project>

Added: projects/embedded/trunk/testsuite/src/test/java/org/jboss/SecurityActions.java
===================================================================
--- projects/embedded/trunk/testsuite/src/test/java/org/jboss/SecurityActions.java	                        (rev 0)
+++ projects/embedded/trunk/testsuite/src/test/java/org/jboss/SecurityActions.java	2009-06-12 08:10:30 UTC (rev 90117)
@@ -0,0 +1,119 @@
+package org.jboss;
+
+import java.security.AccessController;
+import java.security.PrivilegedAction;
+
+class SecurityActions
+{
+
+   //-------------------------------------------------------------------------------||
+   // Constructor ------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------||
+
+   /**
+    * No external instanciation
+    */
+   private SecurityActions()
+   {
+
+   }
+
+   //-------------------------------------------------------------------------------||
+   // Utility Methods --------------------------------------------------------------||
+   //-------------------------------------------------------------------------------||
+
+   /**
+    * Sets the specified property with key and value
+    */
+   static void setSystemProperty(final String key, final String value)
+   {
+      AccessController.doPrivileged(new PrivilegedAction<Void>()
+      {
+         public Void run()
+         {
+            System.setProperty(key, value);
+            return null;
+         }
+      });
+   }
+
+   /**
+    * Obtains the system property with the specified key
+    * 
+    * @param key
+    * @return
+    * @throws IllegalArgumentException If the key is null
+    */
+   static String getSystemProperty(final String key) throws IllegalArgumentException
+   {
+      // Precondition check
+      if (key == null)
+      {
+         throw new IllegalArgumentException("key was null");
+      }
+
+      // Get sysprop
+      return AccessController.doPrivileged(new PrivilegedAction<String>()
+      {
+         public String run()
+         {
+            return System.getProperty(key);
+         }
+      });
+   }
+
+   /**
+    * Obtains the Thread Context ClassLoader
+    */
+   static ClassLoader getThreadContextClassLoader()
+   {
+      return AccessController.doPrivileged(new PrivilegedAction<ClassLoader>()
+      {
+         public ClassLoader run()
+         {
+            return Thread.currentThread().getContextClassLoader();
+         }
+      });
+   }
+
+   /**
+    * Sets the specified CL upon the current Thread's Context 
+    * 
+    * @param cl
+    * @throws IllegalArgumentException If the CL was null
+    */
+   static void setThreadContextClassLoader(final ClassLoader cl) throws IllegalArgumentException
+   {
+      if (cl == null)
+      {
+         throw new IllegalArgumentException("ClassLoader was null");
+      }
+
+      AccessController.doPrivileged(new PrivilegedAction<Void>()
+      {
+         public Void run()
+         {
+            Thread.currentThread().setContextClassLoader(cl);
+            return null;
+         };
+      });
+   }
+
+   /**
+    * Adds the specified shutdown hook
+    * 
+    * @param shutdownHook
+    */
+   static void addShutdownHook(final Thread shutdownHook)
+   {
+      AccessController.doPrivileged(new PrivilegedAction<Void>()
+      {
+         public Void run()
+         {
+            Runtime.getRuntime().addShutdownHook(shutdownHook);
+            return null;
+         }
+      });
+
+   }
+}

Added: projects/embedded/trunk/testsuite/src/test/java/org/jboss/ServerTestCase.java
===================================================================
--- projects/embedded/trunk/testsuite/src/test/java/org/jboss/ServerTestCase.java	                        (rev 0)
+++ projects/embedded/trunk/testsuite/src/test/java/org/jboss/ServerTestCase.java	2009-06-12 08:10:30 UTC (rev 90117)
@@ -0,0 +1,223 @@
+/*
+ * 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;
+
+import java.io.File;
+import java.net.URL;
+import java.net.URLClassLoader;
+import java.util.HashSet;
+import java.util.Set;
+
+import junit.framework.TestCase;
+
+import org.jboss.bootstrap.spi.as.config.JBossASConfigurationInitializer;
+import org.jboss.bootstrap.spi.as.config.JBossASServerConfig;
+import org.jboss.bootstrap.spi.factory.ServerFactory;
+import org.jboss.bootstrap.spi.lifecycle.LifecycleState;
+import org.jboss.bootstrap.spi.server.Server;
+import org.junit.Test;
+
+/**
+ * ServerUnitTestCase
+ * 
+ * Don't even begin to consider this a real test :D
+ * It's essentially all the logic of what Embedded Core will
+ * provide in one unified place.
+ * 
+ * This is the initial prototype for Embedded AS to run 
+ * with a minimal AS Dependency Set upon the Application
+ * ClassLoader.  The deps are defined by the Embedded assembly,
+ * which closely matches run.jar in the traditional
+ * AS setup.
+ * 
+ * Most of the logic in this class has been pulled from AS Main.
+ * 
+ * We also have a series of nasty test-only hacks here until
+ * everything's past the prototyping phase and in some fully-working
+ * order.
+ *
+ * @author <a href="mailto:andrew.rubinger at jboss.org">ALR</a>
+ * @version $Revision: $
+ */
+public class ServerTestCase
+{
+
+   //-------------------------------------------------------------------------------||
+   // Class Members ----------------------------------------------------------------||
+   //-------------------------------------------------------------------------------||
+
+   /**
+    * The server instance
+    */
+   private static Server<?, ?> server;
+
+   private static final String DEFAULT_AS_SERVER_IMPL_CLASS_NAME = "org.jboss.bootstrap.impl.as.server.JBossASServerImpl";
+
+   @Deprecated
+   //FIXME Hack
+   private static final String HARDCODED_JBOSS_HOME = "/home/alrubinger/business/jboss/wc/jbossas/branches/Branch_5_x/build/output/jboss-5.2.0.Beta/";
+
+   /**
+    * Stupid ol' boot library list
+    */
+   @Deprecated
+   //FIXME We need to have the endorsed libs here?  Why not accepted from java.endorsed.dirs?
+   private static final String[] DEFAULT_BOOT_LIBRARY_LIST =
+   {
+         // Concurrent
+         "concurrent.jar",
+         // Logging
+         "log4j-boot.jar",
+         "jboss-logging-spi.jar",
+         "jboss-logging-log4j.jar",
+         "jboss-logging-jdk.jar",
+         "jboss-logmanager.jar",
+         "jboss-logbridge.jar",
+         // Common jars
+         "jboss-common-core.jar",
+         "jboss-xml-binding.jar",
+         // Bootstrap
+         "jboss-bootstrap-spi.jar", "jboss-bootstrap-spi-as.jar", "jboss-bootstrap-spi-mc.jar",
+         "jboss-bootstrap-impl-base.jar",
+         "jboss-bootstrap-impl-as.jar",
+         "jboss-bootstrap-impl-mc.jar",
+         // Microcontainer
+         "javassist.jar", "jboss-reflect.jar", "jboss-mdr.jar", "jboss-dependency.jar", "jboss-kernel.jar",
+         "jboss-metatype.jar",
+         "jboss-managed.jar",
+         // Fixme ClassLoading
+         "jboss-vfs.jar", "jboss-classloading-spi.jar", "jboss-classloader.jar", "jboss-classloading.jar",
+         "jboss-classloading-vfs.jar",
+         // Fixme aop
+         "jboss-aop.jar", "jboss-aop-mc-int.jar", "trove.jar",
+         // Endorsed
+         "endorsed/jaxb-api.jar", "endorsed/xercesImpl.jar", "endorsed/activation.jar", "endorsed/jaxb-api.jar",
+         "endorsed/resolver.jar", "endorsed/serializer.jar", "endorsed/stax-api.jar", "endorsed/xalan.jar"};
+
+   //-------------------------------------------------------------------------------||
+   // Tests ------------------------------------------------------------------------||
+   //-------------------------------------------------------------------------------||
+
+   /**
+    * Ensures that the server reports as running
+    */
+   @Test
+   public void testServerStart() throws Throwable
+   {
+      System.setProperty("xb.builder.useUnorderedSequence", Boolean.TRUE.toString());
+      System.setProperty("java.rmi.server.hostname", "localhost");
+
+      final String propKeyJBossasBindAddress = JBossASServerConfig.PROP_KEY_JBOSSAS_BIND_ADDRESS;
+      final String defaultBindAddress = "127.0.0.1";
+      System.setProperty(propKeyJBossasBindAddress, defaultBindAddress);
+
+      // Initialize the JDK logmanager
+      String name = System.getProperty("java.util.logging.manager");
+      if (name == null)
+      {
+         System.setProperty("java.util.logging.manager", "org.jboss.logmanager.LogManager");
+      }
+
+      final String jbossHome = HARDCODED_JBOSS_HOME;
+      final String jbossLib = jbossHome + "lib";
+
+      final Set<URL> urls = new HashSet<URL>();
+
+      for (String filename : DEFAULT_BOOT_LIBRARY_LIST)
+      {
+         final File bootLibFile = new File(jbossLib, filename);
+         if (!bootLibFile.exists())
+         {
+            System.out.println("WARNING: Could not find expected boot lib " + bootLibFile);
+         }
+         final URL bootLibUrl = bootLibFile.toURI().toURL();
+         urls.add(bootLibUrl);
+      }
+
+      /*
+       * Set boot log directory
+       */
+      final String sysPropBootLogDir = "jboss.boot.server.log.dir";
+      final String sysPropLogDir = JBossASServerConfig.PROP_KEY_JBOSSAS_SERVER_LOG_DIR;
+      String serverName = System.getProperty(JBossASServerConfig.PROP_KEY_JBOSSAS_SERVER_NAME);
+      if (serverName == null || serverName.length() == 0)
+      {
+         serverName = JBossASConfigurationInitializer.VALUE_SERVER_NAME_DEFAULT;
+      }
+      final String manualBootLogDir = System.getProperty(sysPropBootLogDir);
+      final String manualLogDir = System.getProperty(sysPropLogDir);
+      // If nothing's been explicitly specified
+      if (manualBootLogDir == null && manualLogDir == null)
+      {
+         // We default it
+         final File jbossHomeFile = new File(jbossHome);
+         final URL jbossHomeUrl = jbossHomeFile.toURI().toURL();
+         final URL serverLog = new URL(jbossHomeUrl, "server/" + serverName + "/log/");
+         final File serverLogFile = new File(serverLog.toURI());
+         final String serverLogString = serverLogFile.getAbsolutePath();
+         System.setProperty(sysPropBootLogDir, serverLogString);
+      }
+      // If we've got a manual log dir, use it
+      else if (manualLogDir != null)
+      {
+         System.setProperty(sysPropBootLogDir, manualLogDir);
+      }
+
+      final URL[] urlArray = urls.toArray(new URL[]
+      {});
+
+      final Thread currentThread = Thread.currentThread();
+      final ClassLoader oldCl = currentThread.getContextClassLoader();
+
+      final ClassLoader loadingCl = new URLClassLoader(urlArray, oldCl);
+
+      // Make Server
+      server = ServerFactory.createServer(DEFAULT_AS_SERVER_IMPL_CLASS_NAME, loadingCl);
+
+      // Get out the default configuration
+      // This cast to object first is to workaround the JDK Bug: http://bugs.sun.com/view_bug.do?bug_id=6548436
+      final Object jdk6Bug6548436Hack = (Object) server.getConfiguration();
+      JBossASServerConfig config = (JBossASServerConfig) jdk6Bug6548436Hack;
+
+      // Set JBOSS_HOME
+      config.jbossHome(jbossHome);
+
+      currentThread.setContextClassLoader(loadingCl);
+      try
+      {
+         // Start
+         server.start();
+
+         final LifecycleState state = server.getState();
+         final LifecycleState expected = LifecycleState.STARTED;
+         TestCase.assertEquals("The server is not reporting as started", expected, state);
+
+         // Shutdown
+         server.shutdown();
+      }
+      finally
+      {
+         currentThread.setContextClassLoader(oldCl);
+      }
+
+   }
+}

Modified: projects/embedded/trunk/testsuite/src/test/resources/log4j.xml
===================================================================
--- projects/embedded/trunk/testsuite/src/test/resources/log4j.xml	2009-06-12 07:44:04 UTC (rev 90116)
+++ projects/embedded/trunk/testsuite/src/test/resources/log4j.xml	2009-06-12 08:10:30 UTC (rev 90117)
@@ -73,6 +73,10 @@
     <priority value="ALL"/>
   </category>
   
+  <category name="org.jboss.bootstrap">
+    <priority value="ALL"/>
+  </category>
+  
   <!-- ======================= -->
   <!-- Setup the Root category -->
   <!-- ======================= -->




More information about the jboss-cvs-commits mailing list