Author: rhs
Date: Fri Feb  8 05:50:55 2008
New Revision: 619888

URL: http://svn.apache.org/viewvc?rev=619888&view=rev
Log:
simplied QpidTestCase's interface for running non vm brokers and set up build 
system to run cpp tests easily

Added:
    incubator/qpid/trunk/qpid/java/test-provider.properties   (with props)
Modified:
    
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java
    
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java
    
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java
    
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java
    
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java
    
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
    incubator/qpid/trunk/qpid/java/common.xml
    incubator/qpid/trunk/qpid/java/module.xml

Modified: 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java?rev=619888&r1=619887&r2=619888&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java
 Fri Feb  8 05:50:55 2008
@@ -82,8 +82,9 @@
     protected void tearDown() throws Exception
     {
         _connection.close();
+        super.tearDown();
     }
-                
+
     public void testSimpleReceiveConnection()
     {
         try

Modified: 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java?rev=619888&r1=619887&r2=619888&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java
 Fri Feb  8 05:50:55 2008
@@ -51,7 +51,7 @@
             }
         });
 
-        killBroker();
+        stopBroker();
 
         if (!fired.get(3000))
         {

Modified: 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java?rev=619888&r1=619887&r2=619888&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java
 Fri Feb  8 05:50:55 2008
@@ -98,7 +98,7 @@
 
         if (_count < _expected)
         {
-            wait(1000000000);
+            wait(60000);
         }
 
         if (_count < _expected)

Modified: 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java?rev=619888&r1=619887&r2=619888&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java
 Fri Feb  8 05:50:55 2008
@@ -20,13 +20,12 @@
  */
 package org.apache.qpid.test.unit.close;
 
-import junit.framework.TestCase;
-
 import org.apache.qpid.AMQException;
 import org.apache.qpid.client.AMQConnection;
 import org.apache.qpid.client.message.AbstractJMSMessage;
 import org.apache.qpid.client.transport.TransportConnection;
 import org.apache.qpid.testutil.QpidClientConnection;
+import org.apache.qpid.testutil.QpidTestCase;
 import org.apache.qpid.url.URLSyntaxException;
 
 import org.slf4j.Logger;
@@ -41,7 +40,7 @@
 
 import java.util.concurrent.atomic.AtomicInteger;
 
-public class MessageRequeueTest extends TestCase
+public class MessageRequeueTest extends QpidTestCase
 {
     private static final Logger _logger = 
LoggerFactory.getLogger(MessageRequeueTest.class);
 
@@ -64,7 +63,8 @@
     protected void setUp() throws Exception
     {
         super.setUp();
-         conn = new QpidClientConnection(BROKER);
+
+        conn = new QpidClientConnection(BROKER);
 
         conn.connect();
         // clear queue
@@ -78,7 +78,6 @@
 
     protected void tearDown() throws Exception
     {
-        super.tearDown();
 
         if (!passed) // clean up
         {
@@ -91,6 +90,7 @@
             conn.disconnect();
         }
 
+        super.tearDown();
     }
 
     /**
@@ -125,7 +125,7 @@
             if (messageLog[msgindex] != 0)
             {
                 _logger.error("Received Message(" + msgindex + ":" + 
((AbstractJMSMessage) msg).getDeliveryTag()
-                    + ") more than once.");
+                              + ") more than once.");
             }
 
             if (_logger.isInfoEnabled())
@@ -144,16 +144,18 @@
             msg = consumer.receive(1000);
         }
 
-         _logger.info("consuming done.");
+        _logger.info("consuming done.");
         conn.getSession().commit();
         consumer.close();
-        assertEquals("number of consumed messages does not match initial 
data", (int) numTestMessages, messagesReceived);
 
         int index = 0;
         StringBuilder list = new StringBuilder();
         list.append("Failed to receive:");
         int failed = 0;
 
+        _logger.info("consumed: " + messagesReceived);
+
+        assertEquals("number of consumed messages does not match initial 
data", (int) numTestMessages, messagesReceived);
         // wit 0_10 we can have a delivery tag of 0
         if (conn.isBroker08())
         {
@@ -174,7 +176,7 @@
 
             assertEquals(list.toString(), 0, failed);
         }
-        _logger.info("consumed: " + messagesReceived);
+
         conn.disconnect();
         passed = true;
     }
@@ -208,7 +210,7 @@
         }
         catch (InterruptedException e)
         {
-            fail("Uanble to join to Consumer theads");
+            fail("Unable to join to Consumer theads");
         }
 
         _logger.info("consumer 1 count is " + c1.getCount());

Modified: 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java?rev=619888&r1=619887&r2=619888&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java
 Fri Feb  8 05:50:55 2008
@@ -81,11 +81,8 @@
             String brokerUrl = "amqp://guest:guest@" + virtualHost + 
"?brokerlist='" + brokerlist + "'";
             try
             {
-                AMQConnectionFactory factory = new 
AMQConnectionFactory(brokerUrl);
                 _logger.info("connecting to Qpid :" + brokerUrl);
-                //connection = factory.createConnection();
-                setUp();
-                 connection = getConnection("guest", "guest") ;
+                connection = getConnection("guest", "guest") ;
                 // register exception listener
                 connection.setExceptionListener(this);
 
@@ -112,7 +109,6 @@
             connection.close();
             connected = false;
             _logger.info("disconnected");
-            tearDown();
         }
     }
 

Modified: 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java?rev=619888&r1=619887&r2=619888&view=diff
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
 Fri Feb  8 05:50:55 2008
@@ -21,8 +21,8 @@
 
 import javax.jms.Connection;
 import javax.naming.InitialContext;
-import java.io.BufferedReader;
-import java.io.InputStreamReader;
+import java.io.InputStream;
+import java.io.IOException;
 
 import org.apache.qpid.client.transport.TransportConnection;
 import org.apache.qpid.client.AMQConnection;
@@ -39,117 +39,101 @@
 public class QpidTestCase extends TestCase
 {
 
-    /* this clas logger */
     private static final Logger _logger = 
LoggerFactory.getLogger(QpidTestCase.class);
 
-    /* Test properties */
-    private static final String SHEL = "broker_shel";
-    private static final String BROKER_PATH = "broker_path";
-    private static final String BROKER_PARAM = "broker_param";
-    private static final String BROKER_VERSION  = "broker_version";
-    public static final String BROKER_08 = "08";
-    private static final String BROKER_VM = "vm";
-    private static final String EXT_BROKER = "ext" ;
-    /**
-     * The process where the remote broker is running.
-     */
-    private Process _brokerProcess;
+    // system properties
+    private static final String BROKER = "broker";
+    private static final String BROKER_VERSION  = "broker.version";
+
+    // values
+    private static final String VM = "vm";
+    private static final String EXTERNAL = "external";
+    private static final String VERSION_08 = "0-8";
+    private static final String VERSION_010 = "0-10";
 
-    /* The test property values */
-    // The default broker is an in-VM one
-    private String _shel = BROKER_VM;
-    private String _brokerPath = "";
-    private String _brokerParams = "";
-    private String _brokerVersion = "08" ;
+    private String _broker = System.getProperty(BROKER, VM);
+    private String _brokerVersion = System.getProperty(BROKER_VERSION, 
VERSION_08);
+
+    private Process _brokerProcess;
 
-    /* The broker communication objects */
     private InitialContext _initialContext;
     private AMQConnectionFactory _connectionFactory;
 
-    //--------- JUnit support
-
     protected void setUp() throws Exception
     {
         super.setUp();
-        // get the propeties if they are set
-         if (System.getProperties().containsKey(BROKER_VERSION ))
-        {
-            _brokerVersion = System.getProperties().getProperty(BROKER_VERSION 
);
-        }
-        if (System.getProperties().containsKey(SHEL))
-        {
-            _shel = System.getProperties().getProperty(SHEL);
-        }
-        if (System.getProperties().containsKey(BROKER_PATH))
-        {
-            _brokerPath = System.getProperties().getProperty(BROKER_PATH);
-        }
-        if (System.getProperties().containsKey(BROKER_PARAM))
-        {
-            _brokerParams = System.getProperties().getProperty(BROKER_PARAM);
-        }
-        if (!_shel.equals(BROKER_VM) && ! _shel.equals(EXT_BROKER) )
-        {
-            // start a new broker
-            startBroker();
-        }
-        else if ( ! _shel.equals(EXT_BROKER) )
-        {
-            // create an in_VM broker
-            TransportConnection.createVMBroker(1);
-        }
-        _logger.info("=========================================");
-        _logger.info("broker version " + _brokerVersion + " ==== " + _shel + " 
" + _brokerPath + " " + _brokerParams);
+        startBroker();
     }
 
-    /**
-     * This method _is invoked after each test case.
-     *
-     * @throws Exception
-     */
     protected void tearDown() throws Exception
     {
-          killBroker();
-         super.tearDown();
+        stopBroker();
+        super.tearDown();
     }
 
-    public void killBroker()
+    public void startBroker() throws Exception
     {
-        _logger.info("Kill broker");
-        if (_brokerProcess != null)
+        if (_broker.equals(VM))
         {
-            // destroy the currently running broker
-            _brokerProcess.destroy();
-            _brokerProcess = null;
+            // create an in_VM broker
+            TransportConnection.createVMBroker(1);
         }
-        else   if ( _shel.equals(BROKER_VM))
+        else if (!_broker.equals(EXTERNAL))
         {
-            TransportConnection.killAllVMBrokers();
+            _logger.info("starting broker: " + _broker);
+            ProcessBuilder pb = new ProcessBuilder(_broker.split("\\s+"));
+            pb.redirectErrorStream(true);
+            _brokerProcess = pb.start();
+
+            new Thread()
+            {
+                private InputStream in = _brokerProcess.getInputStream();
+
+                public void run()
+                {
+                    try
+                    {
+                        byte[] buf = new byte[4*1024];
+                        int n;
+                        while ((n = in.read(buf)) != -1)
+                        {
+                            System.out.write(buf, 0, n);
+                        }
+                    }
+                    catch (IOException e)
+                    {
+                        _logger.info("redirector", e);
+                    }
+                }
+            }.start();
+
+            Thread.sleep(1000);
+
+            try
+            {
+                int exit = _brokerProcess.exitValue();
+                throw new RuntimeException("broker aborted: " + exit);
+            }
+            catch (IllegalThreadStateException e)
+            {
+                // this is expect if the broker started succesfully
+            }
         }
     }
 
-    //--------- Util method
-
-    /**
-     * This method starts a remote server by spawning an external process.
-     *
-     * @throws Exception If the broker cannot be started
-     */
-    public void startBroker() throws Exception
+    public void stopBroker() throws Exception
     {
-        _logger.info("Starting broker: " + _shel + " " + _brokerPath + "  " + 
_brokerParams + "");
-        Runtime rt = Runtime.getRuntime();
-        _brokerProcess = rt.exec(_shel + " " + _brokerPath + "  " + 
_brokerParams + "");
-        BufferedReader reader = new BufferedReader(new 
InputStreamReader(_brokerProcess.getInputStream()));
-        if (reader.ready())
+        _logger.info("stopping broker: " + _broker);
+        if (_brokerProcess != null)
         {
-            //bad, we had an error starting the broker
-            throw new Exception("Problem when starting the broker: " + 
reader.readLine());
+            _brokerProcess.destroy();
+            _brokerProcess.waitFor();
+            _logger.info("broker exited: " + _brokerProcess.exitValue());
+            _brokerProcess = null;
         }
-        // We need to wait for th ebroker to start ideally we would need to 
ping it
-        synchronized(this)
+        else if (_broker.equals(VM))
         {
-            this.wait(1000);
+            TransportConnection.killAllVMBrokers();
         }
     }
 
@@ -159,28 +143,18 @@
      */
     public boolean isBroker08()
     {
-        return _brokerVersion.equals(BROKER_08);
+        return _brokerVersion.equals(VERSION_08);
     }
 
-    /**
-     * Stop the currently running broker.
-     */
-    public void stopBroker()
+    public boolean isBroker010()
     {
-        _logger.info("Stopping broker");
-        // stooping the broker
-        if (_brokerProcess != null)
-        {
-            _brokerProcess.destroy();
-        }
-        _initialContext = null;
-        _connectionFactory = null;
+        return _brokerVersion.equals(VERSION_010);
     }
 
-     public void shutdownServer() throws Exception
+    public void shutdownServer() throws Exception
     {
-        killBroker();
-        setUp();
+        stopBroker();
+        startBroker();
     }
     /**
      * we assume that the environment is correctly set
@@ -228,7 +202,7 @@
     {
         _logger.info("get Connection");
         Connection con;
-        if (_shel.equals(BROKER_VM))
+        if (_broker.equals(VM))
         {
             con = new AMQConnection("vm://:1", username, password, "Test", 
"test");
         }
@@ -243,7 +217,7 @@
     {
         _logger.info("get Connection");
         Connection con;
-        if (_shel.equals(BROKER_VM))
+        if (_broker.equals(VM))
         {
             con = new AMQConnection("vm://:1", username, password, id, "test");
         }
@@ -254,8 +228,4 @@
         return con;
     }
 
-    public void testfoo()
-    {
-        //do nothing, just to avoid maven to report an error  
-    }
 }

Modified: incubator/qpid/trunk/qpid/java/common.xml
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/common.xml?rev=619888&r1=619887&r2=619888&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/common.xml (original)
+++ incubator/qpid/trunk/qpid/java/common.xml Fri Feb  8 05:50:55 2008
@@ -34,6 +34,7 @@
   <property name="build.report"          location="${build}/report"/>
   <property name="build.release"         location="${build}/release"/>
   <property name="build.release.prepare" location="${build.release}/prepare"/>
+  <property name="build.data"            location="${build}/data"/>
 
   <property name="java.target"           value="1.5"/>
   <property name="java.source"           value="1.5"/>
@@ -82,6 +83,10 @@
 
   <target name="clean-tasks">
     <delete dir="${tasks.classes}"/>
+  </target>
+
+  <target name="clean-results">
+    <delete dir="${build.results}"/>
   </target>
 
   <target name="report" description="generate test report">

Modified: incubator/qpid/trunk/qpid/java/module.xml
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/module.xml?rev=619888&r1=619887&r2=619888&view=diff
==============================================================================
--- incubator/qpid/trunk/qpid/java/module.xml (original)
+++ incubator/qpid/trunk/qpid/java/module.xml Fri Feb  8 05:50:55 2008
@@ -110,6 +110,7 @@
     <mkdir dir="${build.etc}"/>
     <mkdir dir="${build.lib}"/>
     <mkdir dir="${build.results}"/>
+    <mkdir dir="${build.data}"/>
     <mkdir dir="${module.classes}"/>
     <mkdir dir="${module.precompiled}"/>
     <mkdir dir="${module.api}"/>
@@ -156,20 +157,40 @@
   </target>
 
   <property name="test" value="*Test"/>
+
   <property name="log" value="info"/>
   <property name="amqj.logging.level" value="${log}"/>
   <property name="root.logging.level" value="${log}"/>
   <property name="log4j.configuration" 
value="file://${project.root}/log4j-test.xml"/>
 
+  <property name="java.naming.factory.initial" 
value="org.apache.qpid.jndi.PropertiesFileInitialContextFactory"/>
+  <property name="java.naming.provider.url" 
value="${project.root}/test-provider.properties"/>
+
+  <condition property="broker" value="${project.root}/../cpp/src/qpidd 
--data-dir ${build.data} -t" else="vm">
+    <isset property="cpp"/>
+  </condition>
+
+  <condition property="broker.version" value="0-10" else="0-8">
+    <isset property="cpp"/>
+  </condition>
+
   <target name="test" depends="compile-tests" if="module.test.src.exists"
           description="execute unit tests">
     <junit fork="yes" haltonfailure="no" printsummary="on" timeout="90000">
+
       <sysproperty key="amqj.logging.level" value="${amqj.logging.level}"/>
       <sysproperty key="root.logging.level" value="${root.logging.level}"/>
       <sysproperty key="log4j.configuration" value="${log4j.configuration}"/>
+      <sysproperty key="java.naming.factory.initial" 
value="${java.naming.factory.initial}"/>
+      <sysproperty key="java.naming.provider.url" 
value="${java.naming.provider.url}"/>
+      <sysproperty key="broker" value="${broker}"/>
+      <sysproperty key="broker.version" value="${broker.version}"/>
+
       <formatter type="plain"/>
       <formatter type="xml"/>
+
       <classpath refid="module.test.path"/>
+
       <batchtest fork="yes" todir="${build.results}">
         <fileset dir="${module.test.src}">
           <include name="**/${test}.java"/>

Added: incubator/qpid/trunk/qpid/java/test-provider.properties
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/test-provider.properties?rev=619888&view=auto
==============================================================================
--- incubator/qpid/trunk/qpid/java/test-provider.properties (added)
+++ incubator/qpid/trunk/qpid/java/test-provider.properties Fri Feb  8 05:50:55 
2008
@@ -0,0 +1 @@
+connectionfactory.local = 
qpid:password=guest;username=guest;client_id=clientid;[EMAIL 
PROTECTED]:127.0.0.1:5672

Propchange: incubator/qpid/trunk/qpid/java/test-provider.properties
------------------------------------------------------------------------------
    svn:eol-style = native


Reply via email to