diff options
| author | Rafael H. Schloming <rhs@apache.org> | 2008-02-08 13:50:55 +0000 |
|---|---|---|
| committer | Rafael H. Schloming <rhs@apache.org> | 2008-02-08 13:50:55 +0000 |
| commit | 942b577d5047b3617d00a375235400e275bfe1ff (patch) | |
| tree | 62788ad111938dcc88cb6b105b1ca9918ba9e347 | |
| parent | 910fa22beb64c0c4d64221d9485830035c1663ff (diff) | |
| download | qpid-python-942b577d5047b3617d00a375235400e275bfe1ff.tar.gz | |
simplied QpidTestCase's interface for running non vm brokers and set up build system to run cpp tests easily
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@619888 13f79535-47bb-0310-9956-ffa450edef68
9 files changed, 123 insertions, 127 deletions
diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java index e2d3832cc9..3cef57f90d 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ConnectionStartTest.java @@ -82,8 +82,9 @@ public class ConnectionStartTest extends QpidTestCase protected void tearDown() throws Exception { _connection.close(); + super.tearDown(); } - + public void testSimpleReceiveConnection() { try diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java index 20461415d1..ccf16a0b6e 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/connection/ExceptionListenerTest.java @@ -51,7 +51,7 @@ public class ExceptionListenerTest extends QpidTestCase } }); - killBroker(); + stopBroker(); if (!fired.get(3000)) { diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java b/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java index b2bf7fd7e4..f43ccaf0ff 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/client/forwardall/Client.java @@ -98,7 +98,7 @@ public class Client implements MessageListener if (_count < _expected) { - wait(1000000000); + wait(60000); } if (_count < _expected) diff --git a/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java b/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java index 21890e1ae9..5ebde71d6c 100644 --- a/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java +++ b/java/client/src/test/java/org/apache/qpid/test/unit/close/MessageRequeueTest.java @@ -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 javax.jms.Session; 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 @@ public class MessageRequeueTest extends TestCase protected void setUp() throws Exception { super.setUp(); - conn = new QpidClientConnection(BROKER); + + conn = new QpidClientConnection(BROKER); conn.connect(); // clear queue @@ -78,7 +78,6 @@ public class MessageRequeueTest extends TestCase protected void tearDown() throws Exception { - super.tearDown(); if (!passed) // clean up { @@ -91,6 +90,7 @@ public class MessageRequeueTest extends TestCase conn.disconnect(); } + super.tearDown(); } /** @@ -125,7 +125,7 @@ public class MessageRequeueTest extends TestCase 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 @@ public class MessageRequeueTest extends TestCase 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 @@ public class MessageRequeueTest extends TestCase assertEquals(list.toString(), 0, failed); } - _logger.info("consumed: " + messagesReceived); + conn.disconnect(); passed = true; } @@ -208,7 +210,7 @@ public class MessageRequeueTest extends TestCase } 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()); diff --git a/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java b/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java index f9c830ddae..e99a51e1c7 100644 --- a/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java +++ b/java/client/src/test/java/org/apache/qpid/testutil/QpidClientConnection.java @@ -81,11 +81,8 @@ public class QpidClientConnection extends QpidTestCase implements ExceptionListe 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 @@ public class QpidClientConnection extends QpidTestCase implements ExceptionListe connection.close(); connected = false; _logger.info("disconnected"); - tearDown(); } } diff --git a/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java b/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java index 0ccb50dda3..e7c09fca65 100644 --- a/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java +++ b/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java @@ -21,8 +21,8 @@ import junit.framework.TestCase; 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 @@ import org.slf4j.LoggerFactory; 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)) - { - TransportConnection.killAllVMBrokers(); + else if (!_broker.equals(EXTERNAL)) + { + _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 class QpidTestCase extends TestCase */ 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 @@ public class QpidTestCase extends TestCase { _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 @@ public class QpidTestCase extends TestCase { _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 @@ public class QpidTestCase extends TestCase return con; } - public void testfoo() - { - //do nothing, just to avoid maven to report an error - } } diff --git a/java/common.xml b/java/common.xml index 1f42c9d002..8e44693c63 100644 --- a/java/common.xml +++ b/java/common.xml @@ -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"/> @@ -84,6 +85,10 @@ <delete dir="${tasks.classes}"/> </target> + <target name="clean-results"> + <delete dir="${build.results}"/> + </target> + <target name="report" description="generate test report"> <delete dir="${build.report}"/> <mkdir dir="${build.report}"/> diff --git a/java/module.xml b/java/module.xml index d723aef0e2..d80a2c0f56 100644 --- a/java/module.xml +++ b/java/module.xml @@ -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"/> diff --git a/java/test-provider.properties b/java/test-provider.properties new file mode 100644 index 0000000000..b857c5c312 --- /dev/null +++ b/java/test-provider.properties @@ -0,0 +1 @@ +connectionfactory.local = qpid:password=guest;username=guest;client_id=clientid;virtualhost=test@tcp:127.0.0.1:5672 |
