You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by ri...@apache.org on 2009/08/07 20:07:48 UTC

svn commit: r802118 - in /qpid/trunk/qpid/java: module.xml systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java test-profiles/default.testprofile test-profiles/java-derby.testprofile test-profiles/java.testprofile

Author: ritchiem
Date: Fri Aug  7 18:07:47 2009
New Revision: 802118

URL: http://svn.apache.org/viewvc?rev=802118&view=rev
Log:
QPID-2033 : Added destroy for broker process that fails to startup. Also augmented QpidTestCase and build profiles to take a new broker.stopped search value. If this appears in the log output during the external broker startup and the broker does not report ready then the startup will report the line of text associated with the exception as part of the failure. Currently the stopped value is set to to 'Exception'. This means if an exception occurs during startup then test will give more detail about the cause of the failure. This is only monitored during the brokerStart() call and through the getStopLine() call on the Piper we can return the line of text that the Exception matched. Providing more details of why a broker failed to startup. This extra detail is currently added to the exception thrown when the broker fails to become ready.

Added test.mport to profile for defaulting management port

Modified:
    qpid/trunk/qpid/java/module.xml
    qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
    qpid/trunk/qpid/java/test-profiles/default.testprofile
    qpid/trunk/qpid/java/test-profiles/java-derby.testprofile
    qpid/trunk/qpid/java/test-profiles/java.testprofile

Modified: qpid/trunk/qpid/java/module.xml
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/module.xml?rev=802118&r1=802117&r2=802118&view=diff
==============================================================================
--- qpid/trunk/qpid/java/module.xml (original)
+++ qpid/trunk/qpid/java/module.xml Fri Aug  7 18:07:47 2009
@@ -271,6 +271,7 @@
       <sysproperty key="broker.clean" value="${broker.clean}"/>
       <sysproperty key="broker.version" value="${broker.version}"/>
       <sysproperty key="broker.ready" value="${broker.ready}" />
+      <sysproperty key="broker.stopped" value="${broker.stopped}" />
       <sysproperty key="broker.config" value="${broker.config}" />
       <sysproperty key="test.output" value="${module.results}"/>
       <syspropertyset>

Modified: qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java?rev=802118&r1=802117&r2=802118&view=diff
==============================================================================
--- qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java (original)
+++ qpid/trunk/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java Fri Aug  7 18:07:47 2009
@@ -19,15 +19,28 @@
 
 import junit.framework.TestCase;
 import junit.framework.TestResult;
+import org.apache.commons.configuration.ConfigurationException;
+import org.apache.commons.configuration.XMLConfiguration;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.jms.BrokerDetails;
+import org.apache.qpid.jms.ConnectionURL;
+import org.apache.qpid.server.configuration.ServerConfiguration;
+import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry;
+import org.apache.qpid.server.store.DerbyMessageStore;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 
 import javax.jms.Connection;
 import javax.jms.Destination;
-import javax.jms.Session;
-import javax.jms.MessageProducer;
-import javax.jms.Message;
 import javax.jms.JMSException;
-import javax.jms.Queue;
+import javax.jms.Message;
 import javax.jms.MessageConsumer;
+import javax.jms.MessageProducer;
+import javax.jms.Queue;
+import javax.jms.Session;
 import javax.naming.InitialContext;
 import javax.naming.NamingException;
 import java.io.BufferedReader;
@@ -40,31 +53,12 @@
 import java.io.PrintStream;
 import java.net.MalformedURLException;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
 import java.util.Map;
-import java.util.HashMap;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.TimeUnit;
 
-
-import org.apache.commons.configuration.ConfigurationException;
-import org.apache.commons.configuration.XMLConfiguration;
-import org.apache.commons.configuration.Configuration;
-
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQConnectionFactory;
-import org.apache.qpid.server.configuration.ServerConfiguration;
-import org.apache.qpid.server.store.DerbyMessageStore;
-import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.server.registry.ConfigurationFileApplicationRegistry;
-import org.apache.qpid.server.logging.subjects.AbstractTestLogSubject;
-import org.apache.qpid.jms.BrokerDetails;
-import org.apache.qpid.jms.ConnectionURL;
-
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
 /**
  *
  *
@@ -152,6 +146,7 @@
     private static final String BROKER_CLEAN = "broker.clean";
     private static final String BROKER_VERSION = "broker.version";
     private static final String BROKER_READY = "broker.ready";
+    private static final String BROKER_STOPPED = "broker.stopped";
     private static final String TEST_OUTPUT = "test.output";
 
     // values
@@ -166,6 +161,7 @@
 
     protected static int DEFAULT_VM_PORT = 1;
     protected static int DEFAULT_PORT = Integer.getInteger("test.port", 5672);
+    protected static int DEFAULT_MANAGEMENT_PORT = Integer.getInteger("test.mport", 8999);
 
     protected String _brokerLanguage = System.getProperty(BROKER_LANGUAGE, JAVA);
     protected String _broker = System.getProperty(BROKER, VM);
@@ -175,7 +171,7 @@
 
     protected File _outputFile;
 
-    private Map<Integer,Process> _brokers = new HashMap<Integer,Process>();
+    private Map<Integer, Process> _brokers = new HashMap<Integer, Process>();
 
     private InitialContext _initialContext;
     private AMQConnectionFactory _connectionFactory;
@@ -187,6 +183,7 @@
     public static final String QUEUE = "queue";
     public static final String TOPIC = "topic";
 
+
     public QpidTestCase(String name)
     {
         super(name);
@@ -209,7 +206,7 @@
         boolean redirected = _output != null && _output.length() > 0;
         if (redirected)
         {
-            _outputFile = new File (String.format("%s/TEST-%s.out", _output, qname));
+            _outputFile = new File(String.format("%s/TEST-%s.out", _output, qname));
             out = new PrintStream(_outputFile);
             err = new PrintStream(String.format("%s/TEST-%s.err", _output, qname));
             System.setOut(out);
@@ -276,12 +273,21 @@
         private String ready;
         private CountDownLatch latch;
         private boolean seenReady;
+        private String stopped;
+        private String stopLine;
 
         public Piper(InputStream in, String ready)
         {
+            this(in, ready, null);
+        }
+
+        public Piper(InputStream in, String ready, String stopped)
+        {
             this.in = new LineNumberReader(new InputStreamReader(in));
             this.ready = ready;
+            this.stopped = stopped;
             this.seenReady = false;
+
             if (this.ready != null && !this.ready.equals(""))
             {
                 this.latch = new CountDownLatch(1);
@@ -323,6 +329,11 @@
                         seenReady = true;
                         latch.countDown();
                     }
+
+                    if (latch != null && line.contains(stopped))
+                    {
+                        stopLine = line;
+                    }
                 }
             }
             catch (IOException e)
@@ -338,6 +349,11 @@
                 }
             }
         }
+
+        public String getStopLine()
+        {
+            return stopLine;
+        }
     }
 
     public void startBroker() throws Exception
@@ -347,6 +363,7 @@
 
     /**
      * Get the Port that is use by the current broker
+     *
      * @return the current port
      */
     protected int getPort()
@@ -373,10 +390,10 @@
     private String getBrokerCommand(int port) throws MalformedURLException
     {
         return _broker
-            .replace("@PORT", "" + port)
-            .replace("@SSL_PORT", "" + (port - 1))
-            .replace("@MPORT", "" + (port + (8999 - DEFAULT_PORT)))
-            .replace("@CONFIG_FILE", _configFile.toString());
+                .replace("@PORT", "" + port)
+                .replace("@SSL_PORT", "" + (port - 1))
+                .replace("@MPORT", "" + (port + (DEFAULT_MANAGEMENT_PORT - DEFAULT_PORT)))
+                .replace("@CONFIG_FILE", _configFile.toString());
     }
 
     public void startBroker(int port) throws Exception
@@ -411,17 +428,19 @@
             process = pb.start();
 
             Piper p = new Piper(process.getInputStream(),
-                                System.getProperty(BROKER_READY));
+                                System.getProperty(BROKER_READY),
+                                System.getProperty(BROKER_STOPPED));
 
             p.start();
 
             if (!p.await(30, TimeUnit.SECONDS))
             {
-                _logger.info("broker failed to become ready");
+                _logger.info("broker failed to become ready:" + p.getStopLine());
                 //Ensure broker has stopped
                 process.destroy();
                 cleanBroker();
-                throw new RuntimeException("broker failed to become ready");
+                throw new RuntimeException("broker failed to become ready:"
+                                           + p.getStopLine());
             }
 
             try
@@ -506,7 +525,7 @@
         }
         else
         {
-            String command = "pkill -KILL -f "+getBrokerCommand(getPort(port));
+            String command = "pkill -KILL -f " + getBrokerCommand(getPort(port));
             try
             {
                 Runtime.getRuntime().exec(command);
@@ -514,13 +533,12 @@
             catch (Exception e)
             {
                 // Can't do that, try the old fashioned way
-                _logger.warn("Could not run "+command+", killing with stopBroker()");
+                _logger.warn("Could not run " + command + ", killing with stopBroker()");
                 stopBroker(port);
             }
         }
     }
 
-
     /**
      * Attempt to set the Java Broker to use the BDBMessageStore for persistence
      * Falling back to the DerbyMessageStore if
@@ -556,7 +574,7 @@
                                   ".store.class", storeClass.getName());
         configuration.setProperty("virtualhosts.virtualhost." + virtualhost +
                                   ".store." + DerbyMessageStore.ENVIRONMENT_PATH_PROPERTY,
-                                  "${work}/"+virtualhost);
+                                  "${work}/" + virtualhost);
 
         File tmpFile = File.createTempFile("configFile", "test");
         tmpFile.deleteOnExit();
@@ -590,9 +608,10 @@
      * configuration files being created.
      *
      * @param property the configuration property to set
-     * @param value the new value
+     * @param value    the new value
+     *
      * @throws ConfigurationException when loading the current config file
-     * @throws IOException when writing the new config file
+     * @throws IOException            when writing the new config file
      */
     protected void setConfigurationProperty(String property, String value)
             throws ConfigurationException, IOException
@@ -645,9 +664,9 @@
      * Set a System property for the duration of this test.
      *
      * When the test run is complete the value will be reverted.
-
+     *
      * @param property the property to set
-     * @param value the new value to use
+     * @param value    the new value to use
      */
     protected void setSystemProperty(String property, String value)
     {
@@ -845,14 +864,16 @@
      * persistent tests don't leave data behind.
      *
      * @param queue the queue to purge
-     * @throws Exception if a problem occurs
+     *
      * @return the count of messages drained
+     *
+     * @throws Exception if a problem occurs
      */
     protected int drainQueue(Queue queue) throws Exception
     {
         Connection connection = getConnection();
 
-        Session session = connection.createSession(false,Session.AUTO_ACKNOWLEDGE);
+        Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
 
         MessageConsumer consumer = session.createConsumer(queue);
 
@@ -872,11 +893,11 @@
     public List<Message> sendMessage(Session session, Destination destination,
                                      int count) throws Exception
     {
-       return sendMessage(session, destination, count, 0);
+        return sendMessage(session, destination, count, 0);
     }
 
     public List<Message> sendMessage(Session session, Destination destination,
-                                     int count,int batchSize) throws Exception
+                                     int count, int batchSize) throws Exception
     {
         List<Message> messages = new ArrayList<Message>(count);
 
@@ -920,7 +941,6 @@
         return getConnectionFactory().getConnectionURL();
     }
 
-
     public BrokerDetails getBroker()
     {
         try

Modified: qpid/trunk/qpid/java/test-profiles/default.testprofile
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/test-profiles/default.testprofile?rev=802118&r1=802117&r2=802118&view=diff
==============================================================================
--- qpid/trunk/qpid/java/test-profiles/default.testprofile (original)
+++ qpid/trunk/qpid/java/test-profiles/default.testprofile Fri Aug  7 18:07:47 2009
@@ -17,6 +17,7 @@
 log4j.debug=false
 
 test.port=15672
+test.mport=18999
 test.port.ssl=15671
 test.port.alt=15673
 

Modified: qpid/trunk/qpid/java/test-profiles/java-derby.testprofile
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/test-profiles/java-derby.testprofile?rev=802118&r1=802117&r2=802118&view=diff
==============================================================================
--- qpid/trunk/qpid/java/test-profiles/java-derby.testprofile (original)
+++ qpid/trunk/qpid/java/test-profiles/java-derby.testprofile Fri Aug  7 18:07:47 2009
@@ -1,7 +1,8 @@
 broker.language=java
 broker=${project.root}/build/bin/qpid-server -p @PORT -m @MPORT -c @CONFIG_FILE -l ${test.profiles}/log4j-test.xml
 broker.clean=${test.profiles}/clean-dir ${build.data} ${project.root}/build/work/derbyDB
-broker.ready=Qpid Broker Ready
+broker.ready=Ready
+broker.stopped=Exception
 broker.config=${project.root}/build/etc/config-systests-derby.xml
 
 profile.excludes=08StandaloneExcludes

Modified: qpid/trunk/qpid/java/test-profiles/java.testprofile
URL: http://svn.apache.org/viewvc/qpid/trunk/qpid/java/test-profiles/java.testprofile?rev=802118&r1=802117&r2=802118&view=diff
==============================================================================
--- qpid/trunk/qpid/java/test-profiles/java.testprofile (original)
+++ qpid/trunk/qpid/java/test-profiles/java.testprofile Fri Aug  7 18:07:47 2009
@@ -1,6 +1,7 @@
 broker.language=java
 broker=${project.root}/build/bin/qpid-server -p @PORT -m @MPORT -c @CONFIG_FILE -l ${test.profiles}/log4j-test.xml
 broker.clean=${test.profiles}/clean-dir ${build.data} ${project.root}/build/work/derbyDB
-broker.ready=Qpid Broker Ready
+broker.ready=Ready
+broker.stopped=Exception
 
 profile.excludes=08TransientExcludes 08StandaloneExcludes



---------------------------------------------------------------------
Apache Qpid - AMQP Messaging Implementation
Project:      http://qpid.apache.org
Use/Interact: mailto:commits-subscribe@qpid.apache.org