[jboss-cvs] JBoss Messaging SVN: r6034 - in trunk/tests: src/org/jboss/messaging/tests/integration/security and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Mar 6 17:20:35 EST 2009


Author: clebert.suconic at jboss.com
Date: 2009-03-06 17:20:35 -0500 (Fri, 06 Mar 2009)
New Revision: 6034

Modified:
   trunk/tests/joram-tests/src/org/jboss/test/jms/JBossMessagingAdmin.java
   trunk/tests/src/org/jboss/messaging/tests/integration/security/NettySecurityClientTest.java
   trunk/tests/src/org/jboss/messaging/tests/util/SpawnedVMSupport.java
Log:
Tweak on Log at SpawnedVMSupport

Modified: trunk/tests/joram-tests/src/org/jboss/test/jms/JBossMessagingAdmin.java
===================================================================
--- trunk/tests/joram-tests/src/org/jboss/test/jms/JBossMessagingAdmin.java	2009-03-06 22:17:09 UTC (rev 6033)
+++ trunk/tests/joram-tests/src/org/jboss/test/jms/JBossMessagingAdmin.java	2009-03-06 22:20:35 UTC (rev 6034)
@@ -262,34 +262,7 @@
    {
       serverProcess = SpawnedVMSupport.spawnVM(SpawnedJMSServer.class.getName(), false);
       InputStreamReader isr = new InputStreamReader(serverProcess.getInputStream());
-      
-      InputStreamReader errorStream = new InputStreamReader(serverProcess.getErrorStream());
-      
-      final BufferedReader errorReader = new BufferedReader(errorStream);
-
-      // Reading System.err, so the server won't hang
-      new Thread()
-      {
-         public void run()
-         {
-            try
-            {
-               String line = null;
-               while ((line = errorReader.readLine()) != null)
-               {
-                  // Uncomment this line if you want to see the ErrorOutput 
-                  // System.out.println("JoramServer ErrorOutput: " + line);
-               }
-            }
-            catch (Exception e)
-            {
-               e.printStackTrace();
-            }
-         }
-      }.start();
-      
-      
-      
+     
       final BufferedReader br = new BufferedReader(isr);
       String line = null;
       while ((line = br.readLine()) != null)

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/security/NettySecurityClientTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/security/NettySecurityClientTest.java	2009-03-06 22:17:09 UTC (rev 6033)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/security/NettySecurityClientTest.java	2009-03-06 22:20:35 UTC (rev 6034)
@@ -69,6 +69,7 @@
       doTestProducerConsumerClient(true);
    }
    
+
    // SecurityManagerClientTestBase overrides -----------------------
 
    // Package protected ---------------------------------------------
@@ -130,6 +131,9 @@
             fail("Exception when starting the client: " + line);
          }
       }
+      
+      
+      SpawnedVMSupport.startLogger(SimpleClient.class.getName(), p);
 
       // the client VM should exit by itself. If it doesn't, that means we have a problem
       // and the test will timeout

Modified: trunk/tests/src/org/jboss/messaging/tests/util/SpawnedVMSupport.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/util/SpawnedVMSupport.java	2009-03-06 22:17:09 UTC (rev 6033)
+++ trunk/tests/src/org/jboss/messaging/tests/util/SpawnedVMSupport.java	2009-03-06 22:20:35 UTC (rev 6034)
@@ -18,7 +18,7 @@
  * 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.messaging.tests.util;
 
@@ -56,27 +56,26 @@
    // Attributes ----------------------------------------------------
 
    // Static --------------------------------------------------------
-  
-   public static Process spawnVM(String className, String... args)
-   throws Exception
+
+   public static Process spawnVM(final String className, final String... args) throws Exception
    {
       return spawnVM(className, new String[0], true, args);
    }
 
-   public static Process spawnVM(String className, boolean logOutput, String... args)
-   throws Exception
+   public static Process spawnVM(final String className, final boolean logOutput, final String... args) throws Exception
    {
       return spawnVM(className, new String[0], logOutput, args);
    }
 
-   public static Process spawnVM(String className, String[] vmargs, String... args)
-   throws Exception
+   public static Process spawnVM(final String className, final String[] vmargs, final String... args) throws Exception
    {
       return spawnVM(className, vmargs, true, args);
    }
-   
-   public static Process spawnVM(String className, String[] vmargs, boolean logOutput, String... args)
-   throws Exception
+
+   public static Process spawnVM(final String className,
+                                 final String[] vmargs,
+                                 final boolean logOutput,
+                                 final String... args) throws Exception
    {
       StringBuffer sb = new StringBuffer();
 
@@ -84,32 +83,31 @@
 
       sb.append("-Xms512m -Xmx512m ");
 
-      for (int i = 0; i < vmargs.length; i++)
+      for (String vmarg : vmargs)
       {
-         String vmarg = vmargs[i];
          sb.append(vmarg).append(' ');
       }
 
       String classPath = System.getProperty("java.class.path");
 
       // I guess it'd be simpler to check if the OS is Windows...
-      if (System.getProperty("os.name").equals("Linux")
-               || System.getProperty("os.name").equals("Mac OS X"))
+      if (System.getProperty("os.name").equals("Linux") || System.getProperty("os.name").equals("Mac OS X"))
       {
          sb.append("-cp").append(" ").append(classPath).append(" ");
-      } else
+      }
+      else
       {
          sb.append("-cp").append(" \"").append(classPath).append("\" ");
       }
 
       sb.append("-Djava.library.path=").append(System.getProperty("java.library.path", "./native/bin")).append(" ");
-      
-      //sb.append("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 ");
+
+      // sb.append("-Xrunjdwp:transport=dt_socket,server=y,suspend=y,address=8000 ");
       sb.append(className).append(' ');
 
-      for (int i = 0; i < args.length; i++)
+      for (String arg : args)
       {
-         sb.append(args[i]).append(' ');
+         sb.append(arg).append(' ');
       }
 
       String commandLine = sb.toString();
@@ -122,32 +120,40 @@
 
       if (logOutput)
       {
-         ProcessLogger outputLogger = new ProcessLogger(process.getInputStream(),
-                                                        className);
-         outputLogger.start();
+         startLogger(className, process);
 
-         // Adding a reader to System.err, so the VM won't hang on a System.err.println as identified on this forum thread:
-         // http://www.jboss.org/index.html?module=bb&op=viewtopic&t=151815
-         ProcessLogger errorLogger = new ProcessLogger(process.getErrorStream(),
-                                                        className);
-         errorLogger.start();
       }
-      
+
+      // Adding a reader to System.err, so the VM won't hang on a System.err.println as identified on this forum thread:
+      // http://www.jboss.org/index.html?module=bb&op=viewtopic&t=151815
+      ProcessLogger errorLogger = new ProcessLogger(false, process.getErrorStream(), className);
+      errorLogger.start();
+
       return process;
    }
 
    /**
+    * @param className
+    * @param process
+    * @throws ClassNotFoundException
+    */
+   public static void startLogger(final String className, Process process) throws ClassNotFoundException
+   {
+      ProcessLogger outputLogger = new ProcessLogger(true, process.getInputStream(), className);
+      outputLogger.start();
+   }
+
+   /**
     * Assert that a process exits with the expected value (or not depending if
     * the <code>sameValue</code> is expected or not). The method waits 5
     * seconds for the process to exit, then an Exception is thrown. In any case,
     * the process is destroyed before the method returns.
     */
-   public static void assertProcessExits(boolean sameValue, int value,
-         final Process p) throws InterruptedException, ExecutionException,
-         TimeoutException
+   public static void assertProcessExits(final boolean sameValue, final int value, final Process p) throws InterruptedException,
+                                                                                                   ExecutionException,
+                                                                                                   TimeoutException
    {
-      ScheduledExecutorService executor = Executors
-            .newSingleThreadScheduledExecutor();
+      ScheduledExecutorService executor = Executors.newSingleThreadScheduledExecutor();
       Future<Integer> future = executor.submit(new Callable<Integer>()
       {
 
@@ -163,11 +169,13 @@
          if (sameValue)
          {
             assertSame(value, exitValue);
-         } else
+         }
+         else
          {
             assertNotSame(value, exitValue);
          }
-      } finally
+      }
+      finally
       {
          p.destroy();
       }
@@ -178,17 +186,21 @@
     */
    static class ProcessLogger extends Thread
    {
-      InputStream is;
-      Logger processLogger;
+      private InputStream is;
+      
+      private String className;
 
-      ProcessLogger(InputStream is, String className)
-            throws ClassNotFoundException
+      private final boolean print;
+
+      ProcessLogger(final boolean print, final InputStream is, final String className) throws ClassNotFoundException
       {
          this.is = is;
-         this.processLogger = Logger.getLogger(Class.forName(className));
+         this.print = print;
+         this.className = className;
          setDaemon(true);
       }
 
+      @Override
       public void run()
       {
          try
@@ -197,14 +209,20 @@
             BufferedReader br = new BufferedReader(isr);
             String line = null;
             while ((line = br.readLine()) != null)
-               processLogger.info(line);
-         } catch (IOException ioe)
+            {
+               if (print)
+               {
+                  System.out.println(className + ":" + line);
+               }
+            }
+         }
+         catch (IOException ioe)
          {
             ioe.printStackTrace();
          }
       }
    }
-   
+
    // Constructors --------------------------------------------------
 
    // Public --------------------------------------------------------




More information about the jboss-cvs-commits mailing list