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

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Mon May 3 17:23:14 EDT 2010


Author: scott.stark at jboss.org
Date: 2010-05-03 17:23:14 -0400 (Mon, 03 May 2010)
New Revision: 104400

Added:
   projects/bootstrap/trunk/api/src/test/java/org/
   projects/bootstrap/trunk/api/src/test/java/org/jboss/
   projects/bootstrap/trunk/api/src/test/java/org/jboss/test/
   projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/
   projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/
   projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/
   projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/LaunchMetaData.java
   projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/LaunchTestCase.java
   projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/MainTarget.java
Log:
Tests of launching a java vm from a java process

Added: projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/LaunchMetaData.java
===================================================================
--- projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/LaunchMetaData.java	                        (rev 0)
+++ projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/LaunchMetaData.java	2010-05-03 21:23:14 UTC (rev 104400)
@@ -0,0 +1,170 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.bootstrap.jvm.launch;
+
+import java.io.File;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Map;
+import java.util.Properties;
+
+public class LaunchMetaData
+{
+   String jvmCommand;
+   String[] jvmArgs;
+   String[] classpath;
+   String mainClass;
+   long minMemory;
+   long maxMemory;
+   Map<String, String> env;
+   Properties cmdProps;
+   File runDirectory;
+
+   public LaunchMetaData()
+   {
+      jvmCommand = System.getProperty("java.home") + File.separatorChar + "bin" + File.separatorChar + "java";
+      runDirectory = new File(System.getProperty("user.dir"));
+   }
+
+   public String getJvmCommand()
+   {
+      return jvmCommand;
+   }
+
+   public void setJvmCommand(String jvmCommand)
+   {
+      this.jvmCommand = jvmCommand;
+   }
+
+   public String[] getJvmArgs()
+   {
+      return jvmArgs;
+   }
+
+   public void setJvmArgs(String[] jvmArgs)
+   {
+      this.jvmArgs = jvmArgs;
+   }
+
+   public Map<String, String> getEnv()
+   {
+      return env;
+   }
+
+   public void setEnv(Map<String, String> env)
+   {
+      this.env = env;
+   }
+
+   public long getMinMemory()
+   {
+      return minMemory;
+   }
+
+   public void setMinMemory(long minMemory)
+   {
+      this.minMemory = minMemory;
+   }
+
+   public long getMaxMemory()
+   {
+      return maxMemory;
+   }
+
+   public void setMaxMemory(long maxMemory)
+   {
+      this.maxMemory = maxMemory;
+
+   }
+
+   public Properties getCmdProps()
+   {
+      return cmdProps;
+   }
+
+   public void setCmdProps(Properties cmdProps)
+   {
+      this.cmdProps = cmdProps;
+   }
+
+   public String getMainClass()
+   {
+      return mainClass;
+   }
+
+   public void setMainClass(String mainClass)
+   {
+      this.mainClass = mainClass;
+   }
+
+   public File getRunDirectory()
+   {
+      return runDirectory;
+   }
+
+   public void setRunDirectory(File runDirectory)
+   {
+      this.runDirectory = runDirectory;
+   }
+
+   public String[] getClasspath()
+   {
+      return classpath;
+   }
+
+   public void setClasspath(String[] classpath)
+   {
+      this.classpath = classpath;
+   }
+
+   public String[] getCommandLine()
+   {
+      List<String> cmdLine = new ArrayList<String>();
+      // The jvm command to run
+      cmdLine.add(jvmCommand);
+      // Any jvm args
+      for (String arg : getJvmArgs())
+      {
+         cmdLine.add(arg);
+      }
+      // classpath
+      String[] cp = getClasspath();
+      if (cp != null)
+      {
+         cmdLine.add("-classpath");
+         StringBuffer cps = new StringBuffer("'");
+         for (String p : cp)
+         {
+            cps.append(p);
+            cps.append(File.pathSeparatorChar);
+         }
+         cps.setLength(cps.length() - 1);
+         cps.append("'");
+         cmdLine.add(cps.toString());
+      }
+
+      cmdLine.add(getMainClass());
+      String[] cmd = new String[cmdLine.size()];
+      return cmdLine.toArray(cmd);
+   }
+}

Added: projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/LaunchTestCase.java
===================================================================
--- projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/LaunchTestCase.java	                        (rev 0)
+++ projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/LaunchTestCase.java	2010-05-03 21:23:14 UTC (rev 104400)
@@ -0,0 +1,147 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.bootstrap.jvm.launch;
+
+import java.io.BufferedReader;
+import java.io.InputStreamReader;
+import java.io.File;
+import java.io.IOException;
+import java.io.InputStream;
+import java.lang.ProcessBuilder;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.Map;
+import java.util.Properties;
+
+import static org.junit.Assert.*;
+
+import org.junit.Ignore;
+import org.junit.Test;
+import org.junit.runner.RunWith;
+import org.junit.runners.Parameterized;
+
+/**
+ * Basic tests of launching the jvm from within a java process
+ *
+ * @version $Revision:$
+ * @author scott.stark at jboss.org
+ */
+ at RunWith(Parameterized.class)
+public class LaunchTestCase
+{
+   private boolean mainStarted;
+   private String mainTargetName;
+   private String[] jvmArgs;
+
+   public static class InnerMainTarget
+   {
+      public static void main(String[] args)
+      {
+         MainTarget.main(args);
+      }
+   }
+
+   private int number;
+
+   public LaunchTestCase(String mainTargetName, String[] jvmArgs)
+   {
+      this.mainTargetName = mainTargetName;
+      this.jvmArgs = jvmArgs;
+   }
+
+    @Parameterized.Parameters
+    public static Collection data()
+    {
+      Object[][] data = new Object[][] {
+         { MainTarget.class.getName(), new String[]{"-Xms16m", "-Xmx256m"} },
+         { InnerMainTarget.class.getName(), new String[]{"-Xms16m", "-Xmx256m"} }
+      };
+      return Arrays.asList(data);
+   }
+
+   @Test
+   @Ignore
+   public void testLaunchJVM() throws IOException
+   {
+      System.out.println("---- testLaunchJVM.mainTargetName: "+mainTargetName);
+      Map<String, String> env = System.getenv();
+      System.out.println("---- testLaunchJVM.ENV");
+      for(Map.Entry<String, String> envEntry : env.entrySet())
+      {
+         System.out.print(envEntry.getKey());
+         System.out.print("=");
+         System.out.println(envEntry.getValue());
+      }
+      System.out.println("---- END testLaunchJVM.ENV");
+      System.out.println("---- BEG testLaunchJVM.Properties");
+      Properties props = System.getProperties();
+      for(String name : props.stringPropertyNames())
+      {
+         System.out.print(name);
+         System.out.print("=");
+         System.out.println(props.getProperty(name));
+      }
+      System.out.println("---- END testLaunchJVM.Properties");
+
+      org.jboss.test.bootstrap.jvm.launch.LaunchMetaData launchMD = new org.jboss.test.bootstrap.jvm.launch.LaunchMetaData();
+      launchMD.setJvmArgs(jvmArgs);
+      launchMD.setClasspath(getCallerClasspath());
+      launchMD.setMainClass(mainTargetName);
+
+      System.out.println("---- commandLine: "+ Arrays.asList(launchMD.getCommandLine()));
+      ProcessBuilder pb = new ProcessBuilder(launchMD.getCommandLine());
+      env = pb.environment();
+      Map<String, String> launchMDEnv = launchMD.getEnv();
+      if(launchMDEnv != null)
+      {
+         for(Map.Entry<String, String> envEntry : launchMDEnv.entrySet())
+         {
+            env.put(envEntry.getKey(), envEntry.getValue());
+         }
+      }
+      pb.directory(launchMD.getRunDirectory());
+      pb.redirectErrorStream(true);
+
+      // Launch the process
+      Process p = pb.start();
+      InputStream is = p.getInputStream();
+      InputStreamReader isr = new InputStreamReader(is);
+      BufferedReader bis = new BufferedReader(isr);
+      System.out.println("---- BEG Reading the launched process input...");
+      String line;
+      while((line = bis.readLine()) != null)
+         System.out.println(line);
+      System.out.println("---- END Reading the launched process input...");
+
+      bis.close();
+      int exitValue = p.exitValue();
+      assertEquals("Process exited with 123", 123, exitValue);
+   }
+
+   static String[] getCallerClasspath()
+   {
+      String jcp = System.getProperty("java.class.path");
+      String[] callerJCP = jcp.split(File.pathSeparator);
+      return callerJCP;
+   }
+}

Added: projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/MainTarget.java
===================================================================
--- projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/MainTarget.java	                        (rev 0)
+++ projects/bootstrap/trunk/api/src/test/java/org/jboss/test/bootstrap/jvm/launch/MainTarget.java	2010-05-03 21:23:14 UTC (rev 104400)
@@ -0,0 +1,47 @@
+/*
+ * JBoss, Home of Professional Open Source.
+ * Copyright 2010, 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.bootstrap.jvm.launch;
+
+import java.util.Map;
+
+public class MainTarget
+{
+   public static void main(String[] args)
+   {
+      System.out.println("---- ARGS");
+      for (String arg : args)
+      {
+         System.out.println(arg);
+      }
+      Map<String, String> env = System.getenv();
+      System.out.println("---- ENV");
+      for (Map.Entry<String, String> envEntry : env.entrySet())
+      {
+         System.out.print(envEntry.getKey());
+         System.out.print("=");
+         System.out.println(envEntry.getValue());
+      }
+      System.out.flush();
+      System.exit(123);
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list