summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2009-04-17 13:59:14 +0000
committerMartin Ritchie <ritchiem@apache.org>2009-04-17 13:59:14 +0000
commita7fcec559df5a84ccd5b6e23f108503608128a9f (patch)
treef59bba26c4dfea8a06aa14fc33c4e8a8720840e8
parenta97180c89d9a6f98fe81b8aa88f351996f5b1a65 (diff)
downloadqpid-python-a7fcec559df5a84ccd5b6e23f108503608128a9f.tar.gz
QPID-1817 : Update to QpidTestCase to use setUp to start the broker this allows tests to update the _configFile that is being used before the broker is started. By default the etc/config-systests.xml is used. This differs from the stock config.xml only in that it disables the Managment JMX interface by default. If a test requires this functionality it can provided an edited configuration. An example of how that might be done can be seen in SyncWaitDelayTest and will additionally be provided for QPID-1813.
A couple of tests were modified to remove their setUp/tearDown where the code did no additional work. This made the tests cleaner. Additionally FrameworkBaseCase never actually called super.setUp() so that was fixed. merged to trunk from r765602 git-svn-id: https://svn.apache.org/repos/asf/qpid/branches/0.5-release@766014 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--qpid/java/module.xml1
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java9
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java1
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/basic/close/CloseTest.java14
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java32
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java10
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java43
7 files changed, 64 insertions, 46 deletions
diff --git a/qpid/java/module.xml b/qpid/java/module.xml
index 3bf0f13cc8..4a613b32f8 100644
--- a/qpid/java/module.xml
+++ b/qpid/java/module.xml
@@ -251,6 +251,7 @@
<sysproperty key="example.plugin.target" value="${project.root}/build/lib/plugins"/>
<sysproperty key="QPID_EXAMPLE_HOME" value="${project.root}/build"/>
<sysproperty key="QPID_HOME" value="${project.root}/build"/>
+ <sysproperty key="QPID_WORK" value="${project.root}/build/work"/>
<formatter type="plain"/>
<formatter type="xml"/>
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java
index 59ee4ad511..747776c9fc 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/timeouts/SyncWaitDelayTest.java
@@ -46,9 +46,6 @@ public class SyncWaitDelayTest extends QpidTestCase
{
protected static final Logger _logger = LoggerFactory.getLogger(SyncWaitDelayTest.class);
- final String QpidHome = System.getProperty("QPID_HOME");
- final File _configFile = new File(QpidHome, "etc/config.xml");
-
private String VIRTUALHOST = "test";
protected long POST_COMMIT_DELAY = 1000L;
protected long SYNC_WRITE_TIMEOUT = POST_COMMIT_DELAY + 1000;
@@ -77,9 +74,9 @@ public class SyncWaitDelayTest extends QpidTestCase
tmpFile.deleteOnExit();
configuration.save(tmpFile);
- ApplicationRegistry reg = new ConfigurationFileApplicationRegistry(tmpFile);
-
- startBroker(1, reg);
+ _configFile = tmpFile;
+
+ startBroker(1);
//Set the syncWrite timeout to be just larger than the delay on the commitTran.
setSystemProperty("amqj.default_syncwrite_timeout", String.valueOf(SYNC_WRITE_TIMEOUT));
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java
index eb51a32166..5a76ff251b 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/framework/FrameworkBaseCase.java
@@ -189,6 +189,7 @@ public class FrameworkBaseCase extends QpidTestCase implements FrameworkTestCont
*/
protected void setUp() throws Exception
{
+ super.setUp();
NDC.push(getName());
testProps = TestContextProperties.getInstance(MessagingTestConfigProperties.defaults);
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/basic/close/CloseTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/basic/close/CloseTest.java
index 21eaad6d5b..89316b6511 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/basic/close/CloseTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/basic/close/CloseTest.java
@@ -35,18 +35,6 @@ public class CloseTest extends QpidTestCase
{
private static final Logger _logger = LoggerFactory.getLogger(CloseTest.class);
- private static final String BROKER = "vm://:1";
-
- protected void setUp() throws Exception
- {
- super.setUp();
- }
-
- protected void tearDown() throws Exception
- {
- super.setUp();
- }
-
public void testCloseQueueReceiver() throws Exception
{
AMQConnection connection = (AMQConnection) getConnection("guest", "guest");
@@ -62,7 +50,7 @@ public class CloseTest extends QpidTestCase
_logger.info("About to close consumer");
- consumer.close();
+ consumer.close();
_logger.info("Closed Consumer");
connection.close();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
index 5147d4a94d..397fc15b66 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
@@ -30,9 +30,12 @@ import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.AMQTopic;
+import org.apache.qpid.client.AMQConnectionURL;
import org.apache.qpid.exchange.ExchangeDefaults;
import org.apache.qpid.framing.AMQShortString;
import org.apache.qpid.jms.Session;
+import org.apache.qpid.jms.ConnectionURL;
+import org.apache.qpid.jms.BrokerDetails;
import javax.jms.Connection;
import javax.jms.QueueSession;
@@ -45,13 +48,13 @@ public class ConnectionTest extends QpidTestCase
String _broker_NotRunning = "vm://:2";
String _broker_BadDNS = "tcp://hg3sgaaw4lgihjs";
- public String getBroker()
+ public BrokerDetails getBroker()
{
try
{
if (getConnectionFactory().getConnectionURL().getBrokerCount() > 0)
{
- return getConnectionFactory().getConnectionURL().getBrokerDetails(0).toString();
+ return getConnectionFactory().getConnectionURL().getBrokerDetails(0);
}
else
{
@@ -72,7 +75,7 @@ public class ConnectionTest extends QpidTestCase
AMQConnection conn = null;
try
{
- conn = new AMQConnection(getBroker(), "guest", "guest", "fred", "test");
+ conn = new AMQConnection(getBroker().toString(), "guest", "guest", "fred", "test");
}
catch (Exception e)
{
@@ -89,13 +92,18 @@ public class ConnectionTest extends QpidTestCase
AMQConnection conn = null;
try
{
- conn = new AMQConnection("amqp://guest:guest@clientid/test?brokerlist='"
- + getBroker()
- + "?retries='1''&defaultQueueExchange='test.direct'"
+ BrokerDetails broker = getBroker();
+ broker.setProperty("retries","1");
+ ConnectionURL url = new AMQConnectionURL("amqp://guest:guest@clientid/test?brokerlist='"
+ + broker
+ + "'&defaultQueueExchange='test.direct'"
+ "&defaultTopicExchange='test.topic'"
+ "&temporaryQueueExchange='tmp.direct'"
+ "&temporaryTopicExchange='tmp.topic'");
+ System.err.println(url.toString());
+ conn = new AMQConnection(url, null);
+
AMQSession sess = (AMQSession) conn.createSession(false, Session.AUTO_ACKNOWLEDGE);
@@ -151,7 +159,9 @@ public class ConnectionTest extends QpidTestCase
AMQConnection conn = null;
try
{
- conn = new AMQConnection("amqp://guest:rubbishpassword@clientid/test?brokerlist='" + getBroker() + "?retries='0''");
+ BrokerDetails broker = getBroker();
+ broker.setProperty("retries", "0");
+ conn = new AMQConnection("amqp://guest:rubbishpassword@clientid/test?brokerlist='" + broker + "'");
fail("Connection should not be established password is wrong.");
}
catch (AMQConnectionFailureException amqe)
@@ -223,7 +233,9 @@ public class ConnectionTest extends QpidTestCase
AMQConnection conn = null;
try
{
- conn = new AMQConnection("amqp://guest:guest@clientid/rubbishhost?brokerlist='" + getBroker() + "?retries='0''");
+ BrokerDetails broker = getBroker();
+ broker.setProperty("retries", "0");
+ conn = new AMQConnection("amqp://guest:guest@clientid/rubbishhost?brokerlist='" + broker + "'");
fail("Connection should not be established");
}
catch (AMQException amqe)
@@ -244,7 +256,7 @@ public class ConnectionTest extends QpidTestCase
public void testClientIdCannotBeChanged() throws Exception
{
- Connection connection = new AMQConnection(getBroker(), "guest", "guest",
+ Connection connection = new AMQConnection(getBroker().toString(), "guest", "guest",
"fred", "test");
try
{
@@ -266,7 +278,7 @@ public class ConnectionTest extends QpidTestCase
public void testClientIdIsPopulatedAutomatically() throws Exception
{
- Connection connection = new AMQConnection(getBroker(), "guest", "guest",
+ Connection connection = new AMQConnection(getBroker().toString(), "guest", "guest",
null, "test");
try
{
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
index c6a953dbc2..cbe25e4f32 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
@@ -51,16 +51,6 @@ public class DurableSubscriptionTest extends QpidTestCase
{
private static final Logger _logger = LoggerFactory.getLogger(DurableSubscriptionTest.class);
- protected void setUp() throws Exception
- {
- super.setUp();
- }
-
- protected void tearDown() throws Exception
- {
- super.tearDown();
- }
-
public void testUnsubscribe() throws Exception
{
AMQConnection con = (AMQConnection) getConnection("guest", "guest");
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
index 00c1da69e9..d75b6276ac 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/utils/QpidTestCase.java
@@ -21,6 +21,10 @@ import junit.framework.TestCase;
import junit.framework.TestResult;
import javax.jms.Connection;
+import javax.jms.Destination;
+import javax.jms.Session;
+import javax.jms.MessageProducer;
+import javax.jms.Message;
import javax.naming.InitialContext;
import javax.naming.NamingException;
import java.io.*;
@@ -47,6 +51,8 @@ import org.slf4j.LoggerFactory;
*/
public class QpidTestCase extends TestCase
{
+ protected final String QpidHome = System.getProperty("QPID_HOME");
+ protected File _configFile = new File(QpidHome, "etc/config-systests.xml");
private static final Logger _logger = LoggerFactory.getLogger(QpidTestCase.class);
@@ -182,7 +188,6 @@ public class QpidTestCase extends TestCase
}
_logger.info("========== start " + _testName + " ==========");
- startBroker();
try
{
super.runBare();
@@ -209,6 +214,17 @@ public class QpidTestCase extends TestCase
}
}
+ @Override
+ protected void setUp() throws Exception
+ {
+ if (!_configFile.exists())
+ {
+ fail("Unable to test without config file:" + _configFile);
+ }
+
+ startBroker();
+ }
+
public void run(TestResult testResult)
{
if (_exclusionList != null && (_exclusionList.contains(getClass().getName() + "#*") ||
@@ -294,12 +310,6 @@ public class QpidTestCase extends TestCase
}
}
- public void startBroker(int port, ApplicationRegistry config) throws Exception
- {
- ApplicationRegistry.initialise(config, port);
- startBroker(port);
- }
-
public void startBroker() throws Exception
{
startBroker(0);
@@ -336,6 +346,7 @@ public class QpidTestCase extends TestCase
if (_broker.equals(VM))
{
// create an in_VM broker
+ ApplicationRegistry.initialise(new ConfigurationFileApplicationRegistry(_configFile), port);
TransportConnection.createVMBroker(port);
}
else if (!_broker.equals(EXTERNAL))
@@ -605,4 +616,22 @@ public class QpidTestCase extends TestCase
revertSystemProperties();
}
+ public List<Message> sendMessage(Session session, Destination destination,
+ int count) throws Exception
+ {
+ List<Message> messages = new ArrayList<Message>(count);
+
+ MessageProducer producer = session.createProducer(destination);
+
+ for (int i = 0; i < count; i++)
+ {
+ Message next = session.createMessage();
+
+ producer.send(next);
+
+ messages.add(next);
+ }
+ return messages;
+ }
+
}