summaryrefslogtreecommitdiff
path: root/qpid
diff options
context:
space:
mode:
authorArnaud Simon <arnaudsimon@apache.org>2008-05-22 11:42:42 +0000
committerArnaud Simon <arnaudsimon@apache.org>2008-05-22 11:42:42 +0000
commit1a6ea93220643c862ba3520a78e1cf001a7c9439 (patch)
treefcda95bee30154ca14b19f5217dbd8312e880800 /qpid
parentfa85fb8871a8b1e620479d0717f1655553a93223 (diff)
downloadqpid-python-1a6ea93220643c862ba3520a78e1cf001a7c9439.tar.gz
QPID-1079: Updated ...test.client tests for using QpidTestCase
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk@659083 13f79535-47bb-0310-9956-ffa450edef68
Diffstat (limited to 'qpid')
-rw-r--r--qpid/java/010ExcludeList13
-rw-r--r--qpid/java/010ExcludeList-store13
-rw-r--r--qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java60
-rw-r--r--qpid/java/cpp.async.testprofile2
-rw-r--r--qpid/java/cpp.sync.testprofile2
-rw-r--r--qpid/java/cpp.testprofile2
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/FailoverBaseCase.java64
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/client/CancelTest.java40
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java95
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java26
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserClientAckTest.java20
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserDupsOkTest.java19
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserNoAckTest.java20
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserPreAckTest.java22
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTransactedTest.java21
-rw-r--r--qpid/java/systests/src/main/java/org/apache/qpid/test/unit/ack/AcknowledgeTest.java43
-rw-r--r--qpid/java/test-provider.properties8
17 files changed, 214 insertions, 256 deletions
diff --git a/qpid/java/010ExcludeList b/qpid/java/010ExcludeList
index 4528c4d121..8a38aeaad5 100644
--- a/qpid/java/010ExcludeList
+++ b/qpid/java/010ExcludeList
@@ -18,3 +18,16 @@ org.apache.qpid.server.security.acl.SimpleACLTest#*
org.apache.qpid.server.plugins.PluginTest#*
// This test is not finished
org.apache.qpid.test.testcases.TTLTest#*
+// Those tests require failover support
+org.apache.qpid.test.client.QueueBrowserAutoAckTest#testFailoverAsQueueBrowserCreated
+org.apache.qpid.test.client.QueueBrowserAutoAckTest#testFailoverWithQueueBrowser
+org.apache.qpid.test.client.QueueBrowserClientAckTest#testFailoverAsQueueBrowserCreated
+org.apache.qpid.test.client.QueueBrowserClientAckTest#testFailoverWithQueueBrowser
+org.apache.qpid.test.client.QueueBrowserDupsOkTest#testFailoverAsQueueBrowserCreated
+org.apache.qpid.test.client.QueueBrowserDupsOkTest#testFailoverWithQueueBrowser
+org.apache.qpid.test.client.QueueBrowserNoAckTest#testFailoverAsQueueBrowserCreated
+org.apache.qpid.test.client.QueueBrowserNoAckTest#testFailoverWithQueueBrowser
+org.apache.qpid.test.client.QueueBrowserPreAckTest#testFailoverAsQueueBrowserCreated
+org.apache.qpid.test.client.QueueBrowserPreAckTest#testFailoverWithQueueBrowser
+org.apache.qpid.test.client.QueueBrowserTransactedTest#testFailoverAsQueueBrowserCreated
+org.apache.qpid.test.client.QueueBrowserTransactedTest#testFailoverWithQueueBrowser \ No newline at end of file
diff --git a/qpid/java/010ExcludeList-store b/qpid/java/010ExcludeList-store
index db9a15d2e6..8b3a9129bf 100644
--- a/qpid/java/010ExcludeList-store
+++ b/qpid/java/010ExcludeList-store
@@ -13,3 +13,16 @@ org.apache.qpid.server.security.acl.SimpleACLTest#*
org.apache.qpid.server.plugins.PluginTest#*
// This test is not finished
org.apache.qpid.test.testcases.TTLTest#*
+// Those tests require failover support
+org.apache.qpid.test.client.QueueBrowserAutoAckTest#testFailoverAsQueueBrowserCreated
+org.apache.qpid.test.client.QueueBrowserAutoAckTest#testFailoverWithQueueBrowser
+org.apache.qpid.test.client.QueueBrowserClientAckTest#testFailoverAsQueueBrowserCreated
+org.apache.qpid.test.client.QueueBrowserClientAckTest#testFailoverWithQueueBrowser
+org.apache.qpid.test.client.QueueBrowserDupsOkTest#testFailoverAsQueueBrowserCreated
+org.apache.qpid.test.client.QueueBrowserDupsOkTest#testFailoverWithQueueBrowser
+org.apache.qpid.test.client.QueueBrowserNoAckTest#testFailoverAsQueueBrowserCreated
+org.apache.qpid.test.client.QueueBrowserNoAckTest#testFailoverWithQueueBrowser
+org.apache.qpid.test.client.QueueBrowserPreAckTest#testFailoverAsQueueBrowserCreated
+org.apache.qpid.test.client.QueueBrowserPreAckTest#testFailoverWithQueueBrowser
+org.apache.qpid.test.client.QueueBrowserTransactedTest#testFailoverAsQueueBrowserCreated
+org.apache.qpid.test.client.QueueBrowserTransactedTest#testFailoverWithQueueBrowser \ No newline at end of file
diff --git a/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java b/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
index 2efec309b2..36278f890b 100644
--- a/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
+++ b/qpid/java/client/src/test/java/org/apache/qpid/testutil/QpidTestCase.java
@@ -110,12 +110,12 @@ public class QpidTestCase extends TestCase
private static final String BROKER_READY = "broker.ready";
// values
- private static final String VM = "vm";
+ protected 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";
- private String _broker = System.getProperty(BROKER, VM);
+ protected String _broker = System.getProperty(BROKER, VM);
private String _brokerClean = System.getProperty(BROKER_CLEAN, null);
private String _brokerVersion = System.getProperty(BROKER_VERSION, VERSION_08);
@@ -123,6 +123,10 @@ public class QpidTestCase extends TestCase
private InitialContext _initialContext;
private AMQConnectionFactory _connectionFactory;
+ private boolean _brokerStarted;
+
+ // the connections created for a given test
+ protected List<Connection> _connections = new ArrayList<Connection>();
public void runBare() throws Throwable
{
@@ -267,6 +271,7 @@ public class QpidTestCase extends TestCase
// this is expect if the broker started succesfully
}
}
+ _brokerStarted = true;
}
public void cleanBroker()
@@ -311,6 +316,7 @@ public class QpidTestCase extends TestCase
{
TransportConnection.killAllVMBrokers();
}
+ _brokerStarted = false;
}
/**
@@ -351,7 +357,8 @@ public class QpidTestCase extends TestCase
}
/**
- * Get a connection factory for the currently used broker
+ * Get the default connection factory for the currently used broker
+ * Default factory is "local"
*
* @return A conection factory
* @throws Exception if there is an error getting the tactory
@@ -361,11 +368,30 @@ public class QpidTestCase extends TestCase
_logger.info("get ConnectionFactory");
if (_connectionFactory == null)
{
- _connectionFactory = (AMQConnectionFactory) getInitialContext().lookup("local");
+ if (_broker.equals(VM))
+ {
+ _connectionFactory = getConnectionFactory("vm");
+ }
+ else
+ {
+ _connectionFactory = getConnectionFactory("local");
+ }
}
return _connectionFactory;
}
+ /**
+ * Get a connection factory for the currently used broker
+ *
+ * @param factoryName The factory name
+ * @return A conection factory
+ * @throws Exception if there is an error getting the tactory
+ */
+ public AMQConnectionFactory getConnectionFactory(String factoryName) throws Exception
+ {
+ return (AMQConnectionFactory) getInitialContext().lookup(factoryName);
+ }
+
public Connection getConnection() throws Exception
{
return getConnection("guest", "guest");
@@ -382,15 +408,9 @@ public class QpidTestCase extends TestCase
public Connection getConnection(String username, String password) throws Exception
{
_logger.info("get Connection");
- Connection con;
- if (_broker.equals(VM))
- {
- con = new AMQConnection("vm://:1", username, password, "Test", "test");
- }
- else
- {
- con = getConnectionFactory().createConnection(username, password);
- }
+ Connection con = getConnectionFactory().createConnection(username, password);
+ //add the connection in the lis of connections
+ _connections.add(con);
return con;
}
@@ -406,7 +426,21 @@ public class QpidTestCase extends TestCase
{
con = getConnectionFactory().createConnection(username, password);
}
+ //add the connection in the lis of connections
+ _connections.add(con);
return con;
}
+ protected void tearDown() throws java.lang.Exception
+ {
+ // close all the connections used by this test.
+ if (_brokerStarted)
+ {
+ for (Connection c : _connections)
+ {
+ c.close();
+ }
+ }
+ }
+
}
diff --git a/qpid/java/cpp.async.testprofile b/qpid/java/cpp.async.testprofile
index cbdd6f7940..15db0b9c19 100644
--- a/qpid/java/cpp.async.testprofile
+++ b/qpid/java/cpp.async.testprofile
@@ -15,4 +15,4 @@ test.mem=512M
test=*Test
haltonfailure=no
haltonerror=no
-exclude.modules=systests
+exclude.modules=none
diff --git a/qpid/java/cpp.sync.testprofile b/qpid/java/cpp.sync.testprofile
index ef8b298b87..cb52937cd1 100644
--- a/qpid/java/cpp.sync.testprofile
+++ b/qpid/java/cpp.sync.testprofile
@@ -15,4 +15,4 @@ test.mem=512M
test=*Test
haltonfailure=no
haltonerror=no
-exclude.modules=systests
+exclude.modules=none
diff --git a/qpid/java/cpp.testprofile b/qpid/java/cpp.testprofile
index 7b90d26e5c..6db245b007 100644
--- a/qpid/java/cpp.testprofile
+++ b/qpid/java/cpp.testprofile
@@ -15,4 +15,4 @@ test.mem=512M
test=*Test
haltonfailure=no
haltonerror=no
-exclude.modules=systests
+exclude.modules=none
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/FailoverBaseCase.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/FailoverBaseCase.java
index 4dd957c121..e939a06719 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/FailoverBaseCase.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/FailoverBaseCase.java
@@ -20,57 +20,53 @@
*/
package org.apache.qpid.test;
-import org.apache.qpid.test.VMTestCase;
import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.jndi.PropertiesFileInitialContextFactory;
import org.apache.qpid.server.registry.ApplicationRegistry;
+import org.apache.qpid.testutil.QpidTestCase;
-import javax.naming.spi.InitialContextFactory;
-import javax.naming.NamingException;
-import java.util.Hashtable;
-import java.util.Map;
+import javax.jms.Connection;
-public class FailoverBaseCase extends VMTestCase
+public class FailoverBaseCase extends QpidTestCase
{
- private boolean failedOver = true;
+ protected long RECEIVE_TIMEOUT = 1000l;
- public void setUp() throws Exception
+ protected void setUp() throws java.lang.Exception
{
- // Make Broker 2 the first one so we can kill it and allow VMTestCase to clean up vm://:1
- _brokerlist = "vm://:2;vm://:1";
- _clientID = this.getClass().getName();
- _virtualhost = "/test";
-
- _connections.put("connection1", "amqp://guest:guest@" + _clientID + _virtualhost + "?brokerlist='vm://:1'");
- _connections.put("connection2", "amqp://guest:guest@" + _clientID + _virtualhost + "?brokerlist='vm://:2'");
-
- try
- {
- TransportConnection.createVMBroker(2);
- }
- catch (Exception e)
+ super.setUp();
+ if( _broker.equals(VM) )
{
- fail("Unable to create broker: " + e);
+ System.getProperties().setProperty("amqj.AutoCreateVMBroker", "true");
}
-
- super.setUp();
}
- public void tearDown() throws Exception
+ /**
+ * We are using failover factories, Note that 0.10 code path does not yet support failover.
+ *
+ * @return a connection
+ * @throws Exception
+ */
+ public Connection getConnection() throws Exception
{
- if (!failedOver)
+ Connection conn;
+ if( _broker.equals(VM) )
{
- TransportConnection.killVMBroker(2);
- ApplicationRegistry.remove(2);
+ conn = getConnectionFactory("vmfailover").createConnection("guest", "guest");
}
- super.tearDown();
+ else
+ {
+ conn = getConnectionFactory("failover").createConnection("guest", "guest");
+ }
+ _connections.add(conn);
+ return conn;
}
-
+ /**
+ * Only used of VM borker.
+ * // TODO: update the failover mechanism once 0.10 provides support for failover.
+ */
public void failBroker()
{
- failedOver = true;
- TransportConnection.killVMBroker(2);
- ApplicationRegistry.remove(2);
+ TransportConnection.killVMBroker(1);
+ ApplicationRegistry.remove(1);
}
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/CancelTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/CancelTest.java
index 2b02f1cbbf..7b6d6eadba 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/CancelTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/CancelTest.java
@@ -22,19 +22,17 @@
package org.apache.qpid.test.client;
import org.apache.log4j.Logger;
-import org.apache.qpid.test.VMTestCase;
+import org.apache.qpid.testutil.QpidTestCase;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.QueueBrowser;
import javax.jms.Session;
-import javax.jms.JMSException;
-import javax.naming.NamingException;
import java.util.Enumeration;
-public class CancelTest extends VMTestCase
+
+public class CancelTest extends QpidTestCase
{
private static final Logger _logger = Logger.getLogger(CancelTest.class);
@@ -47,10 +45,10 @@ public class CancelTest extends VMTestCase
super.setUp();
- _queue = (Queue) _context.lookup("queue");
+ _queue = (Queue) getInitialContext().lookup("queue");
//Create Client
- _clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
+ _clientConnection = getConnection();
_clientConnection.start();
@@ -62,10 +60,13 @@ public class CancelTest extends VMTestCase
/**
* Simply
+ * This test originally did not assert anything but was just checking
+ * that a message could be browsed and consumed without throwing an exception.
+ * It now checks that at least a message is browsed and that a message is received.
*/
- public void test() throws JMSException, NamingException
+ public void test() throws Exception
{
- Connection producerConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
+ Connection producerConnection = getConnection();
producerConnection.start();
@@ -78,6 +79,7 @@ public class CancelTest extends VMTestCase
QueueBrowser browser = _clientSession.createBrowser(_queue);
Enumeration e = browser.getEnumeration();
+ assertTrue(e.hasMoreElements());
while (e.hasMoreElements())
{
@@ -87,25 +89,7 @@ public class CancelTest extends VMTestCase
browser.close();
MessageConsumer consumer = _clientSession.createConsumer(_queue);
- consumer.receive();
+ assertNotNull( consumer.receive() );
consumer.close();
}
-
- public void loop()
- {
- try
- {
- int run = 0;
- while (true)
- {
- System.err.println(run++);
- test();
- }
- }
- catch (Exception e)
- {
- _logger.error(e, e);
- }
- }
-
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java
index 9ffac5e084..57370f490f 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/DupsOkTest.java
@@ -1,12 +1,11 @@
package org.apache.qpid.test.client;
import org.apache.qpid.AMQException;
+import org.apache.qpid.testutil.QpidTestCase;
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQSession;
-import org.apache.qpid.test.VMTestCase;
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
@@ -15,32 +14,35 @@ import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
import javax.jms.TextMessage;
-import javax.naming.NamingException;
-import java.util.concurrent.CountDownLatch;/*
- *
- * Licensed to the Apache Software Foundation (ASF) under one
- * or more contributor license agreements. See the NOTICE file
- * distributed with this work for additional information
- * regarding copyright ownership. The ASF licenses this file
- * to you under the Apache License, Version 2.0 (the
- * "License"); you may not use this file except in compliance
- * with the License. You may obtain a copy of the License at
- *
- * http://www.apache.org/licenses/LICENSE-2.0
- *
- * Unless required by applicable law or agreed to in writing,
- * software distributed under the License is distributed on an
- * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
- * KIND, either express or implied. See the License for the
- * specific language governing permissions and limitations
- * under the License.
- *
- */
-
-public class DupsOkTest extends VMTestCase
+import java.util.concurrent.CountDownLatch;
+import java.util.concurrent.TimeUnit;
+
+/*
+*
+* Licensed to the Apache Software Foundation (ASF) under one
+* or more contributor license agreements. See the NOTICE file
+* distributed with this work for additional information
+* regarding copyright ownership. The ASF licenses this file
+* to you under the Apache License, Version 2.0 (the
+* "License"); you may not use this file except in compliance
+* with the License. You may obtain a copy of the License at
+*
+* http://www.apache.org/licenses/LICENSE-2.0
+*
+* Unless required by applicable law or agreed to in writing,
+* software distributed under the License is distributed on an
+* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+* KIND, either express or implied. See the License for the
+* specific language governing permissions and limitations
+* under the License.
+*
+*/
+
+public class DupsOkTest extends QpidTestCase
{
private Queue _queue;
+ // Question why do we need to send so many messages?
private static final int MSG_COUNT = 4999;
private CountDownLatch _awaitCompletion = new CountDownLatch(1);
@@ -48,13 +50,11 @@ public class DupsOkTest extends VMTestCase
{
super.setUp();
- _queue = (Queue) _context.lookup("queue");
+ _queue = (Queue) getInitialContext().lookup("queue");
- //CreateQueue
- ((ConnectionFactory) _context.lookup("connection")).createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(_queue).close();
//Create Producer put some messages on the queue
- Connection producerConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
+ Connection producerConnection = getConnection();
producerConnection.start();
@@ -72,10 +72,17 @@ public class DupsOkTest extends VMTestCase
producerConnection.close();
}
- public void testDupsOK() throws NamingException, JMSException, InterruptedException, AMQException
+ /**
+ * This test sends x messages and receives them with an async consumer.
+ * Waits for all messages to be received or for 60 s
+ * and checks whether the queue is empty.
+ *
+ * @throws Exception
+ */
+ public void testDupsOK() throws Exception
{
//Create Client
- Connection clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
+ Connection clientConnection = getConnection();
clientConnection.start();
@@ -98,26 +105,18 @@ public class DupsOkTest extends VMTestCase
if (message instanceof TextMessage)
{
try
- {
- /*if (message.getIntProperty("count") == 5000)
- {
- assertEquals("The queue should have 4999 msgs left", 4999, getMessageCount(_queue.getQueueName()));
- }*/
-
+ {
if (message.getIntProperty("count") == MSG_COUNT)
{
try
{
long remainingMessages = ((AMQSession) clientSession).getQueueDepth((AMQDestination) _queue);
- if(remainingMessages != 0)
- {
-
- assertEquals("The queue should have 0 msgs left, seen " + _msgCount + " messages.", 0, getMessageCount(_queue.getQueueName()));
- }
+ fail("The queue should have 0 msgs left, seen " + _msgCount + " messages, left: "
+ + remainingMessages);
}
catch (AMQException e)
{
- assertNull("Got AMQException", e);
+ fail("Got AMQException" + e.getMessage());
}
finally
{
@@ -134,27 +133,21 @@ public class DupsOkTest extends VMTestCase
}
else
{
- fail("");
+ fail("Got wrong message type");
}
}
});
try
{
- _awaitCompletion.await();
+ _awaitCompletion.await(60, TimeUnit.SECONDS);
}
catch (InterruptedException e)
{
fail("Unable to wait for test completion");
throw e;
}
-
-// consumer.close();
-
assertEquals("The queue should have 0 msgs left", 0, ((AMQSession) clientSession).getQueueDepth((AMQDestination) _queue));
- clientConnection.close();
-
}
-
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java
index 9beaa9844a..2dbac84fc5 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserAutoAckTest.java
@@ -53,19 +53,24 @@ public class QueueBrowserAutoAckTest extends FailoverBaseCase
{
super.setUp();
- _queue = (Queue) _context.lookup("queue");
+ _queue = (Queue) getInitialContext().lookup("queue");
//Create Client
- _clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
+ _clientConnection = getConnection();
_clientConnection.start();
- _clientSession = _clientConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ setupSession();
//Ensure there are no messages on the queue to start with.
checkQueueDepth(0);
}
+ protected void setupSession() throws Exception
+ {
+ _clientSession = _clientConnection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+ }
+
public void tearDown() throws Exception
{
if (_clientConnection != null)
@@ -81,9 +86,9 @@ public class QueueBrowserAutoAckTest extends FailoverBaseCase
Connection producerConnection = null;
try
{
- producerConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
+ producerConnection = getConnection();
}
- catch (NamingException e)
+ catch (Exception e)
{
fail("Unable to lookup connection in JNDI.");
}
@@ -96,10 +101,11 @@ public class QueueBrowserAutoAckTest extends FailoverBaseCase
Connection producerConnection = null;
try
{
- producerConnection = ((ConnectionFactory) _context.lookup(connection)).createConnection();
+ producerConnection = getConnectionFactory(connection).createConnection("guest", "guest");
}
- catch (NamingException e)
+ catch (Exception e)
{
+ e.printStackTrace();
fail("Unable to lookup connection in JNDI.");
}
sendMessages(producerConnection, num);
@@ -285,9 +291,9 @@ public class QueueBrowserAutoAckTest extends FailoverBaseCase
try
{
- connection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
+ connection = getConnection();
}
- catch (NamingException e)
+ catch (Exception e)
{
fail("Unable to make validation connection");
}
@@ -415,7 +421,7 @@ public class QueueBrowserAutoAckTest extends FailoverBaseCase
public void testFailoverWithQueueBrowser() throws JMSException
{
- int messages = 50;
+ int messages = 5;
sendMessages("connection1", messages);
sendMessages("connection2", messages);
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserClientAckTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserClientAckTest.java
index 0ef0217234..d346aa514c 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserClientAckTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserClientAckTest.java
@@ -20,30 +20,18 @@
*/
package org.apache.qpid.test.client;
-import javax.jms.Queue;
-import javax.jms.ConnectionFactory;
import javax.jms.Session;
public class QueueBrowserClientAckTest extends QueueBrowserAutoAckTest
{
- public void setUp() throws Exception
- {
-
- super.setUp();
-
- _clientConnection.close();
- _clientSession.close();
-
- _queue = (Queue) _context.lookup("queue");
- //Create Client
- _clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
- _clientConnection.start();
-
- _clientSession = _clientConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
+ protected void setupSession() throws Exception
+ {
+ _clientSession = _clientConnection.createSession(false, Session.CLIENT_ACKNOWLEDGE);
//Ensure _queue is created
_clientSession.createConsumer(_queue).close();
}
+
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserDupsOkTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserDupsOkTest.java
index 80d74b1b79..37174258dd 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserDupsOkTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserDupsOkTest.java
@@ -20,28 +20,13 @@
*/
package org.apache.qpid.test.client;
-import javax.jms.Queue;
-import javax.jms.ConnectionFactory;
import javax.jms.Session;
public class QueueBrowserDupsOkTest extends QueueBrowserAutoAckTest
{
- public void setUp() throws Exception
+ protected void setupSession() throws Exception
{
-
- super.setUp();
-
- _clientConnection.close();
- _clientSession.close();
-
- _queue = (Queue) _context.lookup("queue");
-
- //Create Client
- _clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
-
- _clientConnection.start();
-
- _clientSession = _clientConnection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
+ _clientSession = _clientConnection.createSession(false, Session.DUPS_OK_ACKNOWLEDGE);
//Ensure _queue is created
_clientSession.createConsumer(_queue).close();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserNoAckTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserNoAckTest.java
index 1bc5f07b4e..0ef788dae3 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserNoAckTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserNoAckTest.java
@@ -22,27 +22,13 @@ package org.apache.qpid.test.client;
import org.apache.qpid.client.AMQSession;
-import javax.jms.ConnectionFactory;
-import javax.jms.Queue;
public class QueueBrowserNoAckTest extends QueueBrowserAutoAckTest
{
- public void setUp() throws Exception
- {
-
- super.setUp();
-
- _clientConnection.close();
- _clientSession.close();
-
- _queue = (Queue) _context.lookup("queue");
- //Create Client
- _clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
-
- _clientConnection.start();
-
- _clientSession = _clientConnection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
+ protected void setupSession() throws Exception
+ {
+ _clientSession = _clientConnection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
//Ensure _queue is created
_clientSession.createConsumer(_queue).close();
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserPreAckTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserPreAckTest.java
index 42e13c89e4..787c12dadb 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserPreAckTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserPreAckTest.java
@@ -22,29 +22,11 @@ package org.apache.qpid.test.client;
import org.apache.qpid.client.AMQSession;
-import javax.jms.Queue;
-import javax.jms.ConnectionFactory;
-
public class QueueBrowserPreAckTest extends QueueBrowserAutoAckTest
{
- public void setUp() throws Exception
- {
-
- super.setUp();
-
- _clientConnection.close();
- _clientSession.close();
-
- _clientConnection.close();
- _clientSession.close();
-
- _queue = (Queue) _context.lookup("queue");
-
- //Create Client
- _clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
-
- _clientConnection.start();
+ protected void setupSession() throws Exception
+ {
_clientSession = _clientConnection.createSession(false, AMQSession.PRE_ACKNOWLEDGE);
//Ensure _queue is created
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTransactedTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTransactedTest.java
index 0d63373e61..6e3d6fd890 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTransactedTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/client/QueueBrowserTransactedTest.java
@@ -20,32 +20,15 @@
*/
package org.apache.qpid.test.client;
-import javax.jms.Queue;
-import javax.jms.ConnectionFactory;
import javax.jms.Session;
public class QueueBrowserTransactedTest extends QueueBrowserAutoAckTest
-{
- public void setUp() throws Exception
+{
+ protected void setupSession() throws Exception
{
-
- super.setUp();
-
- _clientConnection.close();
- _clientSession.close();
-
- _queue = (Queue) _context.lookup("queue");
-
- //Create Client
- _clientConnection = ((ConnectionFactory) _context.lookup("connection")).createConnection();
-
- _clientConnection.start();
-
_clientSession = _clientConnection.createSession(true, Session.SESSION_TRANSACTED);
//Ensure _queue is created
_clientSession.createConsumer(_queue).close();
}
-
-
}
diff --git a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/ack/AcknowledgeTest.java b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/ack/AcknowledgeTest.java
index 8fddf651b4..4852cab3a6 100644
--- a/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/ack/AcknowledgeTest.java
+++ b/qpid/java/systests/src/main/java/org/apache/qpid/test/unit/ack/AcknowledgeTest.java
@@ -22,25 +22,20 @@ package org.apache.qpid.test.unit.ack;
*/
import javax.jms.Connection;
-import javax.jms.ConnectionFactory;
import javax.jms.JMSException;
import javax.jms.Message;
import javax.jms.MessageConsumer;
import javax.jms.MessageProducer;
import javax.jms.Queue;
import javax.jms.Session;
-import javax.jms.TextMessage;
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnectionFactory;
import org.apache.qpid.client.AMQDestination;
-import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.server.registry.ApplicationRegistry;
-import org.apache.qpid.test.VMTestCase;
+import org.apache.qpid.testutil.QpidTestCase;
-public class AcknowledgeTest extends VMTestCase
+public class AcknowledgeTest extends QpidTestCase
{
private static final int NUM_MESSAGES = 50;
private Connection _con;
@@ -49,19 +44,15 @@ public class AcknowledgeTest extends VMTestCase
private Session _producerSession;
private Session _consumerSession;
private MessageConsumer _consumerA;
- private MessageConsumer _consumerB;
@Override
protected void setUp() throws Exception
{
super.setUp();
- _queue = (Queue) _context.lookup("queue");
-
- //CreateQueue
- ((ConnectionFactory) _context.lookup("connection")).createConnection().createSession(false, Session.AUTO_ACKNOWLEDGE).createConsumer(_queue).close();
+ _queue = (Queue) getInitialContext().lookup("queue");
//Create Producer put some messages on the queue
- _con = ((ConnectionFactory) _context.lookup("connection")).createConnection();
+ _con = getConnection();
_con.start();
}
@@ -88,16 +79,6 @@ public class AcknowledgeTest extends VMTestCase
}
- private void consumeMessages(int toConsume, MessageConsumer consumer) throws JMSException
- {
- Message msg;
- for (int i = 0; i < toConsume; i++)
- {
- msg = consumer.receive(1000);
- assertNotNull("Message " + i + " was null!", msg);
- assertEquals("message " + i, ((TextMessage) msg).getText());
- }
- }
private void sendMessages(int totalMessages) throws JMSException
{
@@ -107,15 +88,22 @@ public class AcknowledgeTest extends VMTestCase
}
}
+ /**
+ * Produces and consumes messages an either ack or commit the receipt of those messages
+ *
+ * @param transacted
+ * @param mode
+ * @throws Exception
+ */
private void testMessageAck(boolean transacted, int mode) throws Exception
{
init(transacted, mode);
sendMessages(NUM_MESSAGES/2);
Thread.sleep(1500);
- _consumerB = _consumerSession.createConsumer(_queue);
+ MessageConsumer consumerB = _consumerSession.createConsumer(_queue);
sendMessages(NUM_MESSAGES/2);
int count = 0;
- Message msg = _consumerB.receive(1500);
+ Message msg = consumerB.receive(1500);
while (msg != null)
{
if (mode == Session.CLIENT_ACKNOWLEDGE)
@@ -123,14 +111,14 @@ public class AcknowledgeTest extends VMTestCase
msg.acknowledge();
}
count++;
- msg = _consumerB.receive(1500);
+ msg = consumerB.receive(1500);
}
if (transacted)
{
_consumerSession.commit();
}
_consumerA.close();
- _consumerB.close();
+ consumerB.close();
_consumerSession.close();
assertEquals("Wrong number of messages on queue", NUM_MESSAGES - count,
((AMQSession) _producerSession).getQueueDepth((AMQDestination) _queue));
@@ -153,7 +141,6 @@ public class AcknowledgeTest extends VMTestCase
_consumerSession.commit();
}
_consumerSession.close();
- super.tearDown();
}
public void test2ConsumersAutoAck() throws Exception
diff --git a/qpid/java/test-provider.properties b/qpid/java/test-provider.properties
index 38cc146ae6..6babe6b6c8 100644
--- a/qpid/java/test-provider.properties
+++ b/qpid/java/test-provider.properties
@@ -1,6 +1,14 @@
connectionfactory.local = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5672'
+connectionfactory.vm = amqp://username:password@clientid/test?brokerlist='vm://:1'
+
+connectionfactory.failover = amqp://username:password@clientid/test?brokerlist='tcp://localhost:5672'
+connectionfactory.vmfailover = amqp://username:password@clientid/test?brokerlist='vm://:2;vm://:1'
+connectionfactory.connection1 = amqp://username:password@clientid/test?brokerlist='vm://:1'
+connectionfactory.connection2 = amqp://username:password@clientid/test?brokerlist='vm://:2'
+
queue.MyQueue = example.MyQueue
+queue.queue = example.queue
queue.xaQueue = xaQueue
topic.xaTopic = xaTopic