[jboss-cvs] JBoss Messaging SVN: r4056 - in trunk: tests/jms-tests/src/org/jboss/test/messaging/jms and 4 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Tue Apr 15 05:39:18 EDT 2008


Author: jmesnil
Date: 2008-04-15 05:39:18 -0400 (Tue, 15 Apr 2008)
New Revision: 4056

Added:
   trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientCrashTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/CrashClient.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SpawnedVMSupport.java
Removed:
   trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/SerializedClientSupport.java
   trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/crash/ClientCrashTest.java
   trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/crash/CrashClient.java
   trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SerializedClientSupport.java
Modified:
   trunk/src/main/org/jboss/messaging/core/config/impl/ConfigurationImpl.java
   trunk/src/main/org/jboss/messaging/core/config/impl/FileConfiguration.java
   trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientExitTest.java
   trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/GracefulClient.java
   trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/ssl/CoreClientOverSSLTest.java
Log:
* refactored ClientCrashTest to check behaviour at the core level (instead of JMS)
* renamed SerializedClientSupport to SpawnedVMSupport
* added DEFAULT_REMOTING_PORT constant in ConfigurationImpl

Modified: trunk/src/main/org/jboss/messaging/core/config/impl/ConfigurationImpl.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/config/impl/ConfigurationImpl.java	2008-04-15 09:24:10 UTC (rev 4055)
+++ trunk/src/main/org/jboss/messaging/core/config/impl/ConfigurationImpl.java	2008-04-15 09:39:18 UTC (rev 4056)
@@ -43,6 +43,7 @@
 
    public static final String REMOTING_ENABLE_SSL_SYSPROP_KEY = "jbm.remoting.enable.ssl";
 
+   public static final int DEFAULT_REMOTING_PORT = 5400;
    public static final int DEFAULT_KEEP_ALIVE_INTERVAL = 10; // in seconds
    public static final int DEFAULT_KEEP_ALIVE_TIMEOUT = 5; // in seconds
    public static final int DEFAULT_REQRES_TIMEOUT = 5; // in seconds
@@ -95,7 +96,7 @@
    
    protected TransportType transport;
    protected String host;
-   protected int port;
+   protected int port = DEFAULT_REMOTING_PORT;
 
    protected int timeout = DEFAULT_REQRES_TIMEOUT;
    protected int keepAliveInterval = DEFAULT_KEEP_ALIVE_INTERVAL;

Modified: trunk/src/main/org/jboss/messaging/core/config/impl/FileConfiguration.java
===================================================================
--- trunk/src/main/org/jboss/messaging/core/config/impl/FileConfiguration.java	2008-04-15 09:24:10 UTC (rev 4055)
+++ trunk/src/main/org/jboss/messaging/core/config/impl/FileConfiguration.java	2008-04-15 09:39:18 UTC (rev 4056)
@@ -73,7 +73,7 @@
       
       host = getString(e, "remoting-host", "localhost");
 
-      port = getInteger(e, "remoting-bind-address", 5400);
+      port = getInteger(e, "remoting-bind-address", DEFAULT_REMOTING_PORT);
       
       timeout = getInteger(e, "remoting-timeout", 5);
       

Deleted: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/SerializedClientSupport.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/SerializedClientSupport.java	2008-04-15 09:24:10 UTC (rev 4055)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/SerializedClientSupport.java	2008-04-15 09:39:18 UTC (rev 4056)
@@ -1,213 +0,0 @@
-/*
-   * 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.messaging.jms;
-
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static junit.framework.Assert.assertNotSame;
-import static junit.framework.Assert.assertSame;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.ObjectOutputStream;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeoutException;
-
-import javax.jms.ConnectionFactory;
-import javax.jms.Queue;
-
-import org.jboss.messaging.core.logging.Logger;
-
-/**
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- *
- * @version <tt>$Revision$</tt>
- *
- */
-public class SerializedClientSupport
-{
-   // Constants -----------------------------------------------------
-
-   private static final Logger log = Logger.getLogger(SerializedClientSupport.class);
-
-   // Attributes ----------------------------------------------------
-
-   // Static --------------------------------------------------------
-
-   public static Process spawnVM(String className, String... args)
-         throws Exception
-   {
-      StringBuffer sb = new StringBuffer();
-
-      sb.append("java").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"))
-      {
-         sb.append("-cp").append(" ").append(classPath).append(" ");
-      } else
-      {
-         sb.append("-cp").append(" \"").append(classPath).append("\" ");
-      }
-
-      sb.append(className).append(' ');
-
-      for (int i = 0; i < args.length; i++)
-      {
-         sb.append(args[i]).append(' ');
-      }
-
-      String commandLine = sb.toString();
-
-      log.trace("command line: " + commandLine);
-
-      Process process = Runtime.getRuntime().exec(commandLine);
-
-      log.trace("process: " + process);
-
-      ProcessLogger outputLogger = new ProcessLogger(process.getInputStream(),
-            className);
-      outputLogger.start();
-
-      return process;
-   }
-
-   public static File writeToFile(String fileName, ConnectionFactory cf,
-         Queue queue) throws Exception
-   {
-      String moduleOutput = System.getProperty("java.io.tmpdir");
-      if (moduleOutput == null)
-      {
-         throw new Exception("Can't find 'module.output'");
-      }
-      File dir = new File(moduleOutput);
-
-      if (!dir.isDirectory() || !dir.canWrite())
-      {
-         throw new Exception(dir + " is either not a directory or not writable");
-      }
-
-      File file = new File(dir, fileName);
-
-      ObjectOutputStream oos = new ObjectOutputStream(
-            new FileOutputStream(file));
-      oos.writeObject(cf);
-      oos.writeObject(queue);
-      oos.flush();
-      oos.close();
-
-      return file;
-   }
-
-   /**
-    * 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
-   {
-      ScheduledExecutorService executor = Executors
-            .newSingleThreadScheduledExecutor();
-      Future<Integer> future = executor.submit(new Callable<Integer>()
-      {
-
-         public Integer call() throws Exception
-         {
-            p.waitFor();
-            return p.exitValue();
-         }
-      });
-      try
-      {
-         int exitValue = future.get(10, SECONDS);
-         if (sameValue)
-         {
-            assertSame(value, exitValue);
-         } else
-         {
-            assertNotSame(value, exitValue);
-         }
-      } finally
-      {
-         p.destroy();
-      }
-   }
-
-   /**
-    * Redirect the input stream to a logger (as debug logs)
-    */
-   static class ProcessLogger extends Thread
-   {
-      InputStream is;
-      Logger processLogger;
-
-      ProcessLogger(InputStream is, String className)
-            throws ClassNotFoundException
-      {
-         this.is = is;
-         this.processLogger = Logger.getLogger(Class.forName(className));
-         setDaemon(true);
-      }
-
-      public void run()
-      {
-         try
-         {
-            InputStreamReader isr = new InputStreamReader(is);
-            BufferedReader br = new BufferedReader(isr);
-            String line = null;
-            while ((line = br.readLine()) != null)
-               processLogger.debug(line);
-         } catch (IOException ioe)
-         {
-            ioe.printStackTrace();
-         }
-      }
-   }
-
-   // Constructors --------------------------------------------------
-
-   // Public --------------------------------------------------------
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-
-}

Deleted: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/crash/ClientCrashTest.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/crash/ClientCrashTest.java	2008-04-15 09:24:10 UTC (rev 4055)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/crash/ClientCrashTest.java	2008-04-15 09:39:18 UTC (rev 4056)
@@ -1,190 +0,0 @@
-/*
-  * 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.messaging.jms.crash;
-
-import java.io.File;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-import javax.jms.TextMessage;
-import javax.naming.InitialContext;
-
-import org.jboss.messaging.core.logging.Logger;
-import org.jboss.messaging.core.server.ConnectionManager;
-import org.jboss.test.messaging.JBMServerTestCase;
-import org.jboss.test.messaging.jms.SerializedClientSupport;
-
-
-/**
- * A test that makes sure that a Messaging server cleans up the associated
- * resources when one of its client crashes.
- * 
- * @author <a href="tim.fox at jboss.com">Tim Fox</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * 
- * @version <tt>$Revision$</tt>
- * 
- */
-public class ClientCrashTest extends JBMServerTestCase
-{
-   // Constants -----------------------------------------------------
-
-   public static final String SERIALIZED_CF_FILE_NAME = "ClientCrashTest_CFandQueue.ser";
-   public static final String MESSAGE_TEXT_FROM_SERVER = "ClientCrashTest from server";
-   public static final String MESSAGE_TEXT_FROM_CLIENT = "ClientCrashTest from client";
-
-   // Static --------------------------------------------------------
-
-   private static final Logger log = Logger.getLogger(ClientCrashTest.class);
-
-   // Attributes ----------------------------------------------------
-
-   private File serialized;
-   private ConnectionFactory cf;
-   private Queue queue;
-
-   // Constructors --------------------------------------------------
-
-   public ClientCrashTest(String name)
-   {
-      super(name);
-   }
-
-   // Public --------------------------------------------------------
-
-   public void testCrashClientWithOneConnection() throws Exception
-   {
-      crashClient(1);
-   }
-
-   public void testCrashClientWithTwoConnections() throws Exception
-   {
-      crashClient(2);
-   }
-
-   public void crashClient(int numberOfConnectionsOnTheClient) throws Exception
-   {
-      Connection conn = null;
-
-      try
-      {
-         assertActiveConnections(0);
-
-         // spawn a JVM that creates a JMS client, which waits to receive a test
-         // message
-         Process p = SerializedClientSupport.spawnVM(CrashClient.class
-               .getName(), new String[] { serialized.getAbsolutePath(),
-               Integer.toString(numberOfConnectionsOnTheClient) });
-
-         // send the message to the queue
-         conn = cf.createConnection();
-         conn.start();
-         Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-         MessageProducer producer = sess.createProducer(queue);
-         MessageConsumer consumer = sess.createConsumer(queue);
-
-         TextMessage messageFromClient = (TextMessage) consumer.receive(5000);
-         assertNotNull("no message received", messageFromClient);
-         assertEquals(MESSAGE_TEXT_FROM_CLIENT, messageFromClient.getText());
-
-         // 1 local connection to the server
-         // + 1 per connection to the client
-         assertActiveConnections(1 + numberOfConnectionsOnTheClient);
-
-         producer.send(sess.createTextMessage(MESSAGE_TEXT_FROM_SERVER));
-
-         log.info("waiting for the client VM to crash ...");
-         p.waitFor();
-
-         assertEquals(9, p.exitValue());
-
-         Thread.sleep(2000);
-         // the crash must have been detected and the client resources cleaned
-         // up only the local connection remains
-         assertActiveConnections(1);
-
-         conn.close();
-
-         assertActiveConnections(0);
-      } finally
-      {
-         try
-         {
-            if (conn != null)
-               conn.close();
-         } catch (Throwable ignored)
-         {
-            log.warn("Exception ignored:" + ignored.toString(), ignored);
-         }
-      }
-   }
-
-   // Package protected ---------------------------------------------
-
-   @Override
-   protected void setUp() throws Exception
-   {
-      super.setUp();
-
-      createQueue("Queue");
-
-      InitialContext ic = getInitialContext();
-      cf = (ConnectionFactory) ic.lookup("/ConnectionFactory");
-      queue = (Queue) ic.lookup("/queue/Queue");
-
-      serialized = SerializedClientSupport.writeToFile(SERIALIZED_CF_FILE_NAME,
-            cf, queue);
-   }
-
-   @Override
-   protected void tearDown() throws Exception
-   {      
-      removeAllMessages("Queue", true);
-      servers.get(0).destroyQueue("Queue", "/queue/Queue");
-
-      if (serialized != null)
-      {
-         serialized.delete();
-      }
-
-      super.tearDown();
-   }
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   private static void assertActiveConnections(int expectedActiveConnections)
-         throws Exception
-   {
-      ConnectionManager cm = servers.get(0).getMessagingServer()
-            .getConnectionManager();
-      assertEquals(expectedActiveConnections, cm.getActiveConnections().size());
-   }
-
-   // Inner classes -------------------------------------------------
-
-}

Deleted: trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/crash/CrashClient.java
===================================================================
--- trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/crash/CrashClient.java	2008-04-15 09:24:10 UTC (rev 4055)
+++ trunk/tests/jms-tests/src/org/jboss/test/messaging/jms/crash/CrashClient.java	2008-04-15 09:39:18 UTC (rev 4056)
@@ -1,107 +0,0 @@
-/*
-* 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.messaging.jms.crash;
-
-import java.io.FileInputStream;
-import java.io.ObjectInputStream;
-
-import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
-import javax.jms.MessageConsumer;
-import javax.jms.MessageProducer;
-import javax.jms.Queue;
-import javax.jms.Session;
-
-
-/**
- * Code to be run in an external VM, via main().
- * 
- * This client will open a connection, receive a message and crash.
- *
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * 
- * @version <tt>$Revision$</tt>
- */
-public class CrashClient
-{
-   // Constants ------------------------------------------------------------------------------------
-
-   // Static ---------------------------------------------------------------------------------------
-
-   public static void main(String[] args) throws Exception
-   {
-
-      String serializedFileName = args[0];
-      int numberOfConnections = Integer.parseInt(args[1]);
-
-      // we don't want to mess with JNDI, read the connection factory and the queue from their
-      // serialized format, from disk
-      ObjectInputStream ois =
-         new ObjectInputStream(new FileInputStream(serializedFileName));
-      ConnectionFactory cf =(ConnectionFactory)ois.readObject();
-      Queue queue = (Queue)ois.readObject();
-
-      ois.close();
-      
-      // create one connection which is used
-      Connection conn = cf.createConnection();
-      Session sess = conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
-      MessageConsumer cons = sess.createConsumer(queue);
-      MessageProducer prod = sess.createProducer(queue);
-
-      if (numberOfConnections > 1)
-      {
-         // create (num - 1) unused connections
-         for (int i = 0; i < numberOfConnections - 1; i++)
-         {
-            cf.createConnection();         
-         }
-      }
-      
-      prod.send(sess.createTextMessage(ClientCrashTest.MESSAGE_TEXT_FROM_CLIENT));
-
-      
-      conn.start();
-      cons.receive(5000);
-      
-      // crash
-      System.exit(9);
-   }
-
-   // Attributes -----------------------------------------------------------------------------------
-
-   // Constructors ---------------------------------------------------------------------------------
-
-   // Command implementation -----------------------------------------------------------------------
-
-   // Public ---------------------------------------------------------------------------------------
-
-   // Package protected ----------------------------------------------------------------------------
-
-   // Protected ------------------------------------------------------------------------------------
-
-   // Private --------------------------------------------------------------------------------------
-
-   // Inner classes --------------------------------------------------------------------------------
-
-}

Added: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientCrashTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientCrashTest.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientCrashTest.java	2008-04-15 09:39:18 UTC (rev 4056)
@@ -0,0 +1,191 @@
+/*
+ * 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.messaging.tests.integration.core.remoting.impl;
+
+import static org.jboss.messaging.core.remoting.TransportType.TCP;
+import junit.framework.TestCase;
+
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.Message;
+import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.server.ConnectionManager;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.tests.unit.core.remoting.impl.ConfigurationHelper;
+import org.jboss.messaging.tests.unit.core.util.SpawnedVMSupport;
+
+/**
+ * A test that makes sure that a Messaging server cleans up the associated
+ * resources when one of its client crashes.
+ * 
+ * @author <a href="tim.fox at jboss.com">Tim Fox</a>
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision: 4032 $</tt>
+ * 
+ */
+public class ClientCrashTest extends TestCase
+{
+   // Constants -----------------------------------------------------
+
+   public static final String QUEUE = "ClientCrashTestQueue";
+   public static final String MESSAGE_TEXT_FROM_SERVER = "ClientCrashTest from server";
+   public static final String MESSAGE_TEXT_FROM_CLIENT = "ClientCrashTest from client";
+
+   // Static --------------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(ClientCrashTest.class);
+
+   // Attributes ----------------------------------------------------
+
+   private MessagingServer server;
+   private ClientConnectionFactory cf;
+
+   // Constructors --------------------------------------------------
+
+   public ClientCrashTest(String name)
+   {
+      super(name);
+   }
+
+   // Public --------------------------------------------------------
+
+   public void testCrashClientWithOneConnection() throws Exception
+   {
+      crashClient(1);
+   }
+
+   public void testCrashClientWithTwoConnections() throws Exception
+   {
+      crashClient(2);
+   }
+
+   public void crashClient(int numberOfConnectionsOnTheClient) throws Exception
+   {
+      ClientConnection connection = null;
+
+      try
+      {
+         assertActiveConnections(0);
+
+         // spawn a JVM that creates a JMS client, which waits to receive a test
+         // message
+         Process p = SpawnedVMSupport.spawnVM(CrashClient.class
+               .getName(), new String[] { Integer
+               .toString(numberOfConnectionsOnTheClient) });
+
+         connection = cf.createConnection();
+         ClientSession session = connection.createClientSession(false, true,
+               true, -1, false, false);
+         session.createQueue(QUEUE, QUEUE, null, false, false);
+         ClientConsumer consumer = session.createConsumer(QUEUE, null, false, false, true);
+         ClientProducer producer = session.createProducer(QUEUE);
+
+         connection.start();
+
+         // send the message to the queue
+         Message messageFromClient = consumer.receive(5000);
+         assertNotNull("no message received", messageFromClient);
+         assertEquals(MESSAGE_TEXT_FROM_CLIENT, new String(messageFromClient
+               .getPayload()));
+
+         // 1 local connection to the server
+         // + 1 per connection to the client
+         assertActiveConnections(1 + numberOfConnectionsOnTheClient);
+
+         MessageImpl message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
+               System.currentTimeMillis(), (byte) 1);
+         message
+               .setPayload(ClientCrashTest.MESSAGE_TEXT_FROM_SERVER.getBytes());
+         producer.send(message);
+
+         log.info("waiting for the client VM to crash ...");
+         p.waitFor();
+
+         assertEquals(9, p.exitValue());
+
+         Thread.sleep(2000);
+         // the crash must have been detected and the client resources cleaned
+         // up only the local connection remains
+         assertActiveConnections(1);
+
+         connection.close();
+
+         assertActiveConnections(0);
+      } finally
+      {
+         try
+         {
+            if (connection != null)
+               connection.close();
+         } catch (Throwable ignored)
+         {
+            log.warn("Exception ignored:" + ignored.toString(), ignored);
+         }
+      }
+   }
+
+   // Package protected ---------------------------------------------
+
+   @Override
+   protected void setUp() throws Exception
+   {
+      super.setUp();
+
+      ConfigurationImpl config = ConfigurationHelper.newConfiguration(TCP,
+            "localhost", ConfigurationImpl.DEFAULT_REMOTING_PORT);
+      server = new MessagingServerImpl(config);
+      server.start();
+
+      cf = new ClientConnectionFactoryImpl(0, config, server.getVersion());
+   }
+
+   @Override
+   protected void tearDown() throws Exception
+   {
+      server.stop();
+
+      super.tearDown();
+   }
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   private void assertActiveConnections(int expectedActiveConnections)
+         throws Exception
+   {
+      ConnectionManager cm = server.getConnectionManager();
+      assertEquals(expectedActiveConnections, cm.getActiveConnections().size());
+   }
+
+   // Inner classes -------------------------------------------------
+
+}

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientExitTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientExitTest.java	2008-04-15 09:24:10 UTC (rev 4055)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/ClientExitTest.java	2008-04-15 09:39:18 UTC (rev 4056)
@@ -32,10 +32,10 @@
 import org.jboss.messaging.core.config.impl.ConfigurationImpl;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.message.Message;
-import org.jboss.messaging.tests.unit.core.remoting.impl.ConfigurationHelper;
-import org.jboss.messaging.tests.unit.core.util.SerializedClientSupport;
 import org.jboss.messaging.core.server.MessagingServer;
 import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import org.jboss.messaging.tests.unit.core.remoting.impl.ConfigurationHelper;
+import org.jboss.messaging.tests.unit.core.util.SpawnedVMSupport;
 
 /**
  * A test that makes sure that a Messaging client gracefully exists after the last connection is
@@ -76,7 +76,7 @@
    public void testGracefulClientExit() throws Exception
    {
       // spawn a JVM that creates a JMS client, which sends a test message
-      Process p = SerializedClientSupport.spawnVM(GracefulClient.class.getName());
+      Process p = SpawnedVMSupport.spawnVM(GracefulClient.class.getName());
 
       // read the message from the queue
 
@@ -99,7 +99,7 @@
    protected void setUp() throws Exception
    {
       ConfigurationImpl config = ConfigurationHelper.newConfiguration(TCP,
-            "localhost", 9000);
+            "localhost", ConfigurationImpl.DEFAULT_REMOTING_PORT);
       server = new MessagingServerImpl(config);
       server.start();
 

Added: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/CrashClient.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/CrashClient.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/CrashClient.java	2008-04-15 09:39:18 UTC (rev 4056)
@@ -0,0 +1,131 @@
+/*
+* 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.messaging.tests.integration.core.remoting.impl;
+
+import static org.jboss.messaging.core.remoting.TransportType.TCP;
+import static org.jboss.messaging.tests.integration.core.remoting.impl.ClientCrashTest.QUEUE;
+
+import java.util.Arrays;
+
+import org.jboss.messaging.core.client.ClientConnection;
+import org.jboss.messaging.core.client.ClientConnectionFactory;
+import org.jboss.messaging.core.client.ClientConsumer;
+import org.jboss.messaging.core.client.ClientProducer;
+import org.jboss.messaging.core.client.ClientSession;
+import org.jboss.messaging.core.client.impl.ClientConnectionFactoryImpl;
+import org.jboss.messaging.core.config.impl.ConfigurationImpl;
+import org.jboss.messaging.core.logging.Logger;
+import org.jboss.messaging.core.message.impl.MessageImpl;
+import org.jboss.messaging.core.server.MessagingServer;
+import org.jboss.messaging.core.server.impl.MessagingServerImpl;
+import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.tests.unit.core.remoting.impl.ConfigurationHelper;
+
+
+/**
+ * Code to be run in an external VM, via main().
+ * 
+ * This client will open a connection, receive a message and crash.
+ *
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ */
+public class CrashClient
+{
+   // Constants ------------------------------------------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(CrashClient.class);
+
+   // Static ---------------------------------------------------------------------------------------
+
+   public static void main(String[] args) throws Exception
+   {
+      try
+      {
+         log.info("args = " + Arrays.asList(args));
+
+         if (args.length != 1)
+         {
+            log.fatal("unexpected number of args (should be 1)");
+            System.exit(1);
+         }
+
+         int numberOfConnections = Integer.parseInt(args[0]);
+
+         ConfigurationImpl config = ConfigurationHelper.newConfiguration(TCP,
+               "localhost", ConfigurationImpl.DEFAULT_REMOTING_PORT);
+
+         // FIXME there should be another way to get a meaningful Version on the
+         // client side...
+         MessagingServer server = new MessagingServerImpl();
+         ClientConnectionFactory cf = new ClientConnectionFactoryImpl(0, config, server.getVersion());
+         ClientConnection conn = cf.createConnection();
+         ClientSession session = conn.createClientSession(false, true, true, -1, false, false);
+         ClientProducer producer = session.createProducer(QUEUE);
+         ClientConsumer consumer = session.createConsumer(QUEUE, null, false, false, true);
+
+         if (numberOfConnections > 1)
+         {
+            // create (num - 1) unused connections
+            for (int i = 0; i < numberOfConnections - 1; i++)
+            {
+               cf.createConnection();         
+            }
+         }
+         
+         MessageImpl message = new MessageImpl(JBossTextMessage.TYPE, false, 0,
+               System.currentTimeMillis(), (byte) 1);
+         message.setPayload(ClientCrashTest.MESSAGE_TEXT_FROM_CLIENT.getBytes());
+
+         producer.send(message);
+
+         conn.start();
+         consumer.receive(5000);
+         
+         // crash
+         System.exit(9);
+      } catch (Throwable t)
+      {
+         log.error(t.getMessage(), t);
+         System.exit(1);
+      }
+   }
+
+   // Attributes -----------------------------------------------------------------------------------
+
+   // Constructors ---------------------------------------------------------------------------------
+
+   // Command implementation -----------------------------------------------------------------------
+
+   // Public ---------------------------------------------------------------------------------------
+
+   // Package protected ----------------------------------------------------------------------------
+
+   // Protected ------------------------------------------------------------------------------------
+
+   // Private --------------------------------------------------------------------------------------
+
+   // Inner classes --------------------------------------------------------------------------------
+
+}

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/GracefulClient.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/GracefulClient.java	2008-04-15 09:24:10 UTC (rev 4055)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/impl/GracefulClient.java	2008-04-15 09:39:18 UTC (rev 4056)
@@ -33,10 +33,10 @@
 import org.jboss.messaging.core.config.impl.ConfigurationImpl;
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.message.impl.MessageImpl;
-import org.jboss.messaging.tests.unit.core.remoting.impl.ConfigurationHelper;
 import org.jboss.messaging.core.server.MessagingServer;
 import org.jboss.messaging.core.server.impl.MessagingServerImpl;
 import org.jboss.messaging.jms.client.JBossTextMessage;
+import org.jboss.messaging.tests.unit.core.remoting.impl.ConfigurationHelper;
 
 /**
  * Code to be run in an external VM, via main().
@@ -61,7 +61,7 @@
       try
       {
          ConfigurationImpl config = ConfigurationHelper.newConfiguration(TCP,
-               "localhost", 9000);
+               "localhost", ConfigurationImpl.DEFAULT_REMOTING_PORT);
 
          // FIXME there should be another way to get a meaningful Version on the
          // client side...

Modified: trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/ssl/CoreClientOverSSLTest.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/ssl/CoreClientOverSSLTest.java	2008-04-15 09:24:10 UTC (rev 4055)
+++ trunk/tests/src/org/jboss/messaging/tests/integration/core/remoting/ssl/CoreClientOverSSLTest.java	2008-04-15 09:39:18 UTC (rev 4056)
@@ -34,7 +34,7 @@
 import org.jboss.messaging.core.logging.Logger;
 import org.jboss.messaging.core.message.Message;
 import org.jboss.messaging.tests.unit.core.remoting.impl.ConfigurationHelper;
-import org.jboss.messaging.tests.unit.core.util.SerializedClientSupport;
+import org.jboss.messaging.tests.unit.core.util.SpawnedVMSupport;
 import org.jboss.messaging.core.server.MessagingServer;
 import org.jboss.messaging.core.server.impl.MessagingServerImpl;
 
@@ -76,7 +76,7 @@
 
    public void testSSL() throws Exception
    {
-      final Process p = SerializedClientSupport.spawnVM(CoreClientOverSSL.class
+      final Process p = SpawnedVMSupport.spawnVM(CoreClientOverSSL.class
             .getName(), Boolean.TRUE.toString(), "messaging.keystore",
             "secureexample");
 
@@ -85,12 +85,12 @@
       assertEquals(MESSAGE_TEXT_FROM_CLIENT, new String(m.getPayload()));
 
       log.info("waiting for the client VM to exit ...");
-      SerializedClientSupport.assertProcessExits(true, 0, p);
+      SpawnedVMSupport.assertProcessExits(true, 0, p);
    }
 
    public void testSSLWithIncorrectKeyStorePassword() throws Exception
    {
-      Process p = SerializedClientSupport.spawnVM(CoreClientOverSSL.class
+      Process p = SpawnedVMSupport.spawnVM(CoreClientOverSSL.class
             .getName(), Boolean.TRUE.toString(), "messaging.keystore",
             "incorrectKeyStorePassword");
 
@@ -98,19 +98,19 @@
       assertNull(m);
 
       log.info("waiting for the client VM to exit ...");
-      SerializedClientSupport.assertProcessExits(false, 0, p);
+      SpawnedVMSupport.assertProcessExits(false, 0, p);
    }
 
    public void testPlainConnectionToSSLEndpoint() throws Exception
    {
-      Process p = SerializedClientSupport.spawnVM(CoreClientOverSSL.class
+      Process p = SpawnedVMSupport.spawnVM(CoreClientOverSSL.class
             .getName(), FALSE.toString(), null, null);
 
       Message m = consumer.receive(5000);
       assertNull(m);
 
       log.info("waiting for the client VM to exit ...");
-      SerializedClientSupport.assertProcessExits(false, 0, p);
+      SpawnedVMSupport.assertProcessExits(false, 0, p);
    }
 
    // Package protected ---------------------------------------------

Deleted: trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SerializedClientSupport.java
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SerializedClientSupport.java	2008-04-15 09:24:10 UTC (rev 4055)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SerializedClientSupport.java	2008-04-15 09:39:18 UTC (rev 4056)
@@ -1,198 +0,0 @@
-/*
- * JBoss, Home of Professional Open Source
- *
- * Distributable under LGPL license.
- * See terms of license at gnu.org.
- */
-package org.jboss.messaging.tests.unit.core.util;
-
-import static java.util.concurrent.TimeUnit.SECONDS;
-import static junit.framework.Assert.assertNotSame;
-import static junit.framework.Assert.assertSame;
-
-import java.io.BufferedReader;
-import java.io.File;
-import java.io.FileOutputStream;
-import java.io.IOException;
-import java.io.InputStream;
-import java.io.InputStreamReader;
-import java.io.ObjectOutputStream;
-import java.util.concurrent.Callable;
-import java.util.concurrent.ExecutionException;
-import java.util.concurrent.Executors;
-import java.util.concurrent.Future;
-import java.util.concurrent.ScheduledExecutorService;
-import java.util.concurrent.TimeoutException;
-
-import javax.jms.ConnectionFactory;
-import javax.jms.Queue;
-
-import org.jboss.messaging.core.logging.Logger;
-
-/**
- * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
- * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
- * 
- * @version <tt>$Revision$</tt>
- * 
- */
-public class SerializedClientSupport
-{
-   // Constants -----------------------------------------------------
-
-   private static final Logger log = Logger.getLogger(SerializedClientSupport.class);
-
-   // Attributes ----------------------------------------------------
-
-   // Static --------------------------------------------------------
-
-   public static Process spawnVM(String className, String... args)
-         throws Exception
-   {
-      StringBuffer sb = new StringBuffer();
-
-      sb.append("java").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"))
-      {
-         sb.append("-cp").append(" ").append(classPath).append(" ");
-      } else
-      {
-         sb.append("-cp").append(" \"").append(classPath).append("\" ");
-      }
-
-      sb.append(className).append(' ');
-
-      for (int i = 0; i < args.length; i++)
-      {
-         sb.append(args[i]).append(' ');
-      }
-
-      String commandLine = sb.toString();
-
-      log.trace("command line: " + commandLine);
-
-      Process process = Runtime.getRuntime().exec(commandLine);
-
-      log.trace("process: " + process);
-
-      ProcessLogger outputLogger = new ProcessLogger(process.getInputStream(),
-            className);
-      outputLogger.start();
-
-      return process;
-   }
-
-   public static File writeToFile(String fileName, ConnectionFactory cf,
-         Queue queue) throws Exception
-   {
-      String moduleOutput = System.getProperty("java.io.tmpdir");
-      if (moduleOutput == null)
-      {
-         throw new Exception("Can't find 'module.output'");
-      }
-      File dir = new File(moduleOutput);
-
-      if (!dir.isDirectory() || !dir.canWrite())
-      {
-         throw new Exception(dir + " is either not a directory or not writable");
-      }
-
-      File file = new File(dir, fileName);
-
-      ObjectOutputStream oos = new ObjectOutputStream(
-            new FileOutputStream(file));
-      oos.writeObject(cf);
-      oos.writeObject(queue);
-      oos.flush();
-      oos.close();
-
-      return file;
-   }
-
-   /**
-    * 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
-   {
-      ScheduledExecutorService executor = Executors
-            .newSingleThreadScheduledExecutor();
-      Future<Integer> future = executor.submit(new Callable<Integer>()
-      {
-
-         public Integer call() throws Exception
-         {
-            p.waitFor();
-            return p.exitValue();
-         }
-      });
-      try
-      {
-         int exitValue = future.get(10, SECONDS);
-         if (sameValue)
-         {
-            assertSame(value, exitValue);
-         } else
-         {
-            assertNotSame(value, exitValue);
-         }
-      } finally
-      {
-         p.destroy();
-      }
-   }
-
-   /**
-    * Redirect the input stream to a logger (as debug logs)
-    */
-   static class ProcessLogger extends Thread
-   {
-      InputStream is;
-      Logger processLogger;
-
-      ProcessLogger(InputStream is, String className)
-            throws ClassNotFoundException
-      {
-         this.is = is;
-         this.processLogger = Logger.getLogger(Class.forName(className));
-         setDaemon(true);
-      }
-
-      public void run()
-      {
-         try
-         {
-            InputStreamReader isr = new InputStreamReader(is);
-            BufferedReader br = new BufferedReader(isr);
-            String line = null;
-            while ((line = br.readLine()) != null)
-               processLogger.debug(line);
-         } catch (IOException ioe)
-         {
-            ioe.printStackTrace();
-         }
-      }
-   }
-   
-   // Constructors --------------------------------------------------
-
-   // Public --------------------------------------------------------
-
-   // Package protected ---------------------------------------------
-
-   // Protected -----------------------------------------------------
-
-   // Private -------------------------------------------------------
-
-   // Inner classes -------------------------------------------------
-
-}

Copied: trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SpawnedVMSupport.java (from rev 4055, trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SerializedClientSupport.java)
===================================================================
--- trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SpawnedVMSupport.java	                        (rev 0)
+++ trunk/tests/src/org/jboss/messaging/tests/unit/core/util/SpawnedVMSupport.java	2008-04-15 09:39:18 UTC (rev 4056)
@@ -0,0 +1,165 @@
+/*
+ * JBoss, Home of Professional Open Source
+ *
+ * Distributable under LGPL license.
+ * See terms of license at gnu.org.
+ */
+package org.jboss.messaging.tests.unit.core.util;
+
+import static java.util.concurrent.TimeUnit.SECONDS;
+import static junit.framework.Assert.assertNotSame;
+import static junit.framework.Assert.assertSame;
+
+import java.io.BufferedReader;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.InputStreamReader;
+import java.util.concurrent.Callable;
+import java.util.concurrent.ExecutionException;
+import java.util.concurrent.Executors;
+import java.util.concurrent.Future;
+import java.util.concurrent.ScheduledExecutorService;
+import java.util.concurrent.TimeoutException;
+
+import org.jboss.messaging.core.logging.Logger;
+
+/**
+ * @author <a href="mailto:ovidiu at feodorov.com">Ovidiu Feodorov</a>
+ * @author <a href="mailto:jmesnil at redhat.com">Jeff Mesnil</a>
+ * 
+ * @version <tt>$Revision$</tt>
+ * 
+ */
+public class SpawnedVMSupport
+{
+   // Constants -----------------------------------------------------
+
+   private static final Logger log = Logger.getLogger(SpawnedVMSupport.class);
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   public static Process spawnVM(String className, String... args)
+         throws Exception
+   {
+      StringBuffer sb = new StringBuffer();
+
+      sb.append("java").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"))
+      {
+         sb.append("-cp").append(" ").append(classPath).append(" ");
+      } else
+      {
+         sb.append("-cp").append(" \"").append(classPath).append("\" ");
+      }
+
+      sb.append(className).append(' ');
+
+      for (int i = 0; i < args.length; i++)
+      {
+         sb.append(args[i]).append(' ');
+      }
+
+      String commandLine = sb.toString();
+
+      log.trace("command line: " + commandLine);
+
+      Process process = Runtime.getRuntime().exec(commandLine);
+
+      log.trace("process: " + process);
+
+      ProcessLogger outputLogger = new ProcessLogger(process.getInputStream(),
+            className);
+      outputLogger.start();
+
+      return process;
+   }
+
+   /**
+    * 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
+   {
+      ScheduledExecutorService executor = Executors
+            .newSingleThreadScheduledExecutor();
+      Future<Integer> future = executor.submit(new Callable<Integer>()
+      {
+
+         public Integer call() throws Exception
+         {
+            p.waitFor();
+            return p.exitValue();
+         }
+      });
+      try
+      {
+         int exitValue = future.get(10, SECONDS);
+         if (sameValue)
+         {
+            assertSame(value, exitValue);
+         } else
+         {
+            assertNotSame(value, exitValue);
+         }
+      } finally
+      {
+         p.destroy();
+      }
+   }
+
+   /**
+    * Redirect the input stream to a logger (as debug logs)
+    */
+   static class ProcessLogger extends Thread
+   {
+      InputStream is;
+      Logger processLogger;
+
+      ProcessLogger(InputStream is, String className)
+            throws ClassNotFoundException
+      {
+         this.is = is;
+         this.processLogger = Logger.getLogger(Class.forName(className));
+         setDaemon(true);
+      }
+
+      public void run()
+      {
+         try
+         {
+            InputStreamReader isr = new InputStreamReader(is);
+            BufferedReader br = new BufferedReader(isr);
+            String line = null;
+            while ((line = br.readLine()) != null)
+               processLogger.debug(line);
+         } catch (IOException ioe)
+         {
+            ioe.printStackTrace();
+         }
+      }
+   }
+   
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}




More information about the jboss-cvs-commits mailing list