summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMartin Ritchie <ritchiem@apache.org>2006-11-08 12:12:24 +0000
committerMartin Ritchie <ritchiem@apache.org>2006-11-08 12:12:24 +0000
commitc1b89dc0334fc628004b4c2fa9ade2f29f764b40 (patch)
tree6ec21c16f2e0e1e0b9ff1fff80f6cfe39c1515bf
parent266dbad25f87e25f6066d7447e74066e70324010 (diff)
downloadqpid-python-c1b89dc0334fc628004b4c2fa9ade2f29f764b40.tar.gz
Moved Unit test to test/unit package.
Added TestMessageHelper.java to allow access to package only methods whilst keeping test in the correct package. git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid/java@472458 13f79535-47bb-0310-9956-ffa450edef68
-rw-r--r--client/test/src/org/apache/qpid/client/message/TestMessageHelper.java34
-rw-r--r--client/test/src/org/apache/qpid/destinationurl/UnitTests.java33
-rw-r--r--client/test/src/org/apache/qpid/failover/FailoverBrokerTester.java268
-rw-r--r--client/test/src/org/apache/qpid/failover/FailoverMultiMethodTest.java258
-rw-r--r--client/test/src/org/apache/qpid/failover/FailoverRoundRobinTest.java233
-rw-r--r--client/test/src/org/apache/qpid/failover/FailoverSingleServerTest.java257
-rw-r--r--client/test/src/org/apache/qpid/failover/FailoverTest.java249
-rw-r--r--client/test/src/org/apache/qpid/failover/FailoverTxTest.java179
-rw-r--r--client/test/src/org/apache/qpid/framing/FieldTableTest.java160
-rw-r--r--client/test/src/org/apache/qpid/test/unit/ack/DisconnectAndRedeliverTest.java (renamed from client/test/src/org/apache/qpid/ack/DisconnectAndRedeliverTest.java)2
-rw-r--r--client/test/src/org/apache/qpid/test/unit/ack/RecoverTest.java (renamed from client/test/src/org/apache/qpid/ack/RecoverTest.java)2
-rw-r--r--client/test/src/org/apache/qpid/test/unit/ack/UnitTests.java (renamed from client/test/src/org/apache/qpid/ack/UnitTests.java)2
-rw-r--r--client/test/src/org/apache/qpid/test/unit/basic/BytesMessageTest.java (renamed from client/test/src/org/apache/qpid/basic/BytesMessageTest.java)4
-rw-r--r--client/test/src/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java (renamed from client/test/src/org/apache/qpid/basic/FieldTableKeyEnumeratorTest.java)6
-rw-r--r--client/test/src/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java (renamed from client/test/src/org/apache/qpid/basic/FieldTableMessageTest.java)5
-rw-r--r--client/test/src/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java (renamed from client/test/src/org/apache/qpid/basic/MultipleConnectionTest.java)42
-rw-r--r--client/test/src/org/apache/qpid/test/unit/basic/ObjectMessageTest.java (renamed from client/test/src/org/apache/qpid/basic/ObjectMessageTest.java)13
-rw-r--r--client/test/src/org/apache/qpid/test/unit/basic/ReceiveTest.java (renamed from client/test/src/org/apache/qpid/basic/ReceiveTest.java)41
-rw-r--r--client/test/src/org/apache/qpid/test/unit/basic/SessionStartTest.java (renamed from client/test/src/org/apache/qpid/basic/SessionStartTest.java)13
-rw-r--r--client/test/src/org/apache/qpid/test/unit/basic/TextMessageTest.java (renamed from client/test/src/org/apache/qpid/basic/TextMessageTest.java)14
-rw-r--r--client/test/src/org/apache/qpid/test/unit/basic/UnitTests.java (renamed from client/test/src/org/apache/qpid/basic/UnitTests.java)2
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/AMQConnectionTest.java (renamed from client/test/src/org/apache/qpid/client/TestAMQConnection.java)280
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/AMQSessionTest.java (renamed from client/test/src/org/apache/qpid/client/TestAMQSession.java)274
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/AllClientUnitTests.java (renamed from client/test/src/org/apache/qpid/client/AllClientUnitTests.java)22
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java (renamed from client/test/src/org/apache/qpid/client/channelclose/ChannelCloseOkTest.java)2
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/channelclose/UnitTests.java (renamed from client/test/src/org/apache/qpid/client/channelclose/UnitTests.java)2
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/connection/ConnectionTest.java (renamed from client/test/src/org/apache/qpid/connection/ConnectionTest.java)58
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/connection/TestManyConnections.java (renamed from client/test/src/org/apache/qpid/connection/TestManyConnections.java)2
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java (renamed from client/test/src/org/apache/qpid/connectionurl/ConnectionURLTest.java)22
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/connectionurl/UnitTests.java (renamed from client/test/src/org/apache/qpid/connectionurl/UnitTests.java)5
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java (renamed from client/test/src/org/apache/qpid/destinationurl/DestinationURLTest.java)2
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/destinationurl/UnitTests.java (renamed from client/test/src/org/apache/qpid/client/message/UnitTests.java)6
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/forwardall/Client.java (renamed from client/test/src/org/apache/qpid/forwardall/Client.java)2
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java (renamed from client/test/src/org/apache/qpid/forwardall/Combined.java)6
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/forwardall/Service.java (renamed from client/test/src/org/apache/qpid/forwardall/Service.java)2
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/forwardall/ServiceCreator.java (renamed from client/test/src/org/apache/qpid/forwardall/ServiceCreator.java)2
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/forwardall/SpecialQueue.java (renamed from client/test/src/org/apache/qpid/forwardall/SpecialQueue.java)2
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/forwardall/UnitTests.java (renamed from client/test/src/org/apache/qpid/forwardall/UnitTests.java)4
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/message/BytesMessageTest.java (renamed from client/test/src/org/apache/qpid/client/message/TestBytesMessage.java)54
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/message/MessageUnitTests.java35
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java (renamed from client/test/src/org/apache/qpid/client/message/ObjectMessageTest.java)65
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/message/TextMessageTest.java (renamed from client/test/src/org/apache/qpid/client/message/TestTextMessage.java)12
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java (renamed from client/test/src/org/apache/qpid/client/protocol/TestAMQProtocolSession.java)230
-rw-r--r--client/test/src/org/apache/qpid/test/unit/client/protocol/TestIoSession.java (renamed from client/test/src/org/apache/qpid/client/protocol/TestIoSession.java)192
-rw-r--r--client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java210
-rw-r--r--client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java123
-rw-r--r--client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Lookup.java136
-rw-r--r--client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Unbind.java158
-rw-r--r--client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java32
-rw-r--r--client/test/src/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java (renamed from client/test/src/org/apache/qpid/topic/DurableSubscriptionTest.java)39
-rw-r--r--client/test/src/org/apache/qpid/test/unit/transacted/TransactedTest.java (renamed from client/test/src/org/apache/qpid/transacted/TransactedTest.java)4
-rw-r--r--client/test/src/org/apache/qpid/test/unit/transacted/UnitTests.java (renamed from client/test/src/org/apache/qpid/transacted/UnitTests.java)2
52 files changed, 1537 insertions, 2265 deletions
diff --git a/client/test/src/org/apache/qpid/client/message/TestMessageHelper.java b/client/test/src/org/apache/qpid/client/message/TestMessageHelper.java
new file mode 100644
index 0000000000..669bfd7a5f
--- /dev/null
+++ b/client/test/src/org/apache/qpid/client/message/TestMessageHelper.java
@@ -0,0 +1,34 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ */
+package org.apache.qpid.client.message;
+
+import javax.jms.JMSException;
+
+public class TestMessageHelper
+{
+ public static JMSTextMessage newJMSTextMessage() throws JMSException
+ {
+ return new JMSTextMessage();
+ }
+
+ public static JMSBytesMessage newJMSBytesMessage() throws JMSException
+ {
+ return new JMSBytesMessage();
+ }
+
+}
diff --git a/client/test/src/org/apache/qpid/destinationurl/UnitTests.java b/client/test/src/org/apache/qpid/destinationurl/UnitTests.java
deleted file mode 100644
index 12760aef94..0000000000
--- a/client/test/src/org/apache/qpid/destinationurl/UnitTests.java
+++ /dev/null
@@ -1,33 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-package org.apache.qpid.destinationurl;
-
-import org.junit.runner.RunWith;
-import org.junit.runners.Suite;
-import org.apache.qpid.ack.*;
-import junit.framework.JUnit4TestAdapter;
-
-@RunWith(Suite.class)
-@Suite.SuiteClasses({DestinationURLTest.class})
-public class UnitTests
-{
- public static junit.framework.Test suite()
- {
- return new JUnit4TestAdapter(org.apache.qpid.destinationurl.UnitTests.class);
- }
-}
diff --git a/client/test/src/org/apache/qpid/failover/FailoverBrokerTester.java b/client/test/src/org/apache/qpid/failover/FailoverBrokerTester.java
deleted file mode 100644
index 96c863fae4..0000000000
--- a/client/test/src/org/apache/qpid/failover/FailoverBrokerTester.java
+++ /dev/null
@@ -1,268 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-package org.apache.qpid.failover;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
-
-public class FailoverBrokerTester implements Runnable
-{
- private static final Logger _logger = Logger.getLogger(FailoverBrokerTester.class);
-
- private int[] _brokers;
- private int[] _brokersKilling;
- private long _delayBeforeKillingStart;
- private long _delayBetweenCullings;
- private long _delayBetweenRecreates;
- private boolean _recreateBrokers;
- private long _delayBeforeReCreationStart;
-
- private volatile boolean RUNNING;
-
-
- /**
- * An InVM Broker Tester. Creates then kills VM brokers to allow failover testing.
- *
- * @param brokerCount The number of brokers to create
- * @param delay The delay before and between broker killings
- */
- public FailoverBrokerTester(int brokerCount, long delay)
- {
- this(brokerCount, delay, delay, false, 0, 0);
- }
-
- /**
- * An InVM Broker Tester. Creates then kills VM brokers to allow failover testing.
- *
- * @param brokerCount The number of brokers
- * @param delayBeforeKillingStart
- * @param delayBetweenCullings
- * @param recreateBrokers
- * @param delayBeforeReCreationStart
- * @param delayBetweenRecreates
- */
- public FailoverBrokerTester(int brokerCount, long delayBeforeKillingStart,
- long delayBetweenCullings, boolean recreateBrokers,
- long delayBeforeReCreationStart, long delayBetweenRecreates)
- {
- int[] brokers = new int[brokerCount];
-
- for (int n = 0; n < brokerCount; n++)
- {
- brokers[n] = n + 1;
- }
- _brokersKilling = _brokers = brokers;
- _recreateBrokers = recreateBrokers;
- _delayBeforeKillingStart = delayBeforeKillingStart;
- _delayBetweenCullings = delayBetweenCullings;
- _delayBetweenRecreates = delayBetweenRecreates;
- _delayBeforeReCreationStart = delayBeforeReCreationStart;
-
- createWorld();
- }
-
- /**
- * An InVM Broker Tester. Creates then kills VM brokers to allow failover testing.
- *
- * @param brokerArray Array for broker creation and killing order
- * @param delayBeforeKillingStart
- * @param delayBetweenCullings
- * @param recreateBrokers
- * @param delayBeforeReCreationStart
- * @param delayBetweenRecreates
- */
- public FailoverBrokerTester(int[] brokerArray, long delayBeforeKillingStart,
- long delayBetweenCullings, boolean recreateBrokers,
- long delayBeforeReCreationStart, long delayBetweenRecreates)
- {
- _brokersKilling = _brokers = brokerArray;
- _recreateBrokers = recreateBrokers;
- _delayBeforeKillingStart = delayBeforeKillingStart;
- _delayBetweenCullings = delayBetweenCullings;
- _delayBetweenRecreates = delayBetweenRecreates;
- _delayBeforeReCreationStart = delayBeforeReCreationStart;
-
- createWorld();
- }
-
- /**
- * An InVM Broker Tester. Creates then kills VM brokers to allow failover testing.
- *
- * @param brokerCreateOrder Array for broker creation order
- * @param brokerKillOrder Array for broker killing order
- * @param delayBeforeKillingStart
- * @param delayBetweenCullings
- * @param recreateBrokers
- * @param delayBeforeReCreationStart
- * @param delayBetweenRecreates
- */
- public FailoverBrokerTester(int[] brokerCreateOrder, int[] brokerKillOrder, long delayBeforeKillingStart,
- long delayBetweenCullings, boolean recreateBrokers,
- long delayBeforeReCreationStart, long delayBetweenRecreates)
- {
- _brokers = brokerCreateOrder;
- _brokersKilling = brokerKillOrder;
- _recreateBrokers = recreateBrokers;
- _delayBeforeKillingStart = delayBeforeKillingStart;
- _delayBetweenCullings = delayBetweenCullings;
- _delayBetweenRecreates = delayBetweenRecreates;
- _delayBeforeReCreationStart = delayBeforeReCreationStart;
-
- createWorld();
- }
-
- private void createWorld()
- {
- genesis();
-
- Thread brokerGod = new Thread(this);
- brokerGod.setName("Broker God");
- brokerGod.start();
- }
-
-
- private void genesis()
- {
- _logger.info("Creating " + _brokers.length + " VM Brokers.");
- for (int count = 0; count < _brokers.length; count++)
- {
- try
- {
- TransportConnection.createVMBroker(_brokers[count]);
- }
- catch (AMQVMBrokerCreationException e)
- {
- ;
- }
- }
- }
-
- public void run()
- {
-
- RUNNING = true;
- try
- {
- _logger.info("Sleeping before culling starts.");
- Thread.sleep(_delayBeforeKillingStart);
- }
- catch (InterruptedException e)
- {
- _logger.info("Interupted sleeping before killing starts.");
- }
-
- Thread brokerGod = new Thread(new BrokerDestroyer());
- brokerGod.setName("Broker Destroyer");
- brokerGod.start();
-
- if (_recreateBrokers)
- {
- try
- {
- _logger.info("Sleeping before recreation starts.");
- Thread.sleep(_delayBeforeReCreationStart - _delayBeforeKillingStart);
- }
- catch (InterruptedException e)
- {
- _logger.info("Interupted sleeping before recreation starts.");
- }
-
- brokerGod = new Thread(new BrokerCreator());
- brokerGod.setName("Broker Creator");
- brokerGod.start();
- }
- }
-
-
- public void stopTesting()
- {
- _logger.info("Stopping Broker Tester.");
- RUNNING = false;
- }
-
- class BrokerCreator implements Runnable
- {
- public void run()
- {
- _logger.info("Created Broker Creator.");
- while (RUNNING)
- {
- for (int count = 0; count < _brokers.length; count++)
- {
- try
- {
- _logger.info("Creating Broker:" + _brokers[count]);
- TransportConnection.createVMBroker(_brokers[count]);
- }
- catch (AMQVMBrokerCreationException e)
- {
- _logger.info("Unable to recreate broker:" + count + ", Port:" + _brokers[count]);
- }
- try
- {
- Thread.sleep(_delayBetweenRecreates);
- }
- catch (InterruptedException e)
- {
- _logger.info("Interupted between broker recreates.");
- }
- }
- }
- _logger.info("Ending Broker Creator.");
- }
- }
-
- class BrokerDestroyer implements Runnable
- {
- public void run()
- {
- _logger.info("Created Broker Destroyer.");
- while (RUNNING)
- {
- for (int count = 0; count < _brokersKilling.length; count++)
- {
- _logger.info("Destroying Broker:" + _brokersKilling[count]);
- killNextBroker(_brokersKilling[count], _delayBetweenCullings);
- }
- }
- _logger.info("Ending Broker Destroyer.");
- }
-
- private void killNextBroker(int broker, long delay)
- {
-
- //Kill the broker
- TransportConnection.killVMBroker(broker);
-
- //Give the client time to get up and going
- try
- {
- Thread.sleep(delay);
- }
- catch (InterruptedException e)
- {
- _logger.info("Sleeping before broker killing was interrupted,");
- }
-
-
- }
- }
-
-
-}
diff --git a/client/test/src/org/apache/qpid/failover/FailoverMultiMethodTest.java b/client/test/src/org/apache/qpid/failover/FailoverMultiMethodTest.java
deleted file mode 100644
index b9f4c1c0dc..0000000000
--- a/client/test/src/org/apache/qpid/failover/FailoverMultiMethodTest.java
+++ /dev/null
@@ -1,258 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-package org.apache.qpid.failover;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.url.URLSyntaxException;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.jms.ConnectionListener;
-import org.apache.qpid.jms.ConnectionURL;
-
-import javax.jms.*;
-import java.util.Timer;
-import java.util.TimerTask;
-
-public class FailoverMultiMethodTest implements MessageListener, ConnectionListener
-{
- private static final long TIMEOUT = 10000;
- private static final long INTERVAL = 5000;
- private final Timer _timer = new Timer(true);
- private final Connection _connection;
- private final Session _session;
- private final MessageProducer _producer;
- private Timeout _timeout;
- private int _count;
-
- FailoverMultiMethodTest(String connectionString) throws JMSException, AMQException, URLSyntaxException
- {
- // Parse the incomming broker strings
-
- ConnectionURL connection = new AMQConnectionURL(connectionString);
-
- /*
- if (!(connection.getBrokerCount() > 0))
- {
- throw new IllegalArgumentException("BrokerDetails details must specify at least one broker");
- }
-
- // Create a FailoverMethod. In this case a SingleServer Method
- // This Method will retry the given server once before failing.
- FailoverMethod singleMethod = new FailoverSingleServer(connection);
-
- // Create the policy with the Failover Method
- FailoverPolicy policy = new FailoverPolicy(singleMethod);
-
- // Create a new method that will Cycle through all servers using the default values.
- FailoverMethod cycleMethod = new FailoverRoundRobinServers(connection);
-
- // Set the retry per server to 1
- cycleMethod.setRetries(1);
-
- // Add the failover method to the policy.
- policy.addMethod(cycleMethod);
-
- policy.setMethodRetries(1);
- */
-
- _connection = new AMQConnection(connection);
-
-
- ((AMQConnection) _connection).setConnectionListener(this);
-
- _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Topic topic = _session.createTopic("BLZ-24");
- Queue queue = _session.createTemporaryQueue();
- _producer = _session.createProducer(topic);
- _session.createConsumer(queue).setMessageListener(this);
- //new TopicListener(_session, topic);
- new TopicListener(_connection.createSession(false, Session.AUTO_ACKNOWLEDGE), topic);
-
- _connection.start();
-
- Message msg = _session.createTextMessage("Init");
- msg.setJMSReplyTo(queue);
- send(msg);
- }
-
- public synchronized void onMessage(Message message)
- {
- try
- {
- //cancel timeout:
- _timeout.clear();
- new DelayedSend(_session.createTextMessage("Message" + (++_count)), INTERVAL);
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
-
- private synchronized void send(Message msg) throws JMSException
- {
- _producer.send(msg);
- //start timeout:
- _timeout = new Timeout(TIMEOUT);
- }
-
- private void error(Exception e)
- {
- e.printStackTrace();
- stop();
- }
-
- private void stop()
- {
- System.out.println("Stopping...");
- try
- {
- _connection.close();
- }
- catch (JMSException e)
- {
- System.out.println("Failed to shutdown: " + e);
- e.printStackTrace();
- }
- }
-
- private void timeout()
- {
- error(new RuntimeException("Timed out: count = " + _count));
- }
-
- public void bytesSent(long count)
- {
- }
-
- public void bytesReceived(long count)
- {
- }
-
- public boolean preFailover(boolean redirect)
- {
- System.out.println("preFailover(" + redirect + ") called");
- return true;
- }
-
- public boolean preResubscribe()
- {
- System.out.println("preResubscribe() called");
- return true;
- }
-
- public void failoverComplete()
- {
- System.out.println("failoverComplete() called");
- }
-
- private class TopicListener implements MessageListener
- {
- private final Session _session;
- private MessageProducer _producer;
- private int _received;
-
- TopicListener(Session session, Topic topic) throws JMSException
- {
- _session = session;
- _session.createConsumer(topic).setMessageListener(this);
- }
-
- public void onMessage(Message message)
- {
- try
- {
- //if(_received++ % 100 == 0)
- {
- System.out.println("Received: " + ((TextMessage) message).getText());
- }
- if (_producer == null)
- {
- _producer = init(message);
- }
- reply(message);
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
-
- private void reply(Message message) throws JMSException
- {
- _producer.send(_session.createTextMessage(((TextMessage) message).getText()));
- }
-
- private MessageProducer init(Message message) throws JMSException
- {
- return _session.createProducer(message.getJMSReplyTo());
- }
- }
-
- private class Timeout extends TimerTask
- {
- private volatile boolean _cancelled;
-
- Timeout(long time)
- {
- _timer.schedule(this, time);
- }
-
- void clear()
- {
- _cancelled = true;
- }
-
- public void run()
- {
- if (!_cancelled)
- {
- timeout();
- }
- }
- }
-
- private class DelayedSend extends TimerTask
- {
- private final Message _msg;
-
- DelayedSend(Message msg, long delay)
- {
- _msg = msg;
- _timer.schedule(this, delay);
- }
-
- public void run()
- {
- try
- {
- send(_msg);
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
- }
-
- public static void main(final String[] argv) throws Exception
- {
- final String connection = argv.length == 0 ? "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'" : argv[0];
- new FailoverMultiMethodTest(connection);
- }
-}
diff --git a/client/test/src/org/apache/qpid/failover/FailoverRoundRobinTest.java b/client/test/src/org/apache/qpid/failover/FailoverRoundRobinTest.java
deleted file mode 100644
index 23119f2394..0000000000
--- a/client/test/src/org/apache/qpid/failover/FailoverRoundRobinTest.java
+++ /dev/null
@@ -1,233 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-package org.apache.qpid.failover;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.url.URLSyntaxException;
-import org.apache.qpid.jms.ConnectionURL;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.jms.ConnectionListener;
-
-import javax.jms.*;
-import java.util.Timer;
-import java.util.TimerTask;
-
-public class FailoverRoundRobinTest implements MessageListener, ConnectionListener
-{
- private static final long TIMEOUT = 10000;
- private static final long INTERVAL = 5000;
- private final Timer _timer = new Timer(true);
- private final Connection _connection;
- private final Session _session;
- private final MessageProducer _producer;
- private Timeout _timeout;
- private int _count;
-
-
- FailoverRoundRobinTest(String connectionString) throws JMSException, AMQException, URLSyntaxException
- {
- ConnectionURL connection = new AMQConnectionURL(connectionString);
- _connection = new AMQConnection(connection);
-
- ((AMQConnection) _connection).setConnectionListener(this);
-
- _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Topic topic = _session.createTopic("BLZ-24");
- Queue queue = _session.createTemporaryQueue();
- _producer = _session.createProducer(topic);
- _session.createConsumer(queue).setMessageListener(this);
- //new TopicListener(_session, topic);
- new TopicListener(_connection.createSession(false, Session.AUTO_ACKNOWLEDGE), topic);
- _connection.start();
-
- Message msg = _session.createTextMessage("Init");
- msg.setJMSReplyTo(queue);
- send(msg);
- }
-
- public synchronized void onMessage(Message message)
- {
- try
- {
- //cancel timeout:
- _timeout.clear();
- new DelayedSend(_session.createTextMessage("Message" + (++_count)), INTERVAL);
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
-
- private synchronized void send(Message msg) throws JMSException
- {
- _producer.send(msg);
- //start timeout:
- _timeout = new Timeout(TIMEOUT);
- }
-
- private void error(Exception e)
- {
- e.printStackTrace();
- stop();
- }
-
- private void stop()
- {
- System.out.println("Stopping...");
- try
- {
- _connection.close();
- }
- catch (JMSException e)
- {
- System.out.println("Failed to shutdown: " + e);
- e.printStackTrace();
- }
- }
-
- private void timeout()
- {
- error(new RuntimeException("Timed out: count = " + _count));
- }
-
- public void bytesSent(long count)
- {
- }
-
- public void bytesReceived(long count)
- {
- }
-
- public boolean preFailover(boolean redirect)
- {
- System.out.println("preFailover(" + redirect + ") called");
- return true;
- }
-
- public boolean preResubscribe()
- {
- System.out.println("preResubscribe() called");
- return true;
- }
-
- public void failoverComplete()
- {
- System.out.println("failoverComplete() called");
- }
-
- private class TopicListener implements MessageListener
- {
- private final Session _session;
- private MessageProducer _producer;
- private int _received;
-
- TopicListener(Session session, Topic topic) throws JMSException
- {
- _session = session;
- _session.createConsumer(topic).setMessageListener(this);
- }
-
- public void onMessage(Message message)
- {
- try
- {
- //if(_received++ % 100 == 0)
- {
- System.out.println("Received: " + ((TextMessage) message).getText());
- }
- if (_producer == null)
- {
- _producer = init(message);
- }
- reply(message);
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
-
- private void reply(Message message) throws JMSException
- {
- _producer.send(_session.createTextMessage(((TextMessage) message).getText()));
- }
-
- private MessageProducer init(Message message) throws JMSException
- {
- return _session.createProducer(message.getJMSReplyTo());
- }
- }
-
- private class Timeout extends TimerTask
- {
- private volatile boolean _cancelled;
-
- Timeout(long time)
- {
- _timer.schedule(this, time);
- }
-
- void clear()
- {
- _cancelled = true;
- }
-
- public void run()
- {
- if (!_cancelled)
- {
- timeout();
- }
- }
- }
-
- private class DelayedSend extends TimerTask
- {
- private final Message _msg;
-
- DelayedSend(Message msg, long delay)
- {
- _msg = msg;
- _timer.schedule(this, delay);
- }
-
- public void run()
- {
- try
- {
- send(_msg);
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
- }
-
- public static void main(final String[] argv) throws Exception
- {
- //Default failover is to use single server
- String url = "amqp://guest:guest@test/clientID?"+
- "brokerlist='tcp://localhost:5672?retries='2';"+
- "tcp://localhost:5673''&failover='roundrobin'";
- final String broker = argv.length == 0? url : argv[0];
- new FailoverRoundRobinTest(broker);
- }
-}
diff --git a/client/test/src/org/apache/qpid/failover/FailoverSingleServerTest.java b/client/test/src/org/apache/qpid/failover/FailoverSingleServerTest.java
deleted file mode 100644
index 7f3b058438..0000000000
--- a/client/test/src/org/apache/qpid/failover/FailoverSingleServerTest.java
+++ /dev/null
@@ -1,257 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-package org.apache.qpid.failover;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.url.URLSyntaxException;
-import org.apache.qpid.jms.ConnectionURL;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.jms.*;
-
-import javax.jms.*;
-import javax.jms.Connection;
-import javax.jms.MessageProducer;
-import javax.jms.Session;
-import java.util.Timer;
-import java.util.TimerTask;
-
-public class FailoverSingleServerTest implements MessageListener, ConnectionListener
-{
- private static final long TIMEOUT = 10000;
- private static final long INTERVAL = 5000;
- private final Timer _timer = new Timer(true);
- private final Connection _connection;
- private final Session _session;
- private final MessageProducer _producer;
- private Timeout _timeout;
- private int _count;
-
- private
-
-
- FailoverSingleServerTest(String connectionString) throws JMSException, AMQException, URLSyntaxException
- {
-
-
- ConnectionURL connection = new AMQConnectionURL(connectionString);
-
-/*
- BrokerDetails[] details = BrokerDetails.parseBrokerDetails(brokers);
-
-
-
- if (!(details.length > 0))
- {
- throw new IllegalArgumentException("BrokerDetails details must specify at least one broker");
- }
-
- // Create a cycling Server Failover that tries twice for the server
- FailoverMethod singleMethod = new FailoverSingleServer(details[0]);
-
- singleMethod.setRetries(2);
-
- FailoverPolicy policy = new FailoverPolicy(singleMethod);
-*/
-
-
- _connection = new AMQConnection(connection);
-
- ((AMQConnection) _connection).setConnectionListener(this);
- _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Topic topic = _session.createTopic("BLZ-24");
- Queue queue = _session.createTemporaryQueue();
- _producer = _session.createProducer(topic);
- _session.createConsumer(queue).setMessageListener(this);
- //new TopicListener(_session, topic);
- new TopicListener(_connection.createSession(false, Session.AUTO_ACKNOWLEDGE), topic);
- _connection.start();
-
- Message msg = _session.createTextMessage("Init");
- msg.setJMSReplyTo(queue);
- send(msg);
- }
-
- public synchronized void onMessage(Message message)
- {
- try
- {
- //cancel timeout:
- _timeout.clear();
- new DelayedSend(_session.createTextMessage("Message" + (++_count)), INTERVAL);
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
-
- private synchronized void send(Message msg) throws JMSException
- {
- _producer.send(msg);
- //start timeout:
- _timeout = new Timeout(TIMEOUT);
- }
-
- private void error(Exception e)
- {
- e.printStackTrace();
- stop();
- }
-
- private void stop()
- {
- System.out.println("Stopping...");
- try
- {
- _connection.close();
- }
- catch (JMSException e)
- {
- System.out.println("Failed to shutdown: " + e);
- e.printStackTrace();
- }
- }
-
- private void timeout()
- {
- error(new RuntimeException("Timed out: count = " + _count));
- }
-
- public void bytesSent(long count)
- {
- }
-
- public void bytesReceived(long count)
- {
- }
-
- public boolean preFailover(boolean redirect)
- {
- System.out.println("preFailover(" + redirect + ") called");
- return true;
- }
-
- public boolean preResubscribe()
- {
- System.out.println("preResubscribe() called");
- return true;
- }
-
- public void failoverComplete()
- {
- System.out.println("failoverComplete() called");
- }
-
- private class TopicListener implements MessageListener
- {
- private final Session _session;
- private MessageProducer _producer;
- private int _received;
-
- TopicListener(Session session, Topic topic) throws JMSException
- {
- _session = session;
- _session.createConsumer(topic).setMessageListener(this);
- }
-
- public void onMessage(Message message)
- {
- try
- {
- //if(_received++ % 100 == 0)
- {
- System.out.println("Received: " + ((TextMessage) message).getText());
- }
- if(_producer == null)
- {
- _producer = init(message);
- }
- reply(message);
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
-
- private void reply(Message message) throws JMSException
- {
- _producer.send(_session.createTextMessage(((TextMessage) message).getText()));
- }
-
- private MessageProducer init(Message message) throws JMSException
- {
- return _session.createProducer(message.getJMSReplyTo());
- }
- }
-
- private class Timeout extends TimerTask
- {
- private volatile boolean _cancelled;
-
- Timeout(long time)
- {
- _timer.schedule(this, time);
- }
-
- void clear()
- {
- _cancelled = true;
- }
-
- public void run()
- {
- if(!_cancelled)
- {
- timeout();
- }
- }
- }
-
- private class DelayedSend extends TimerTask
- {
- private final Message _msg;
-
- DelayedSend(Message msg, long delay)
- {
- _msg = msg;
- _timer.schedule(this, delay);
- }
-
- public void run()
- {
- try
- {
- send(_msg);
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
- }
-
- public static void main(final String[] argv) throws Exception
- {
- //Default failover is to use single server
- String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672?retries='2''";
- final String broker = argv.length == 0? url : argv[0];
- new FailoverSingleServerTest(broker);
- }
-}
diff --git a/client/test/src/org/apache/qpid/failover/FailoverTest.java b/client/test/src/org/apache/qpid/failover/FailoverTest.java
deleted file mode 100644
index 4905bf5614..0000000000
--- a/client/test/src/org/apache/qpid/failover/FailoverTest.java
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-package org.apache.qpid.failover;
-
-import org.apache.qpid.AMQException;
-import org.apache.qpid.url.URLSyntaxException;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.jms.ConnectionListener;
-
-import javax.jms.*;
-import java.util.Timer;
-import java.util.TimerTask;
-
-public class FailoverTest implements MessageListener, ConnectionListener
-{
- private static final long TIMEOUT = 10 * 1000;
- private static final long INTERVAL = 500;
- private final Timer _timer = new Timer(true);
- private final Connection _connection;
- private final Session _session;
- private final MessageProducer _producer;
- private Timeout _timeout;
- private int _count;
- private Queue _tempQueue;
-
- FailoverTest(String connectionUrl) throws JMSException, AMQException, URLSyntaxException
- {
- this(new AMQConnection(connectionUrl));
- ((AMQConnection) _connection).setConnectionListener(this);
- }
-
- FailoverTest(Connection connection) throws JMSException
- {
- AMQConnection amqConnection = (AMQConnection) connection;
- System.out.println("connection.url = " + amqConnection.toURL());
- _connection = connection;
- _session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Topic topic = _session.createTopic("topic1");
- _tempQueue = _session.createTemporaryQueue();
- _producer = _session.createProducer(topic);
- _session.createConsumer(_tempQueue).setMessageListener(this);
- //new TopicListener(_session, topic);
- new TopicListener(_connection.createSession(false, Session.AUTO_ACKNOWLEDGE), topic);
- _connection.start();
-
- Message msg = _session.createTextMessage("Init");
- msg.setJMSReplyTo(_tempQueue);
- send(msg);
- }
-
- public synchronized void onMessage(Message message)
- {
- try
- {
- //cancel timeout:
- _timeout.clear();
- new DelayedSend(_session.createTextMessage("Message" + (++_count)), INTERVAL);
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
-
- private synchronized void send(Message msg) throws JMSException
- {
- _producer.send(msg);
- //start timeout:
- _timeout = new Timeout(TIMEOUT);
- }
-
- private void error(Exception e)
- {
- e.printStackTrace();
- stop();
- }
-
- private void stop()
- {
- System.out.println("Stopping...");
- try
- {
- _connection.close();
- }
- catch (JMSException e)
- {
- System.out.println("Failed to shutdown: " + e);
- e.printStackTrace();
- }
- }
-
- private void timeout()
- {
- try {
- System.out.println("timed out. Resending init message");
- Message msg = _session.createTextMessage("Init");
- msg.setJMSReplyTo(_tempQueue);
- send(msg);
- } catch (JMSException e) {
- throw new RuntimeException("Got JMSException", e);
- }
-// error(new RuntimeException("Timed out: count = " + _count));
- }
-
- public void bytesSent(long count)
- {
- }
-
- public void bytesReceived(long count)
- {
- }
-
- public boolean preFailover(boolean redirect)
- {
- System.out.println("preFailover(" + redirect + ") called");
- return true;
- }
-
- public boolean preResubscribe()
- {
- System.out.println("preResubscribe() called");
- return true;
- }
-
- public void failoverComplete()
- {
- System.out.println("failoverComplete() called");
- }
-
- private class TopicListener implements MessageListener
- {
- private final Session _session;
- private MessageProducer _producer;
- private int _received;
-
- TopicListener(Session session, Topic topic) throws JMSException
- {
- _session = session;
- _session.createConsumer(topic).setMessageListener(this);
- }
-
- public void onMessage(Message message)
- {
- try
- {
- //if(_received++ % 100 == 0)
- {
- System.out.println("Received: " + ((TextMessage) message).getText());
- }
- if(_producer == null)
- {
- _producer = init(message);
- }
- reply(message);
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
-
- private void reply(Message message) throws JMSException
- {
- _producer.send(_session.createTextMessage(((TextMessage) message).getText()));
- }
-
- private MessageProducer init(Message message) throws JMSException
- {
- return _session.createProducer(message.getJMSReplyTo());
- }
- }
-
- private class Timeout extends TimerTask
- {
- private volatile boolean _cancelled;
-
- Timeout(long time)
- {
- _timer.schedule(this, time);
- }
-
- void clear()
- {
- _cancelled = true;
- }
-
- public void run()
- {
- if(!_cancelled)
- {
- timeout();
- System.out.println("would have timed out!");
- }
- }
- }
-
- private class DelayedSend extends TimerTask
- {
- private final Message _msg;
-
- DelayedSend(Message msg, long delay)
- {
- _msg = msg;
- _timer.schedule(this, delay);
- }
-
- public void run()
- {
- try
- {
- send(_msg);
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
- }
-
- public static void main(final String[] argv) throws Exception
- {
- final String clientId = "failover" + System.currentTimeMillis();
- final String defaultUrl = "amqp://guest:guest@" + clientId + "/test" +
- "?brokerlist='tcp://localhost:5672;tcp://localhost:5673'&failover='roundrobin'";
-
- System.out.println("url = [" + defaultUrl + "]");
-
- System.out.println("connection url = [" + new AMQConnectionURL(defaultUrl) + "]");
-
- final String broker = argv.length == 0? defaultUrl : argv[0];
- new FailoverTest(broker);
- }
-}
diff --git a/client/test/src/org/apache/qpid/failover/FailoverTxTest.java b/client/test/src/org/apache/qpid/failover/FailoverTxTest.java
deleted file mode 100644
index 10ec682bf5..0000000000
--- a/client/test/src/org/apache/qpid/failover/FailoverTxTest.java
+++ /dev/null
@@ -1,179 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-package org.apache.qpid.failover;
-
-import org.apache.log4j.Logger;
-import org.apache.qpid.client.AMQConnection;
-import org.apache.qpid.client.AMQConnectionURL;
-import org.apache.qpid.jms.ConnectionListener;
-import org.junit.Assert;
-
-import javax.jms.*;
-import javax.jms.IllegalStateException;
-
-public class FailoverTxTest implements ConnectionListener
-{
- private static Logger _log = Logger.getLogger(FailoverTxTest.class);
-
- AMQConnection _connection;
-
- FailoverTxTest(String connectionUrl) throws Exception
- {
- _connection = new AMQConnection(connectionUrl);
- _connection.setConnectionListener(this);
- System.out.println("connection.url = " + _connection.toURL());
- Session session = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
- Destination queue = session.createTemporaryQueue();
-
- session.createConsumer(queue).setMessageListener(new MessageListener()
- {
- public void onMessage(Message message)
- {
- try
- {
- _log.info("Received: " + ((TextMessage) message).getText());
- }
- catch (JMSException e)
- {
- error(e);
- }
- }
- });
-
- _connection.start();
-
- sendInTx(queue);
-
- _connection.close();
- _log.info("FailoverTxText complete");
- }
-
- private void sendInTx(Destination queue) throws JMSException
- {
- Session session = _connection.createSession(true, Session.AUTO_ACKNOWLEDGE);
- MessageProducer producer = session.createProducer(queue);
- for (int i = 1; i <= 10; ++i)
- {
- for (int j = 1; j <= 10; ++j)
- {
- TextMessage msg = session.createTextMessage("Tx=" + i + " msg=" + j);
- _log.info("sending message = " + msg.getText());
- producer.send(msg);
- try
- {
- Thread.sleep(1000);
- }
- catch (InterruptedException e)
- {
- throw new RuntimeException("Someone interrupted me!", e);
- }
- }
- session.commit();
- }
- }
-
- private void error(Exception e)
- {
- _log.fatal("Exception received. About to stop.", e);
- stop();
- }
-
- private void stop()
- {
- System.out.println("Stopping...");
- try
- {
- _connection.close();
- }
- catch (JMSException e)
- {
- System.out.println("Failed to shutdown: " + e);
- e.printStackTrace();
- }
- }
-
- public void bytesSent(long count)
- {
- }
-
- public void bytesReceived(long count)
- {
- }
-
- public boolean preFailover(boolean redirect)
- {
- System.out.println("preFailover(" + redirect + ") called");
- return true;
- }
-
- public boolean preResubscribe()
- {
- System.out.println("preResubscribe() called");
- return true;
- }
-
- public void failoverComplete()
- {
- System.out.println("failoverComplete() called");
- }
-
- public static void main(final String[] argv) throws Exception
- {
- int[] creationOrder = {1, 2, 3};
- int[] killingOrder = {1, 2, 3};
- long delayBeforeKillingStart = 2000;
- long delayBetweenCullings = 2000;
- boolean recreateBrokers = true;
- long delayBeforeReCreationStart = 4000;
- long delayBetweenRecreates = 3000;
-
- FailoverBrokerTester tester = new FailoverBrokerTester(creationOrder, killingOrder, delayBeforeKillingStart, delayBetweenCullings,
- recreateBrokers, delayBeforeReCreationStart, delayBetweenRecreates);
-
- try
- {
- final String clientId = "failover" + System.currentTimeMillis();
- final String defaultUrl = "amqp://guest:guest@" + clientId + "/test" +
- "?brokerlist='vm://:1;vm://:2;vm://:3'&failover='roundrobin?cyclecount='2''";
-
- System.out.println("url = [" + defaultUrl + "]");
-
- System.out.println("connection url = [" + new AMQConnectionURL(defaultUrl) + "]");
-
- final String url = argv.length == 0 ? defaultUrl : argv[0];
- new FailoverTxTest(url);
-
- }
- catch (Throwable t)
- {
-
- if (t instanceof IllegalStateException)
- {
- t.getMessage().endsWith("has been closed");
- }
- else
- {
- Assert.fail("Unexpected Exception occured:" + t.getMessage());
- }
- }
- finally
- {
- tester.stopTesting();
- }
- }
-}
diff --git a/client/test/src/org/apache/qpid/framing/FieldTableTest.java b/client/test/src/org/apache/qpid/framing/FieldTableTest.java
deleted file mode 100644
index c76596ac5c..0000000000
--- a/client/test/src/org/apache/qpid/framing/FieldTableTest.java
+++ /dev/null
@@ -1,160 +0,0 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-package org.apache.qpid.framing;
-
-import junit.framework.JUnit4TestAdapter;
-import org.apache.mina.common.ByteBuffer;
-import org.apache.xml.security.utils.Base64;
-import org.apache.xml.security.exceptions.Base64DecodingException;
-import static org.junit.Assert.assertEquals;
-import org.junit.Test;
-
-import java.io.BufferedReader;
-import java.io.IOException;
-import java.io.InputStreamReader;
-import java.io.Reader;
-import java.util.Enumeration;
-import java.util.Properties;
-
-public class FieldTableTest
-{
- @Test
- public void dataDump() throws IOException, AMQFrameDecodingException, Base64DecodingException
- {
- byte[] data = readBase64("content.txt");
- System.out.println("Got " + data.length + " bytes of data");
- for (int i = 0; i < 100; i++)
- {
- System.out.print((char) data[i]);
- }
- System.out.println();
- int size = 4194304;
- ByteBuffer buffer = ByteBuffer.allocate(data.length);
- buffer.put(data);
- buffer.flip();
- FieldTable table = new FieldTable(buffer, size);
- }
-
- /*
- @Test
- public void case1() throws AMQFrameDecodingException, IOException
- {
- testEncoding(load("FieldTableTest.properties"));
- }
-
- @Test
- public void case2() throws AMQFrameDecodingException, IOException
- {
- testEncoding(load("FieldTableTest2.properties"));
- }
- */
- void testEncoding(FieldTable table) throws AMQFrameDecodingException
- {
- assertEquivalent(table, encodeThenDecode(table));
- }
-
- public void assertEquivalent(FieldTable table1, FieldTable table2)
- {
- for (Object o : table1.keySet())
- {
- String key = (String) o;
- assertEquals("Values for " + key + " did not match", table1.get(key), table2.get(key));
- //System.out.println("Values for " + key + " matched (" + table1.get(key) + ")");
- }
- }
-
- FieldTable encodeThenDecode(FieldTable table) throws AMQFrameDecodingException
- {
- ContentHeaderBody header = new ContentHeaderBody();
- header.classId = 6;
- BasicContentHeaderProperties properties = new BasicContentHeaderProperties();
- header.properties = properties;
-
- properties.setHeaders(table);
- int size = header.getSize();
-
- //encode
- ByteBuffer buffer = ByteBuffer.allocate(size);
- header.writePayload(buffer);
-
- //decode
- buffer.flip();
-
- header = new ContentHeaderBody();
- header.populateFromBuffer(buffer, size);
-
- return ((BasicContentHeaderProperties) header.properties).getHeaders();
- }
-
- byte[] readBase64(String name) throws IOException, Base64DecodingException
- {
- String content = read(new InputStreamReader(getClass().getResourceAsStream(name)));
- return Base64.decode(content);
- }
-
- FieldTable load(String name) throws IOException
- {
- return populate(new FieldTable(), read(name));
- }
-
- Properties read(String name) throws IOException
- {
- Properties p = new Properties();
- p.load(getClass().getResourceAsStream(name));
- return p;
- }
-
- FieldTable populate(FieldTable table, Properties properties)
- {
- for (Enumeration i = properties.propertyNames(); i.hasMoreElements();)
- {
- String key = (String) i.nextElement();
- String value = properties.getProperty(key);
- try{
- int ival = Integer.parseInt(value);
- table.put(key, (long) ival);
- }
- catch(NumberFormatException e)
- {
- table.put(key, value);
- }
- }
- return table;
- }
-
- static String read(Reader in) throws IOException
- {
- return read(in instanceof BufferedReader ? (BufferedReader) in : new BufferedReader(in));
- }
-
- static String read(BufferedReader in) throws IOException
- {
- StringBuffer buffer = new StringBuffer();
- String line = in.readLine();
- while (line != null){
- buffer.append(line).append(" ");
- line = in.readLine();
- }
- return buffer.toString();
- }
-
- public static junit.framework.Test suite()
- {
- return new JUnit4TestAdapter(FieldTableTest.class);
- }
-}
diff --git a/client/test/src/org/apache/qpid/ack/DisconnectAndRedeliverTest.java b/client/test/src/org/apache/qpid/test/unit/ack/DisconnectAndRedeliverTest.java
index fca04c8330..4e96695d23 100644
--- a/client/test/src/org/apache/qpid/ack/DisconnectAndRedeliverTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/ack/DisconnectAndRedeliverTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.ack;
+package org.apache.qpid.test.unit.ack;
import junit.framework.JUnit4TestAdapter;
import org.apache.log4j.Logger;
diff --git a/client/test/src/org/apache/qpid/ack/RecoverTest.java b/client/test/src/org/apache/qpid/test/unit/ack/RecoverTest.java
index 78be978e2e..4322a53b21 100644
--- a/client/test/src/org/apache/qpid/ack/RecoverTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/ack/RecoverTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.ack;
+package org.apache.qpid.test.unit.ack;
import junit.framework.JUnit4TestAdapter;
import org.apache.qpid.client.AMQConnection;
diff --git a/client/test/src/org/apache/qpid/ack/UnitTests.java b/client/test/src/org/apache/qpid/test/unit/ack/UnitTests.java
index 5caaff69cf..394817c3f9 100644
--- a/client/test/src/org/apache/qpid/ack/UnitTests.java
+++ b/client/test/src/org/apache/qpid/test/unit/ack/UnitTests.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.ack;
+package org.apache.qpid.test.unit.ack;
import junit.framework.JUnit4TestAdapter;
import org.junit.runner.RunWith;
diff --git a/client/test/src/org/apache/qpid/basic/BytesMessageTest.java b/client/test/src/org/apache/qpid/test/unit/basic/BytesMessageTest.java
index a832213066..29a1b57e26 100644
--- a/client/test/src/org/apache/qpid/basic/BytesMessageTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/basic/BytesMessageTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.basic;
+package org.apache.qpid.test.unit.basic;
import junit.framework.JUnit4TestAdapter;
import org.apache.qpid.client.AMQConnection;
@@ -49,8 +49,8 @@ public class BytesMessageTest implements MessageListener
@Before
public void init() throws Exception
{
- init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path"));
createVMBroker();
+ init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path"));
}
public void createVMBroker()
diff --git a/client/test/src/org/apache/qpid/basic/FieldTableKeyEnumeratorTest.java b/client/test/src/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java
index 08ff65ea29..d4e073d9ca 100644
--- a/client/test/src/org/apache/qpid/basic/FieldTableKeyEnumeratorTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java
@@ -15,11 +15,13 @@
* limitations under the License.
*
*/
-package org.apache.qpid.client.message;
+package org.apache.qpid.test.unit.basic;
import org.junit.Test;
import org.junit.Assert;
import org.apache.qpid.framing.FieldTable;
+import org.apache.qpid.client.message.JMSTextMessage;
+import org.apache.qpid.client.message.TestMessageHelper;
import java.util.Enumeration;
@@ -54,7 +56,7 @@ public class FieldTableKeyEnumeratorTest
{
try
{
- JMSTextMessage text = new JMSTextMessage();
+ JMSTextMessage text = TestMessageHelper.newJMSTextMessage();
text.setBooleanProperty("Boolean1", true);
text.setBooleanProperty("Boolean2", true);
diff --git a/client/test/src/org/apache/qpid/basic/FieldTableMessageTest.java b/client/test/src/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java
index 545f7b1094..472ec4d210 100644
--- a/client/test/src/org/apache/qpid/basic/FieldTableMessageTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.basic;
+package org.apache.qpid.test.unit.basic;
import junit.framework.JUnit4TestAdapter;
import org.apache.qpid.client.AMQConnection;
@@ -37,7 +37,6 @@ import org.junit.After;
import javax.jms.*;
import java.io.IOException;
import java.util.ArrayList;
-import java.util.Enumeration;
public class FieldTableMessageTest implements MessageListener
{
@@ -52,8 +51,8 @@ public class FieldTableMessageTest implements MessageListener
@Before
public void init() throws Exception
{
- init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path"));
createVMBroker();
+ init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path"));
}
public void createVMBroker()
diff --git a/client/test/src/org/apache/qpid/basic/MultipleConnectionTest.java b/client/test/src/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java
index 8bf6fc1991..ef4d6f829b 100644
--- a/client/test/src/org/apache/qpid/basic/MultipleConnectionTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java
@@ -15,14 +15,19 @@
* limitations under the License.
*
*/
-package org.apache.qpid.basic;
+package org.apache.qpid.test.unit.basic;
import junit.framework.JUnit4TestAdapter;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQSession;
import org.apache.qpid.client.AMQTopic;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.client.transport.TransportConnection;
import org.junit.Test;
+import org.junit.Before;
+import org.junit.After;
+import org.junit.Assert;
import javax.jms.*;
@@ -31,7 +36,7 @@ import javax.jms.*;
*/
public class MultipleConnectionTest
{
- public static String _connectionString="vm://:1";
+ public static String _connectionString = "vm://:1";
private static class Receiver
{
@@ -135,7 +140,7 @@ public class MultipleConnectionTest
private static void waitForCompletion(int expected, long wait, Receiver[] receivers) throws InterruptedException
{
- for(int i = 0; i < receivers.length; i++)
+ for (int i = 0; i < receivers.length; i++)
{
waitForCompletion(expected, wait, receivers[i]._counters);
}
@@ -143,12 +148,13 @@ public class MultipleConnectionTest
private static void waitForCompletion(int expected, long wait, MessageCounter[] counters) throws InterruptedException
{
- for(int i = 0; i < counters.length; i++)
+ for (int i = 0; i < counters.length; i++)
{
- if(!counters[i].waitUntil(expected, wait))
+ if (!counters[i].waitUntil(expected, wait))
{
throw new RuntimeException("Expected: " + expected + " got " + counters[i]);
- };
+ }
+ ;
}
}
@@ -191,7 +197,7 @@ public class MultipleConnectionTest
};
Publisher publisher = new Publisher(broker, topic);
- for(int i = 0; i < messages; i++)
+ for (int i = 0; i < messages; i++)
{
publisher.send("Message " + (i + 1));
}
@@ -204,13 +210,33 @@ public class MultipleConnectionTest
finally
{
publisher.close();
- for(int i = 0; i < receivers.length; i++)
+ for (int i = 0; i < receivers.length; i++)
{
receivers[i].close();
}
}
}
+ @Before
+ public void createVMBroker() throws Exception
+ {
+ try
+ {
+ TransportConnection.createVMBroker(1);
+ }
+ catch (AMQVMBrokerCreationException e)
+ {
+ Assert.fail("Unable to create broker: " + e);
+ }
+ }
+
+ @After
+ public void stopVmBroker()
+ {
+ TransportConnection.killVMBroker(1);
+ }
+
+
public static junit.framework.Test suite()
{
return new JUnit4TestAdapter(MultipleConnectionTest.class);
diff --git a/client/test/src/org/apache/qpid/basic/ObjectMessageTest.java b/client/test/src/org/apache/qpid/test/unit/basic/ObjectMessageTest.java
index ceb2fa907e..3e0d37d9b0 100644
--- a/client/test/src/org/apache/qpid/basic/ObjectMessageTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/basic/ObjectMessageTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.basic;
+package org.apache.qpid.test.unit.basic;
import junit.framework.JUnit4TestAdapter;
import org.apache.qpid.client.AMQConnection;
@@ -50,11 +50,18 @@ public class ObjectMessageTest implements MessageListener
public String _connectionString = "vm://:1";
@Before
- public void init() throws Exception
+ public void init()
{
String broker = _connectionString;
- init(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test_path"));
createVMBroker();
+ try
+ {
+ init(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test_path"));
+ }
+ catch (Exception e)
+ {
+ Assert.fail("Uable to initialise: " + e);
+ }
}
public void createVMBroker()
diff --git a/client/test/src/org/apache/qpid/basic/ReceiveTest.java b/client/test/src/org/apache/qpid/test/unit/basic/ReceiveTest.java
index d72d748935..e781ceee2c 100644
--- a/client/test/src/org/apache/qpid/basic/ReceiveTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/basic/ReceiveTest.java
@@ -15,16 +15,20 @@
* limitations under the License.
*
*/
-package org.apache.qpid.basic;
+package org.apache.qpid.test.unit.basic;
import junit.framework.JUnit4TestAdapter;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.client.transport.TransportConnection;
import org.junit.Before;
import org.junit.Test;
+import org.junit.Assert;
+import org.junit.After;
import javax.jms.MessageConsumer;
@@ -35,15 +39,44 @@ public class ReceiveTest
private AMQSession _session;
private MessageConsumer _consumer;
- public String _connectionString = "vm://:1";
-
+ private static final String VM_BROKER = "vm://:1";
+ public String _connectionString = VM_BROKER;
+
@Before
public void init() throws Exception
{
+ if (_connectionString.equals(VM_BROKER))
+ {
+ createVMBroker();
+ }
+
String broker = _connectionString;
init(new AMQConnection(broker, "guest", "guest", "ReceiveTestClient", "/test_path"));
}
+ public void createVMBroker()
+ {
+ try
+ {
+ TransportConnection.createVMBroker(1);
+ }
+ catch (
+ AMQVMBrokerCreationException e)
+ {
+ Assert.fail("Unable to create broker: " + e);
+ }
+ }
+
+ @After
+ public void stopVmBroker()
+ {
+ if (_connectionString.equals(VM_BROKER))
+ {
+ TransportConnection.killVMBroker(1);
+ }
+ }
+
+
private void init(AMQConnection connection) throws Exception
{
init(connection, new AMQQueue("ReceiveTest", true));
@@ -68,7 +101,7 @@ public class ReceiveTest
public static void main(String[] argv) throws Exception
{
ReceiveTest test = new ReceiveTest();
- test._connectionString = argv.length == 0 ? "vm://:1" : argv[0];
+ test._connectionString = argv.length == 0 ? VM_BROKER : argv[0];
test.init();
test.test();
}
diff --git a/client/test/src/org/apache/qpid/basic/SessionStartTest.java b/client/test/src/org/apache/qpid/test/unit/basic/SessionStartTest.java
index edd7beae14..3cdb1e8cca 100644
--- a/client/test/src/org/apache/qpid/basic/SessionStartTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/basic/SessionStartTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.basic;
+package org.apache.qpid.test.unit.basic;
import junit.framework.JUnit4TestAdapter;
import org.apache.qpid.client.AMQConnection;
@@ -43,10 +43,17 @@ public class SessionStartTest implements MessageListener
public String _connectionString = "vm://:1";
@Before
- public void init() throws Exception
+ public void init()
{
- init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path"));
createVMBroker();
+ try
+ {
+ init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path"));
+ }
+ catch (Exception e)
+ {
+ Assert.fail("Unable to initialise connection: " + e);
+ }
}
public void createVMBroker()
diff --git a/client/test/src/org/apache/qpid/basic/TextMessageTest.java b/client/test/src/org/apache/qpid/test/unit/basic/TextMessageTest.java
index 5bf5da2fb7..d4f1eeb9b1 100644
--- a/client/test/src/org/apache/qpid/basic/TextMessageTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/basic/TextMessageTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.basic;
+package org.apache.qpid.test.unit.basic;
import junit.framework.JUnit4TestAdapter;
import org.apache.qpid.client.AMQConnection;
@@ -46,10 +46,18 @@ public class TextMessageTest implements MessageListener
public String _connectionString = "vm://:1";
@Before
- public void init() throws Exception
+ public void init()
{
- init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path"));
createVMBroker();
+
+ try
+ {
+ init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path"));
+ }
+ catch (Exception e)
+ {
+ Assert.fail("Unable to initialilse connection: " + e);
+ }
}
public void createVMBroker()
diff --git a/client/test/src/org/apache/qpid/basic/UnitTests.java b/client/test/src/org/apache/qpid/test/unit/basic/UnitTests.java
index b87254f73a..9e17510eb6 100644
--- a/client/test/src/org/apache/qpid/basic/UnitTests.java
+++ b/client/test/src/org/apache/qpid/test/unit/basic/UnitTests.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.basic;
+package org.apache.qpid.test.unit.basic;
import junit.framework.JUnit4TestAdapter;
import org.junit.runner.RunWith;
diff --git a/client/test/src/org/apache/qpid/client/TestAMQConnection.java b/client/test/src/org/apache/qpid/test/unit/client/AMQConnectionTest.java
index 1858abf536..3dbfe39bdc 100644
--- a/client/test/src/org/apache/qpid/client/TestAMQConnection.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/AMQConnectionTest.java
@@ -1,138 +1,142 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-package org.apache.qpid.client;
-
-import org.junit.*;
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.url.URLSyntaxException;
-import junit.framework.JUnit4TestAdapter;
-
-import javax.jms.*;
-
-public class TestAMQConnection
-{
-
- private static AMQConnection _connection;
- private static AMQTopic _topic;
- private static AMQQueue _queue;
- private static QueueSession _queueSession;
- private static TopicSession _topicSession;
-
-
- @Before
- public void setUp() throws AMQException, URLSyntaxException, JMSException
- {
- createVMBroker();
- //initialise the variables we need for testing
- _connection = new AMQConnection("vm://:1", "guest", "guest", "fred", "/test");
- _topic = new AMQTopic("mytopic");
- _queue = new AMQQueue("myqueue");
- }
-
- public void createVMBroker()
- {
- try
- {
- TransportConnection.createVMBroker(1);
- }
- catch (AMQVMBrokerCreationException e)
- {
- Assert.fail("Unable to create broker: " + e);
- }
- }
-
- @After
- public void stopVmBroker()
- {
- try
- {
- _connection.close();
- }
- catch (JMSException e)
- {
- //ignore
- }
- TransportConnection.killVMBroker(1);
- }
-
- /**
- * Simple tests to check we can create TopicSession and QueueSession ok
- * And that they throw exceptions where appropriate as per JMS spec
- */
-
- @Test
- public void testCreateQueueSession() throws JMSException
- {
- _queueSession = _connection.createQueueSession(false, AMQSession.NO_ACKNOWLEDGE);
- }
-
- @Test
- public void testCreateTopicSession() throws JMSException
- {
- _topicSession = _connection.createTopicSession(false, AMQSession.NO_ACKNOWLEDGE);
- }
-
- @Test(expected = javax.jms.IllegalStateException.class)
- public void testTopicSessionCreateBrowser() throws JMSException
- {
- _topicSession.createBrowser(_queue);
- }
-
- @Test(expected = javax.jms.IllegalStateException.class)
- public void testTopicSessionCreateQueue() throws JMSException
- {
- _topicSession.createQueue("abc");
- }
-
- @Test(expected = javax.jms.IllegalStateException.class)
- public void testTopicSessionCreateTemporaryQueue() throws JMSException
- {
- _topicSession.createTemporaryQueue();
- }
-
- @Test(expected = javax.jms.IllegalStateException.class)
- public void testQueueSessionCreateTemporaryTopic() throws JMSException
- {
- _queueSession.createTemporaryTopic();
- }
-
- @Test(expected = javax.jms.IllegalStateException.class)
- public void testQueueSessionCreateTopic() throws JMSException
- {
- _queueSession.createTopic("abc");
- }
-
- @Test(expected = javax.jms.IllegalStateException.class)
- public void testQueueSessionDurableSubscriber() throws JMSException
- {
- _queueSession.createDurableSubscriber(_topic, "abc");
- }
-
- @Test(expected = javax.jms.IllegalStateException.class)
- public void testQueueSessionUnsubscribe() throws JMSException
- {
- _queueSession.unsubscribe("abc");
- }
-
- public static junit.framework.Test suite()
- {
- return new JUnit4TestAdapter(TestAMQConnection.class);
- }
-}
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ */
+package org.apache.qpid.test.unit.client;
+
+import org.junit.*;
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.client.AMQTopic;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.url.URLSyntaxException;
+import junit.framework.JUnit4TestAdapter;
+
+import javax.jms.*;
+
+public class AMQConnectionTest
+{
+
+ private static AMQConnection _connection;
+ private static AMQTopic _topic;
+ private static AMQQueue _queue;
+ private static QueueSession _queueSession;
+ private static TopicSession _topicSession;
+
+
+ @Before
+ public void setUp() throws AMQException, URLSyntaxException, JMSException
+ {
+ createVMBroker();
+ //initialise the variables we need for testing
+ _connection = new AMQConnection("vm://:1", "guest", "guest", "fred", "/test");
+ _topic = new AMQTopic("mytopic");
+ _queue = new AMQQueue("myqueue");
+ }
+
+ public void createVMBroker()
+ {
+ try
+ {
+ TransportConnection.createVMBroker(1);
+ }
+ catch (AMQVMBrokerCreationException e)
+ {
+ Assert.fail("Unable to create broker: " + e);
+ }
+ }
+
+ @After
+ public void stopVmBroker()
+ {
+ try
+ {
+ _connection.close();
+ }
+ catch (JMSException e)
+ {
+ //ignore
+ }
+ TransportConnection.killVMBroker(1);
+ }
+
+ /**
+ * Simple tests to check we can create TopicSession and QueueSession ok
+ * And that they throw exceptions where appropriate as per JMS spec
+ */
+
+ @Test
+ public void testCreateQueueSession() throws JMSException
+ {
+ _queueSession = _connection.createQueueSession(false, AMQSession.NO_ACKNOWLEDGE);
+ }
+
+ @Test
+ public void testCreateTopicSession() throws JMSException
+ {
+ _topicSession = _connection.createTopicSession(false, AMQSession.NO_ACKNOWLEDGE);
+ }
+
+ @Test(expected = javax.jms.IllegalStateException.class)
+ public void testTopicSessionCreateBrowser() throws JMSException
+ {
+ _topicSession.createBrowser(_queue);
+ }
+
+ @Test(expected = javax.jms.IllegalStateException.class)
+ public void testTopicSessionCreateQueue() throws JMSException
+ {
+ _topicSession.createQueue("abc");
+ }
+
+ @Test(expected = javax.jms.IllegalStateException.class)
+ public void testTopicSessionCreateTemporaryQueue() throws JMSException
+ {
+ _topicSession.createTemporaryQueue();
+ }
+
+ @Test(expected = javax.jms.IllegalStateException.class)
+ public void testQueueSessionCreateTemporaryTopic() throws JMSException
+ {
+ _queueSession.createTemporaryTopic();
+ }
+
+ @Test(expected = javax.jms.IllegalStateException.class)
+ public void testQueueSessionCreateTopic() throws JMSException
+ {
+ _queueSession.createTopic("abc");
+ }
+
+ @Test(expected = javax.jms.IllegalStateException.class)
+ public void testQueueSessionDurableSubscriber() throws JMSException
+ {
+ _queueSession.createDurableSubscriber(_topic, "abc");
+ }
+
+ @Test(expected = javax.jms.IllegalStateException.class)
+ public void testQueueSessionUnsubscribe() throws JMSException
+ {
+ _queueSession.unsubscribe("abc");
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(AMQConnectionTest.class);
+ }
+}
diff --git a/client/test/src/org/apache/qpid/client/TestAMQSession.java b/client/test/src/org/apache/qpid/test/unit/client/AMQSessionTest.java
index 99da8c5b10..cf33e7443b 100644
--- a/client/test/src/org/apache/qpid/client/TestAMQSession.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/AMQSessionTest.java
@@ -1,135 +1,139 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-package org.apache.qpid.client;
-
-import org.junit.*;
-import org.apache.qpid.AMQException;
-import org.apache.qpid.client.transport.TransportConnection;
-import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
-import org.apache.qpid.url.URLSyntaxException;
-
-import javax.jms.JMSException;
-import javax.jms.TopicSubscriber;
-import javax.jms.QueueReceiver;
-
-import junit.framework.JUnit4TestAdapter;
-
-/**
- * Tests for QueueReceiver and TopicSubscriber creation methods on AMQSession
- */
-public class TestAMQSession
-{
-
- private static AMQSession _session;
- private static AMQTopic _topic;
- private static AMQQueue _queue;
- private static AMQConnection _connection;
-
- @Before
- public void setUp() throws AMQException, URLSyntaxException, JMSException
- {
- createVMBroker();
- //initialise the variables we need for testing
- _connection = new AMQConnection("vm://:1", "guest", "guest", "fred", "/test");
- _topic = new AMQTopic("mytopic");
- _queue = new AMQQueue("myqueue");
- _session = (AMQSession) _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
- }
-
-
- public void createVMBroker()
- {
- try
- {
- TransportConnection.createVMBroker(1);
- }
- catch (AMQVMBrokerCreationException e)
- {
- Assert.fail("Unable to create broker: " + e);
- }
- }
-
- @After
- public void stopVmBroker()
- {
- try
- {
- _connection.close();
- }
- catch (JMSException e)
- {
- //just close
- }
- TransportConnection.killVMBroker(1);
- }
-
- @Test
- public void testCreateSubscriber() throws JMSException
- {
- TopicSubscriber subscriber = _session.createSubscriber(_topic);
- Assert.assertEquals("Topic names should match from TopicSubscriber", _topic.getTopicName(), subscriber.getTopic().getTopicName());
-
- subscriber = _session.createSubscriber(_topic, "abc", false);
- Assert.assertEquals("Topic names should match from TopicSubscriber with selector", _topic.getTopicName(), subscriber.getTopic().getTopicName());
- }
-
- @Test
- public void testCreateDurableSubscriber() throws JMSException
- {
- TopicSubscriber subscriber = _session.createDurableSubscriber(_topic, "mysubname");
- Assert.assertEquals("Topic names should match from durable TopicSubscriber", _topic.getTopicName(), subscriber.getTopic().getTopicName());
-
- subscriber = _session.createDurableSubscriber(_topic, "mysubname", "abc", false);
- Assert.assertEquals("Topic names should match from durable TopicSubscriber with selector", _topic.getTopicName(), subscriber.getTopic().getTopicName());
- }
-
- @Test
- public void testCreateQueueReceiver() throws JMSException
- {
- QueueReceiver receiver = _session.createQueueReceiver(_queue);
- Assert.assertEquals("Queue names should match from QueueReceiver", _queue.getQueueName(), receiver.getQueue().getQueueName());
-
- receiver = _session.createQueueReceiver(_queue, "abc");
- Assert.assertEquals("Queue names should match from QueueReceiver with selector", _queue.getQueueName(), receiver.getQueue().getQueueName());
- }
-
- @Test
- public void testCreateReceiver() throws JMSException
- {
- QueueReceiver receiver = _session.createReceiver(_queue);
- Assert.assertEquals("Queue names should match from QueueReceiver", _queue.getQueueName(), receiver.getQueue().getQueueName());
-
- receiver = _session.createReceiver(_queue, "abc");
- Assert.assertEquals("Queue names should match from QueueReceiver with selector", _queue.getQueueName(), receiver.getQueue().getQueueName());
- }
-
- @AfterClass
- public static void stopVmBrokers()
- {
- _queue = null;
- _topic = null;
- _session = null;
- }
-
- public static junit.framework.Test suite()
- {
- return new JUnit4TestAdapter(TestAMQSession.class);
- }
-
-
-}
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ */
+package org.apache.qpid.test.unit.client;
+
+import org.junit.*;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.client.AMQTopic;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.url.URLSyntaxException;
+
+import javax.jms.JMSException;
+import javax.jms.TopicSubscriber;
+import javax.jms.QueueReceiver;
+
+import junit.framework.JUnit4TestAdapter;
+
+/**
+ * Tests for QueueReceiver and TopicSubscriber creation methods on AMQSession
+ */
+public class AMQSessionTest
+{
+
+ private static AMQSession _session;
+ private static AMQTopic _topic;
+ private static AMQQueue _queue;
+ private static AMQConnection _connection;
+
+ @Before
+ public void setUp() throws AMQException, URLSyntaxException, JMSException
+ {
+ createVMBroker();
+ //initialise the variables we need for testing
+ _connection = new AMQConnection("vm://:1", "guest", "guest", "fred", "/test");
+ _topic = new AMQTopic("mytopic");
+ _queue = new AMQQueue("myqueue");
+ _session = (AMQSession) _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
+ }
+
+
+ public void createVMBroker()
+ {
+ try
+ {
+ TransportConnection.createVMBroker(1);
+ }
+ catch (AMQVMBrokerCreationException e)
+ {
+ Assert.fail("Unable to create broker: " + e);
+ }
+ }
+
+ @After
+ public void stopVmBroker()
+ {
+ try
+ {
+ _connection.close();
+ }
+ catch (JMSException e)
+ {
+ //just close
+ }
+ TransportConnection.killVMBroker(1);
+ }
+
+ @Test
+ public void testCreateSubscriber() throws JMSException
+ {
+ TopicSubscriber subscriber = _session.createSubscriber(_topic);
+ Assert.assertEquals("Topic names should match from TopicSubscriber", _topic.getTopicName(), subscriber.getTopic().getTopicName());
+
+ subscriber = _session.createSubscriber(_topic, "abc", false);
+ Assert.assertEquals("Topic names should match from TopicSubscriber with selector", _topic.getTopicName(), subscriber.getTopic().getTopicName());
+ }
+
+ @Test
+ public void testCreateDurableSubscriber() throws JMSException
+ {
+ TopicSubscriber subscriber = _session.createDurableSubscriber(_topic, "mysubname");
+ Assert.assertEquals("Topic names should match from durable TopicSubscriber", _topic.getTopicName(), subscriber.getTopic().getTopicName());
+
+ subscriber = _session.createDurableSubscriber(_topic, "mysubname", "abc", false);
+ Assert.assertEquals("Topic names should match from durable TopicSubscriber with selector", _topic.getTopicName(), subscriber.getTopic().getTopicName());
+ }
+
+ @Test
+ public void testCreateQueueReceiver() throws JMSException
+ {
+ QueueReceiver receiver = _session.createQueueReceiver(_queue);
+ Assert.assertEquals("Queue names should match from QueueReceiver", _queue.getQueueName(), receiver.getQueue().getQueueName());
+
+ receiver = _session.createQueueReceiver(_queue, "abc");
+ Assert.assertEquals("Queue names should match from QueueReceiver with selector", _queue.getQueueName(), receiver.getQueue().getQueueName());
+ }
+
+ @Test
+ public void testCreateReceiver() throws JMSException
+ {
+ QueueReceiver receiver = _session.createReceiver(_queue);
+ Assert.assertEquals("Queue names should match from QueueReceiver", _queue.getQueueName(), receiver.getQueue().getQueueName());
+
+ receiver = _session.createReceiver(_queue, "abc");
+ Assert.assertEquals("Queue names should match from QueueReceiver with selector", _queue.getQueueName(), receiver.getQueue().getQueueName());
+ }
+
+ @AfterClass
+ public static void stopVmBrokers()
+ {
+ _queue = null;
+ _topic = null;
+ _session = null;
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(AMQSessionTest.class);
+ }
+
+
+}
diff --git a/client/test/src/org/apache/qpid/client/AllClientUnitTests.java b/client/test/src/org/apache/qpid/test/unit/client/AllClientUnitTests.java
index 1b2b2ed0aa..6e9f173ea8 100644
--- a/client/test/src/org/apache/qpid/client/AllClientUnitTests.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/AllClientUnitTests.java
@@ -26,17 +26,17 @@ import org.junit.runners.Suite;
*/
@RunWith(Suite.class)
@Suite.SuiteClasses({
- org.apache.qpid.ack.UnitTests.class,
- org.apache.qpid.basic.UnitTests.class,
- org.apache.qpid.client.channelclose.UnitTests.class,
- org.apache.qpid.client.message.UnitTests.class,
- org.apache.qpid.forwardall.UnitTests.class,
- org.apache.qpid.destinationurl.UnitTests.class,
- org.apache.qpid.jndi.referenceabletest.UnitTests.class,
- org.apache.qpid.transacted.UnitTests.class,
- org.apache.qpid.client.protocol.TestAMQProtocolSession.class,
- org.apache.qpid.client.TestAMQConnection.class,
- org.apache.qpid.client.TestAMQSession.class
+ org.apache.qpid.test.unit.ack.UnitTests.class,
+ org.apache.qpid.test.unit.basic.UnitTests.class,
+ org.apache.qpid.test.unit.client.channelclose.UnitTests.class,
+ org.apache.qpid.test.unit.client.message.MessageUnitTests.class,
+ org.apache.qpid.test.unit.client.forwardall.UnitTests.class,
+ org.apache.qpid.test.unit.client.destinationurl.UnitTests.class,
+ org.apache.qpid.test.unit.jndi.referenceabletest.UnitTests.class,
+ org.apache.qpid.test.unit.transacted.UnitTests.class,
+ org.apache.qpid.test.unit.client.protocol.AMQProtocolSessionTest.class,
+ org.apache.qpid.test.unit.client.AMQConnectionTest.class,
+ org.apache.qpid.test.unit.client.AMQSessionTest.class
})
public class AllClientUnitTests
{
diff --git a/client/test/src/org/apache/qpid/client/channelclose/ChannelCloseOkTest.java b/client/test/src/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java
index 7b714a01b7..cb3093e22c 100644
--- a/client/test/src/org/apache/qpid/client/channelclose/ChannelCloseOkTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.client.channelclose;
+package org.apache.qpid.test.unit.client.channelclose;
import junit.framework.JUnit4TestAdapter;
import org.apache.qpid.client.AMQConnection;
diff --git a/client/test/src/org/apache/qpid/client/channelclose/UnitTests.java b/client/test/src/org/apache/qpid/test/unit/client/channelclose/UnitTests.java
index ed98bc0c30..8f97c723f7 100644
--- a/client/test/src/org/apache/qpid/client/channelclose/UnitTests.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/channelclose/UnitTests.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.client.channelclose;
+package org.apache.qpid.test.unit.client.channelclose;
import junit.framework.JUnit4TestAdapter;
import org.junit.runner.RunWith;
diff --git a/client/test/src/org/apache/qpid/connection/ConnectionTest.java b/client/test/src/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
index e86d238dc4..d88ca8322d 100644
--- a/client/test/src/org/apache/qpid/connection/ConnectionTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/connection/ConnectionTest.java
@@ -15,15 +15,19 @@
* limitations under the License.
*
*/
-package org.apache.qpid.connection;
+package org.apache.qpid.test.unit.client.connection;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQAuthenticationException;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.AMQException;
import org.apache.qpid.AMQConnectionException;
import org.apache.qpid.AMQUnresolvedAddressException;
import org.junit.Test;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.After;
import javax.jms.Connection;
@@ -31,12 +35,42 @@ import junit.framework.JUnit4TestAdapter;
public class ConnectionTest
{
+
+ String _broker = "vm://:1";
+ String _broker_NotRunning = "vm://:2";
+ String _broker_BadDNS = "tcp://hg3sgaaw4lgihjs";
+
+ @Before
+ public void createVMBroker()
+ {
+ try
+ {
+ TransportConnection.createVMBroker(1);
+ }
+ catch (AMQVMBrokerCreationException e)
+ {
+ Assert.fail("Unable to create broker: " + e);
+ }
+ }
+
+ @After
+ public void stopVmBroker()
+ {
+ TransportConnection.killVMBroker(1);
+ }
+
@Test
- public void simpleConnection() throws Exception
+ public void simpleConnection()
{
- Connection connection = new AMQConnection("localhost:5672", "guest", "guest",
- "fred", "/test");
- System.out.println("connection = " + connection);
+ try
+ {
+ Connection connection = new AMQConnection(_broker, "guest", "guest",
+ "fred", "/test");
+ }
+ catch (Exception e)
+ {
+ Assert.fail("Connection to " + _broker + " should succeed. Reason: " + e);
+ }
}
@Test
@@ -44,14 +78,14 @@ public class ConnectionTest
{
try
{
- new AMQConnection("amqp://guest:rubbishpassword@clientid/testpath?brokerlist='tcp://localhost:5672?retries='1''");
- Assert.fail("Connection should not be established");
+ new AMQConnection("amqp://guest:rubbishpassword@clientid/testpath?brokerlist='" + _broker + "?retries='1''");
+ Assert.fail("Connection should not be established password is wrong.");
}
catch (AMQException amqe)
{
if (!(amqe instanceof AMQAuthenticationException))
{
- Assert.fail("Correct exception not thrown");
+ Assert.fail("Correct exception not thrown. Excpected 'AMQAuthenticationException' got: " + amqe);
}
}
}
@@ -61,14 +95,14 @@ public class ConnectionTest
{
try
{
- new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:5673?retries='0''");
+ new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='" + _broker_NotRunning + "?retries='0''");
Assert.fail("Connection should not be established");
}
catch (AMQException amqe)
{
if (!(amqe instanceof AMQConnectionException))
{
- Assert.fail("Correct exception not thrown");
+ Assert.fail("Correct exception not thrown. Excpected 'AMQConnectionException' got: " + amqe);
}
}
}
@@ -78,14 +112,14 @@ public class ConnectionTest
{
try
{
- new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='tcp://rubbishhost:5672?retries='0''");
+ new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='" + _broker_BadDNS + "?retries='0''");
Assert.fail("Connection should not be established");
}
catch (AMQException amqe)
{
if (!(amqe instanceof AMQUnresolvedAddressException))
{
- Assert.fail("Correct exception not thrown");
+ Assert.fail("Correct exception not thrown. Excpected 'AMQUnresolvedAddressException' got: " + amqe);
}
}
}
diff --git a/client/test/src/org/apache/qpid/connection/TestManyConnections.java b/client/test/src/org/apache/qpid/test/unit/client/connection/TestManyConnections.java
index 4456037c2e..700645f242 100644
--- a/client/test/src/org/apache/qpid/connection/TestManyConnections.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/connection/TestManyConnections.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.connection;
+package org.apache.qpid.test.unit.client.connection;
import junit.framework.JUnit4TestAdapter;
import org.apache.qpid.AMQException;
diff --git a/client/test/src/org/apache/qpid/connectionurl/ConnectionURLTest.java b/client/test/src/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
index cc8442af90..d9e01204bc 100644
--- a/client/test/src/org/apache/qpid/connectionurl/ConnectionURLTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java
@@ -15,12 +15,16 @@
* limitations under the License.
*
*/
-package org.apache.qpid.connectionurl;
+package org.apache.qpid.test.unit.client.connectionurl;
import org.junit.Test;
import org.junit.Assert;
+import org.junit.Before;
+import org.junit.After;
import org.apache.qpid.client.AMQConnectionURL;
import org.apache.qpid.client.AMQBrokerDetails;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.client.transport.TransportConnection;
import org.apache.qpid.jms.ConnectionURL;
import org.apache.qpid.jms.BrokerDetails;
import org.apache.qpid.url.URLSyntaxException;
@@ -28,6 +32,7 @@ import junit.framework.JUnit4TestAdapter;
public class ConnectionURLTest
{
+
@Test
public void failoverURL() throws URLSyntaxException
{
@@ -325,12 +330,12 @@ public class ConnectionURLTest
try
{
- new AMQConnectionURL(url);
+ AMQConnectionURL connection = new AMQConnectionURL(url);
Float version = Float.parseFloat(System.getProperty("java.specification.version"));
if (version > 1.5)
{
- Assert.fail("URL Should not parse on Java 1.6 or greater");
+ Assert.fail("URL Should not parse on Java " + version + " Connection is:" + connection);
}
}
catch (URLSyntaxException urise)
@@ -430,15 +435,16 @@ public class ConnectionURLTest
{
String url = "amqp://guest:guest@id/test" + "?brokerlist='tcp://localhost:5672";
- try{
- new AMQConnectionURL(url);
- }catch(URLSyntaxException e)
+ try
+ {
+ new AMQConnectionURL(url);
+ }
+ catch (URLSyntaxException e)
{
- Assert.assertEquals(e.getMessage(),"Unterminated option at index 32: brokerlist='tcp://localhost:5672");
+ Assert.assertEquals(e.getMessage(), "Unterminated option at index 32: brokerlist='tcp://localhost:5672");
}
-
}
diff --git a/client/test/src/org/apache/qpid/connectionurl/UnitTests.java b/client/test/src/org/apache/qpid/test/unit/client/connectionurl/UnitTests.java
index f4f269330e..06995c9de3 100644
--- a/client/test/src/org/apache/qpid/connectionurl/UnitTests.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/connectionurl/UnitTests.java
@@ -15,11 +15,10 @@
* limitations under the License.
*
*/
-package org.apache.qpid.connectionurl;
+package org.apache.qpid.test.unit.client.connectionurl;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
-import org.apache.qpid.ack.*;
import junit.framework.JUnit4TestAdapter;
@RunWith(Suite.class)
@@ -28,6 +27,6 @@ public class UnitTests
{
public static junit.framework.Test suite()
{
- return new JUnit4TestAdapter(org.apache.qpid.connectionurl.UnitTests.class);
+ return new JUnit4TestAdapter(org.apache.qpid.test.unit.client.connectionurl.UnitTests.class);
}
}
diff --git a/client/test/src/org/apache/qpid/destinationurl/DestinationURLTest.java b/client/test/src/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java
index 8369fa9e75..fbb6920503 100644
--- a/client/test/src/org/apache/qpid/destinationurl/DestinationURLTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.destinationurl;
+package org.apache.qpid.test.unit.client.destinationurl;
import org.junit.Test;
import org.junit.Assert;
diff --git a/client/test/src/org/apache/qpid/client/message/UnitTests.java b/client/test/src/org/apache/qpid/test/unit/client/destinationurl/UnitTests.java
index 889c437df3..12c6813f2a 100644
--- a/client/test/src/org/apache/qpid/client/message/UnitTests.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/destinationurl/UnitTests.java
@@ -15,14 +15,14 @@
* limitations under the License.
*
*/
-package org.apache.qpid.client.message;
+package org.apache.qpid.test.unit.client.destinationurl;
-import junit.framework.JUnit4TestAdapter;
import org.junit.runner.RunWith;
import org.junit.runners.Suite;
+import junit.framework.JUnit4TestAdapter;
@RunWith(Suite.class)
-@Suite.SuiteClasses({TestBytesMessage.class, TestTextMessage.class})
+@Suite.SuiteClasses({DestinationURLTest.class})
public class UnitTests
{
public static junit.framework.Test suite()
diff --git a/client/test/src/org/apache/qpid/forwardall/Client.java b/client/test/src/org/apache/qpid/test/unit/client/forwardall/Client.java
index 4ad8587ae0..d1384e3c05 100644
--- a/client/test/src/org/apache/qpid/forwardall/Client.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/forwardall/Client.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.forwardall;
+package org.apache.qpid.test.unit.client.forwardall;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQQueue;
diff --git a/client/test/src/org/apache/qpid/forwardall/Combined.java b/client/test/src/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java
index f767e8b1e8..4620fe13b0 100644
--- a/client/test/src/org/apache/qpid/forwardall/Combined.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.forwardall;
+package org.apache.qpid.test.unit.client.forwardall;
import junit.framework.JUnit4TestAdapter;
import org.junit.Test;
@@ -29,7 +29,7 @@ import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
* Runs the Service's and Client parts of the test in the same process
* as the broker
*/
-public class Combined
+public class CombinedTest
{
@Before
@@ -67,6 +67,6 @@ public class Combined
public static junit.framework.Test suite()
{
- return new JUnit4TestAdapter(Combined.class);
+ return new JUnit4TestAdapter(CombinedTest.class);
}
}
diff --git a/client/test/src/org/apache/qpid/forwardall/Service.java b/client/test/src/org/apache/qpid/test/unit/client/forwardall/Service.java
index f0a62456f5..d9cc374835 100644
--- a/client/test/src/org/apache/qpid/forwardall/Service.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/forwardall/Service.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.forwardall;
+package org.apache.qpid.test.unit.client.forwardall;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQQueue;
diff --git a/client/test/src/org/apache/qpid/forwardall/ServiceCreator.java b/client/test/src/org/apache/qpid/test/unit/client/forwardall/ServiceCreator.java
index e58cc924d4..3995b26e7d 100644
--- a/client/test/src/org/apache/qpid/forwardall/ServiceCreator.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/forwardall/ServiceCreator.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.forwardall;
+package org.apache.qpid.test.unit.client.forwardall;
import javax.jms.JMSException;
diff --git a/client/test/src/org/apache/qpid/forwardall/SpecialQueue.java b/client/test/src/org/apache/qpid/test/unit/client/forwardall/SpecialQueue.java
index efa633033f..e4cd3108d4 100644
--- a/client/test/src/org/apache/qpid/forwardall/SpecialQueue.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/forwardall/SpecialQueue.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.forwardall;
+package org.apache.qpid.test.unit.client.forwardall;
import org.apache.qpid.client.AMQQueue;
diff --git a/client/test/src/org/apache/qpid/forwardall/UnitTests.java b/client/test/src/org/apache/qpid/test/unit/client/forwardall/UnitTests.java
index c62acce11d..14fc2e7cd4 100644
--- a/client/test/src/org/apache/qpid/forwardall/UnitTests.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/forwardall/UnitTests.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.forwardall;
+package org.apache.qpid.test.unit.client.forwardall;
import junit.framework.JUnit4TestAdapter;
import org.junit.runner.RunWith;
@@ -23,7 +23,7 @@ import org.junit.runners.Suite;
@RunWith(Suite.class)
@Suite.SuiteClasses({
- Combined.class
+ CombinedTest.class
})
public class UnitTests
{
diff --git a/client/test/src/org/apache/qpid/client/message/TestBytesMessage.java b/client/test/src/org/apache/qpid/test/unit/client/message/BytesMessageTest.java
index 03bb65081f..8599b6338f 100644
--- a/client/test/src/org/apache/qpid/client/message/TestBytesMessage.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/message/BytesMessageTest.java
@@ -15,17 +15,19 @@
* limitations under the License.
*
*/
-package org.apache.qpid.client.message;
+package org.apache.qpid.test.unit.client.message;
import junit.framework.JUnit4TestAdapter;
import org.junit.Test;
import org.junit.Assert;
+import org.apache.qpid.client.message.JMSBytesMessage;
+import org.apache.qpid.client.message.TestMessageHelper;
import javax.jms.MessageNotReadableException;
import javax.jms.MessageNotWriteableException;
import javax.jms.MessageEOFException;
-public class TestBytesMessage
+public class BytesMessageTest
{
/**
* Tests that on creation a call to getBodyLength() throws an exception
@@ -34,14 +36,14 @@ public class TestBytesMessage
@Test(expected=MessageNotReadableException.class)
public void testNotReadableOnCreationWithNull() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.getBodyLength();
}
@Test(expected= MessageNotWriteableException.class)
public void testResetMakesReadble() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeInt(10);
bm.reset();
bm.writeInt(12);
@@ -50,7 +52,7 @@ public class TestBytesMessage
@Test
public void testClearBodyMakesWritable() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeInt(10);
bm.reset();
bm.clearBody();
@@ -60,7 +62,7 @@ public class TestBytesMessage
@Test
public void testWriteInt() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeInt(10);
bm.reset();
long len = bm.getBodyLength();
@@ -72,7 +74,7 @@ public class TestBytesMessage
@Test
public void testWriteString() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeUTF("Bananas");
bm.reset();
String res = bm.readUTF();
@@ -82,14 +84,14 @@ public class TestBytesMessage
@Test(expected=NullPointerException.class)
public void testWriteObjectThrowsNPE() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeObject(null);
}
@Test
public void testReadBoolean() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeBoolean(true);
bm.reset();
boolean result = bm.readBoolean();
@@ -99,7 +101,7 @@ public class TestBytesMessage
@Test(expected=MessageEOFException.class)
public void testEOFByte() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeByte((byte)1);
bm.reset();
bm.readByte();
@@ -110,7 +112,7 @@ public class TestBytesMessage
@Test(expected=MessageEOFException.class)
public void testEOFUnsignedByte() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeByte((byte)1);
bm.reset();
bm.readByte();
@@ -121,7 +123,7 @@ public class TestBytesMessage
@Test(expected=MessageEOFException.class)
public void testEOFBoolean() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeBoolean(true);
bm.reset();
bm.readBoolean();
@@ -132,7 +134,7 @@ public class TestBytesMessage
@Test(expected=MessageEOFException.class)
public void testEOFChar() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeChar('A');
bm.reset();
bm.readChar();
@@ -143,7 +145,7 @@ public class TestBytesMessage
@Test(expected=MessageEOFException.class)
public void testEOFDouble() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeDouble(1.3d);
bm.reset();
bm.readDouble();
@@ -154,7 +156,7 @@ public class TestBytesMessage
@Test(expected=MessageEOFException.class)
public void testEOFFloat() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeFloat(1.3f);
bm.reset();
bm.readFloat();
@@ -165,7 +167,7 @@ public class TestBytesMessage
@Test(expected=MessageEOFException.class)
public void testEOFInt() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeInt(99);
bm.reset();
bm.readInt();
@@ -176,7 +178,7 @@ public class TestBytesMessage
@Test(expected=MessageEOFException.class)
public void testEOFLong() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeLong(4L);
bm.reset();
bm.readLong();
@@ -187,7 +189,7 @@ public class TestBytesMessage
@Test(expected=MessageEOFException.class)
public void testEOFShort() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeShort((short)4);
bm.reset();
bm.readShort();
@@ -198,7 +200,7 @@ public class TestBytesMessage
@Test(expected=MessageEOFException.class)
public void testEOFUnsignedShort() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeShort((short)4);
bm.reset();
bm.readUnsignedShort();
@@ -214,7 +216,7 @@ public class TestBytesMessage
@Test
public void testReadBytes() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeByte((byte)3);
bm.writeByte((byte)4);
bm.reset();
@@ -228,7 +230,7 @@ public class TestBytesMessage
@Test
public void testReadBytesEOF() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeByte((byte)3);
bm.writeByte((byte)4);
bm.reset();
@@ -241,7 +243,7 @@ public class TestBytesMessage
@Test
public void testReadBytesWithLargerArray() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeByte((byte)3);
bm.writeByte((byte)4);
bm.reset();
@@ -256,7 +258,7 @@ public class TestBytesMessage
@Test
public void testReadBytesWithCount() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.writeByte((byte)3);
bm.writeByte((byte)4);
bm.writeByte((byte)5);
@@ -272,7 +274,7 @@ public class TestBytesMessage
@Test
public void testToBodyString() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
final String testText = "This is a test";
bm.writeUTF(testText);
bm.reset();
@@ -283,7 +285,7 @@ public class TestBytesMessage
@Test
public void testToBodyStringWithNull() throws Exception
{
- JMSBytesMessage bm = new JMSBytesMessage();
+ JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage();
bm.reset();
String result = bm.toBodyString();
Assert.assertNull(result);
@@ -291,6 +293,6 @@ public class TestBytesMessage
public static junit.framework.Test suite()
{
- return new JUnit4TestAdapter(TestBytesMessage.class);
+ return new JUnit4TestAdapter(BytesMessageTest.class);
}
}
diff --git a/client/test/src/org/apache/qpid/test/unit/client/message/MessageUnitTests.java b/client/test/src/org/apache/qpid/test/unit/client/message/MessageUnitTests.java
new file mode 100644
index 0000000000..a0aecee224
--- /dev/null
+++ b/client/test/src/org/apache/qpid/test/unit/client/message/MessageUnitTests.java
@@ -0,0 +1,35 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ */
+package org.apache.qpid.test.unit.client.message;
+
+
+import junit.framework.JUnit4TestAdapter;
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import org.apache.qpid.client.message.TextMessageTest;
+import org.apache.qpid.client.message.BytesMessageTest;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({BytesMessageTest.class, TextMessageTest.class})
+public class MessageUnitTests
+{
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(MessageUnitTests.class);
+ }
+}
diff --git a/client/test/src/org/apache/qpid/client/message/ObjectMessageTest.java b/client/test/src/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java
index a5e1a0d558..cd9299122d 100644
--- a/client/test/src/org/apache/qpid/client/message/ObjectMessageTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java
@@ -15,14 +15,18 @@
* limitations under the License.
*
*/
-package org.apache.qpid.client.message;
+package org.apache.qpid.test.unit.client.message;
import org.apache.qpid.client.AMQConnection;
import org.apache.qpid.client.AMQQueue;
import org.apache.qpid.client.AMQDestination;
import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import org.apache.qpid.client.transport.TransportConnection;
import org.junit.Before;
import org.junit.Test;
+import org.junit.Assert;
+import org.junit.After;
import javax.jms.MessageListener;
import javax.jms.MessageProducer;
@@ -45,6 +49,26 @@ public class ObjectMessageTest implements MessageListener
private int received;
private final ArrayList items = new ArrayList();
+
+ @Before
+ public void createVMBroker()
+ {
+ try
+ {
+ TransportConnection.createVMBroker(1);
+ }
+ catch (AMQVMBrokerCreationException e)
+ {
+ Assert.fail("Unable to create broker: " + e);
+ }
+ }
+
+ @After
+ public void stopVmBroker()
+ {
+ TransportConnection.killVMBroker(1);
+ }
+
ObjectMessageTest(String broker) throws Exception
{
this(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test_path"));
@@ -72,6 +96,7 @@ public class ObjectMessageTest implements MessageListener
data = new Serializable[]{a1, a2, b, c, "Hello World!", new Integer(1001)};
}
+
public void test() throws Exception
{
try
@@ -97,10 +122,10 @@ public class ObjectMessageTest implements MessageListener
MessageProducer producer = session.createProducer(destination, false, false, true);
- for(int i = 0; i < data.length; i++)
+ for (int i = 0; i < data.length; i++)
{
ObjectMessage msg;
- if(i % 2 == 0)
+ if (i % 2 == 0)
{
msg = session.createObjectMessage(data[i]);
}
@@ -116,21 +141,21 @@ public class ObjectMessageTest implements MessageListener
public void check() throws Exception
{
Object[] actual = (Object[]) items.toArray();
- if(actual.length != data.length)
+ if (actual.length != data.length)
{
throw new Exception("Expected " + data.length + " objects, got " + actual.length);
}
- for(int i = 0; i < data.length; i++)
+ for (int i = 0; i < data.length; i++)
{
- if(actual[i] instanceof Exception)
+ if (actual[i] instanceof Exception)
{
throw new Exception("Error on receive of " + data[i], ((Exception) actual[i]));
}
- if(actual[i] == null)
+ if (actual[i] == null)
{
throw new Exception("Expected " + data[i] + " got null");
}
- if(!data[i].equals(actual[i]))
+ if (!data[i].equals(actual[i]))
{
throw new Exception("Expected " + data[i] + " got " + actual[i]);
}
@@ -147,7 +172,7 @@ public class ObjectMessageTest implements MessageListener
private synchronized void waitUntilReceived(int count) throws InterruptedException
{
waiting = true;
- while(received < count)
+ while (received < count)
{
wait();
}
@@ -159,7 +184,7 @@ public class ObjectMessageTest implements MessageListener
received++;
try
{
- if(message instanceof ObjectMessage)
+ if (message instanceof ObjectMessage)
{
items.add(((ObjectMessage) message).getObject());
}
@@ -175,7 +200,8 @@ public class ObjectMessageTest implements MessageListener
items.add(e);
}
- if(waiting){
+ if (waiting)
+ {
synchronized(this)
{
notify();
@@ -183,15 +209,30 @@ public class ObjectMessageTest implements MessageListener
}
}
+
+ @Test
+ public void doJUnitTest()
+ {
+ try
+ {
+ new ObjectMessageTest("vm://:1").test();
+ }
+ catch (Exception e)
+ {
+ Assert.fail("This Test should succeed but failed due to: " + e);
+ }
+ }
+
public static void main(String[] argv) throws Exception
{
String broker = argv.length > 0 ? argv[0] : "vm://:1";
- if("-help".equals(broker))
+ if ("-help".equals(broker))
{
System.out.println("Usage: <broker>");
}
new ObjectMessageTest(broker).test();
}
+
private static class A implements Serializable
{
private String sValue;
diff --git a/client/test/src/org/apache/qpid/client/message/TestTextMessage.java b/client/test/src/org/apache/qpid/test/unit/client/message/TextMessageTest.java
index 766f47d841..e5768b51b3 100644
--- a/client/test/src/org/apache/qpid/client/message/TestTextMessage.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/message/TextMessageTest.java
@@ -15,18 +15,20 @@
* limitations under the License.
*
*/
-package org.apache.qpid.client.message;
+package org.apache.qpid.test.unit.client.message;
import junit.framework.JUnit4TestAdapter;
import org.junit.Test;
import org.junit.Assert;
+import org.apache.qpid.client.message.TestMessageHelper;
+import org.apache.qpid.client.message.JMSTextMessage;
-public class TestTextMessage
+public class TextMessageTest
{
@Test
public void testTextOnConstruction() throws Exception
{
- JMSTextMessage tm = new JMSTextMessage();
+ JMSTextMessage tm = TestMessageHelper.newJMSTextMessage();
tm.setText("pies");
String val = tm.getText();
Assert.assertEquals(val, "pies");
@@ -35,7 +37,7 @@ public class TestTextMessage
@Test
public void testClearBody() throws Exception
{
- JMSTextMessage tm = new JMSTextMessage();
+ JMSTextMessage tm = TestMessageHelper.newJMSTextMessage();
tm.setText("pies");
tm.clearBody();
String val = tm.getText();
@@ -46,6 +48,6 @@ public class TestTextMessage
}
public static junit.framework.Test suite()
{
- return new JUnit4TestAdapter(TestTextMessage.class);
+ return new JUnit4TestAdapter(TextMessageTest.class);
}
}
diff --git a/client/test/src/org/apache/qpid/client/protocol/TestAMQProtocolSession.java b/client/test/src/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java
index 15da927a0e..7134abc1f8 100644
--- a/client/test/src/org/apache/qpid/client/protocol/TestAMQProtocolSession.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java
@@ -1,114 +1,116 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-package org.apache.qpid.client.protocol;
-
-import org.apache.qpid.client.AMQConnection;
-import org.apache.mina.common.IoSession;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.After;
-import junit.framework.JUnit4TestAdapter;
-import junit.framework.Assert;
-
-public class TestAMQProtocolSession extends AMQProtocolSession {
-
- //private Strings for test values and expected results
- private String _brokenAddress;
- private String _generatedAddress;
- private String _emptyAddress;
- private String _generatedAddress_2;
- private String _validAddress;
- private String _generatedAddress_3;
- private int _port;
- private TestAMQProtocolSession _testSession;
-
- public TestAMQProtocolSession()
- {
-
- }
-
- public TestAMQProtocolSession(AMQProtocolHandler protocolHandler, IoSession protocolSession, AMQConnection connection)
- {
- super(protocolHandler,protocolSession,connection);
- }
-
- public TestIoSession getMinaProtocolSession()
- {
- return (TestIoSession) _minaProtocolSession;
- }
-
- @Before
- public void setUp()
- {
- //don't care about the values set here apart from the dummy IoSession
- _testSession = new TestAMQProtocolSession(null,new TestIoSession(),null);
-
- //initialise addresses for test and expected results
- _port = 123;
- _brokenAddress = "tcp://myAddress;:";
- _generatedAddress = "tmp_tcpmyAddress123_1";
- _emptyAddress = "";
- _generatedAddress_2 = "tmp_localhost127.0.0.1123_2";
- _validAddress = "abc";
- _generatedAddress_3 = "tmp_abc123_3";
-
- }
-
- @Test
- public void TestGenerateQueueName()
- {
- String testAddress;
-
- //test address with / and ; chars which generateQueueName should remove
- _testSession.getMinaProtocolSession().setStringLocalAddress(_brokenAddress);
- _testSession.getMinaProtocolSession().setLocalPort(_port);
-
- testAddress = _testSession.generateQueueName();
- Assert.assertEquals("Failure when generating a queue name from an address with special chars",_generatedAddress,testAddress);
-
- //test empty address
- _testSession.getMinaProtocolSession().setStringLocalAddress(_emptyAddress);
-
- testAddress = _testSession.generateQueueName();
- Assert.assertEquals("Failure when generating a queue name from an empty address",_generatedAddress_2,testAddress);
-
- //test address with no special chars
- _testSession.getMinaProtocolSession().setStringLocalAddress(_validAddress);
-
- testAddress = _testSession.generateQueueName();
- Assert.assertEquals("Failure when generating a queue name from an address with no special chars",_generatedAddress_3,testAddress);
-
- }
-
- public static junit.framework.Test suite()
- {
- return new JUnit4TestAdapter(TestAMQProtocolSession.class);
- }
-
- @After
- public void tearDown()
- {
- _testSession = null;
- _brokenAddress = null;
- _generatedAddress = null;
- _emptyAddress = null;
- _generatedAddress_2 = null;
- _validAddress = null;
- _generatedAddress_3 = null;
- }
-}
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ */
+package org.apache.qpid.test.unit.client.protocol;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.protocol.AMQProtocolHandler;
+import org.apache.qpid.client.protocol.AMQProtocolSession;
+import org.apache.mina.common.IoSession;
+import org.junit.Before;
+import org.junit.Test;
+import org.junit.After;
+import junit.framework.JUnit4TestAdapter;
+import junit.framework.Assert;
+
+public class AMQProtocolSessionTest extends AMQProtocolSession
+{
+ //private Strings for test values and expected results
+ private String _brokenAddress;
+ private String _generatedAddress;
+ private String _emptyAddress;
+ private String _generatedAddress_2;
+ private String _validAddress;
+ private String _generatedAddress_3;
+ private int _port;
+ private AMQProtocolSessionTest _testSession;
+
+ public AMQProtocolSessionTest()
+ {
+
+ }
+
+ public AMQProtocolSessionTest(AMQProtocolHandler protocolHandler, IoSession protocolSession, AMQConnection connection)
+ {
+ super(protocolHandler,protocolSession,connection);
+ }
+
+ public TestIoSession getMinaProtocolSession()
+ {
+ return (TestIoSession) _minaProtocolSession;
+ }
+
+ @Before
+ public void setUp()
+ {
+ //don't care about the values set here apart from the dummy IoSession
+ _testSession = new AMQProtocolSessionTest(null,new TestIoSession(),null);
+
+ //initialise addresses for test and expected results
+ _port = 123;
+ _brokenAddress = "tcp://myAddress;:";
+ _generatedAddress = "tmp_tcpmyAddress123_1";
+ _emptyAddress = "";
+ _generatedAddress_2 = "tmp_localhost127.0.0.1123_2";
+ _validAddress = "abc";
+ _generatedAddress_3 = "tmp_abc123_3";
+
+ }
+
+ @Test
+ public void TestGenerateQueueName()
+ {
+ String testAddress;
+
+ //test address with / and ; chars which generateQueueName should remove
+ _testSession.getMinaProtocolSession().setStringLocalAddress(_brokenAddress);
+ _testSession.getMinaProtocolSession().setLocalPort(_port);
+
+ testAddress = _testSession.generateQueueName();
+ Assert.assertEquals("Failure when generating a queue name from an address with special chars",_generatedAddress,testAddress);
+
+ //test empty address
+ _testSession.getMinaProtocolSession().setStringLocalAddress(_emptyAddress);
+
+ testAddress = _testSession.generateQueueName();
+ Assert.assertEquals("Failure when generating a queue name from an empty address",_generatedAddress_2,testAddress);
+
+ //test address with no special chars
+ _testSession.getMinaProtocolSession().setStringLocalAddress(_validAddress);
+
+ testAddress = _testSession.generateQueueName();
+ Assert.assertEquals("Failure when generating a queue name from an address with no special chars",_generatedAddress_3,testAddress);
+
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(AMQProtocolSessionTest.class);
+ }
+
+ @After
+ public void tearDown()
+ {
+ _testSession = null;
+ _brokenAddress = null;
+ _generatedAddress = null;
+ _emptyAddress = null;
+ _generatedAddress_2 = null;
+ _validAddress = null;
+ _generatedAddress_3 = null;
+ }
+}
diff --git a/client/test/src/org/apache/qpid/client/protocol/TestIoSession.java b/client/test/src/org/apache/qpid/test/unit/client/protocol/TestIoSession.java
index fd9565ba5f..7a54a7039c 100644
--- a/client/test/src/org/apache/qpid/client/protocol/TestIoSession.java
+++ b/client/test/src/org/apache/qpid/test/unit/client/protocol/TestIoSession.java
@@ -1,96 +1,96 @@
-/*
- *
- * Copyright (c) 2006 The Apache Software Foundation
- *
- * Licensed 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.
- *
- */
-package org.apache.qpid.client.protocol;
-
-import org.apache.mina.common.support.BaseIoSession;
-import org.apache.mina.common.*;
-
-import java.net.SocketAddress;
-import java.net.InetSocketAddress;
-
-public class TestIoSession extends BaseIoSession {
-
- private String _stringLocalAddress;
- private int _localPort;
-
- public SocketAddress getLocalAddress()
- {
- //create a new address for testing purposes using member variables
- return new InetSocketAddress(_stringLocalAddress,_localPort);
- }
-
- protected void updateTrafficMask() {
- //dummy
- }
-
- public IoService getService() {
- return null;
- }
-
- public IoServiceConfig getServiceConfig() {
- return null;
- }
-
- public IoHandler getHandler() {
- return null;
- }
-
- public IoSessionConfig getConfig() {
- return null;
- }
-
- public IoFilterChain getFilterChain() {
- return null;
- }
-
- public TransportType getTransportType() {
- return null;
- }
-
- public SocketAddress getRemoteAddress() {
- return null;
- }
-
- public SocketAddress getServiceAddress() {
- return null;
- }
-
- public int getScheduledWriteRequests() {
- return 0;
- }
-
- public int getScheduledWriteBytes() {
- return 0;
- }
-
- public String getStringLocalAddress() {
- return _stringLocalAddress;
- }
-
- public void setStringLocalAddress(String _stringLocalAddress) {
- this._stringLocalAddress = _stringLocalAddress;
- }
-
- public int getLocalPort() {
- return _localPort;
- }
-
- public void setLocalPort(int _localPort) {
- this._localPort = _localPort;
- }
-}
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ */
+package org.apache.qpid.test.unit.client.protocol;
+
+import org.apache.mina.common.support.BaseIoSession;
+import org.apache.mina.common.*;
+
+import java.net.SocketAddress;
+import java.net.InetSocketAddress;
+
+public class TestIoSession extends BaseIoSession {
+
+ private String _stringLocalAddress;
+ private int _localPort;
+
+ public SocketAddress getLocalAddress()
+ {
+ //create a new address for testing purposes using member variables
+ return new InetSocketAddress(_stringLocalAddress,_localPort);
+ }
+
+ protected void updateTrafficMask() {
+ //dummy
+ }
+
+ public IoService getService() {
+ return null;
+ }
+
+ public IoServiceConfig getServiceConfig() {
+ return null;
+ }
+
+ public IoHandler getHandler() {
+ return null;
+ }
+
+ public IoSessionConfig getConfig() {
+ return null;
+ }
+
+ public IoFilterChain getFilterChain() {
+ return null;
+ }
+
+ public TransportType getTransportType() {
+ return null;
+ }
+
+ public SocketAddress getRemoteAddress() {
+ return null;
+ }
+
+ public SocketAddress getServiceAddress() {
+ return null;
+ }
+
+ public int getScheduledWriteRequests() {
+ return 0;
+ }
+
+ public int getScheduledWriteBytes() {
+ return 0;
+ }
+
+ public String getStringLocalAddress() {
+ return _stringLocalAddress;
+ }
+
+ public void setStringLocalAddress(String _stringLocalAddress) {
+ this._stringLocalAddress = _stringLocalAddress;
+ }
+
+ public int getLocalPort() {
+ return _localPort;
+ }
+
+ public void setLocalPort(int _localPort) {
+ this._localPort = _localPort;
+ }
+}
diff --git a/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java b/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java
new file mode 100644
index 0000000000..a867a6d6e3
--- /dev/null
+++ b/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java
@@ -0,0 +1,210 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ */
+package org.apache.qpid.test.unit.jndi.referenceabletest;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.client.AMQTopic;
+import org.apache.qpid.url.URLSyntaxException;
+import org.junit.Assert;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.jms.Session;
+import javax.jms.Topic;
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NamingException;
+import javax.naming.NoInitialContextException;
+import java.io.File;
+import java.util.Hashtable;
+
+/**
+ * Usage: To run these you need to have the sun JNDI SPI for the FileSystem.
+ * This can be downloaded from sun here:
+ * http://java.sun.com/products/jndi/downloads/index.html
+ * Click : Download JNDI 1.2.1 & More button
+ * Download: File System Service Provider, 1.2 Beta 3
+ * and add the two jars in the lib dir to your class path.
+ * <p/>
+ * Also you need to create the directory /temp/qpid-jndi-test
+ */
+class Bind
+{
+ public static final String DEFAULT_PROVIDER_FILE_PATH = System.getProperty("java.io.tmpdir") + "/JNDITest";
+ public static final String PROVIDER_URL = "file://" + DEFAULT_PROVIDER_FILE_PATH;
+
+ String _connectionFactoryString = "";
+
+ String _connectionString = "amqp://guest:guest@clientid/testpath?brokerlist='vm://:1'";
+ Topic _topic = null;
+
+ boolean _bound = false;
+
+ public Bind() throws NameAlreadyBoundException, NoInitialContextException
+ {
+ this(false);
+ }
+
+ public Bind(boolean output) throws NameAlreadyBoundException, NoInitialContextException
+ {
+ // Set up the environment for creating the initial context
+ Hashtable env = new Hashtable(11);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "com.sun.jndi.fscontext.RefFSContextFactory");
+ env.put(Context.PROVIDER_URL, PROVIDER_URL);
+
+
+ File file = new File(PROVIDER_URL.substring(PROVIDER_URL.indexOf("://") + 3));
+
+ if (file.exists() && !file.isDirectory())
+ {
+ System.out.println("Couldn't make directory file already exists");
+ return;
+ }
+ else
+ {
+ if (!file.exists())
+ {
+ if (!file.mkdirs())
+ {
+ System.out.println("Couldn't make directory");
+ return;
+ }
+ }
+ }
+
+ Connection connection = null;
+ try
+ {
+ // Create the initial context
+ Context ctx = new InitialContext(env);
+
+ // Create the connection factory to be bound
+ ConnectionFactory connectionFactory = null;
+ // Create the Connection to be bound
+
+
+ try
+ {
+ connectionFactory = new AMQConnectionFactory(_connectionString);
+ connection = connectionFactory.createConnection();
+
+ _connectionFactoryString = ((AMQConnectionFactory) connectionFactory).getConnectionURL().getURL();
+ }
+ catch (JMSException jmsqe)
+ {
+ Assert.fail("Unable to create Connection:" + jmsqe);
+ }
+ catch (URLSyntaxException urlse)
+ {
+ Assert.fail("Unable to create Connection:" + urlse);
+ }
+
+ try
+ {
+ Session session = connection.createSession(false, Session.AUTO_ACKNOWLEDGE);
+
+ _topic = session.createTopic("Fruity");
+ }
+ catch (JMSException jmse)
+ {
+
+ }
+ // Perform the binds
+ ctx.bind("ConnectionFactory", connectionFactory);
+ if (output)
+ {
+ System.out.println("Bound factory\n" + ((AMQConnectionFactory) connectionFactory).getConnectionURL());
+ }
+ ctx.bind("Connection", connection);
+ if (output)
+ {
+ System.out.println("Bound Connection\n" + ((AMQConnection) connection).toURL());
+ }
+ ctx.bind("Topic", _topic);
+ if (output)
+ {
+ System.out.println("Bound Topic:\n" + ((AMQTopic) _topic).toURL());
+ }
+ _bound = true;
+
+ // Check that it is bound
+ //Object obj = ctx.lookup("Connection");
+ //System.out.println(((AMQConnection)obj).toURL());
+
+ // Close the context when we're done
+ ctx.close();
+ }
+ catch (NamingException e)
+ {
+ System.out.println("Operation failed: " + e);
+ if (e instanceof NameAlreadyBoundException)
+ {
+ throw(NameAlreadyBoundException) e;
+ }
+
+ if (e instanceof NoInitialContextException)
+ {
+ throw(NoInitialContextException) e;
+ }
+ }
+ finally
+ {
+ try
+ {
+ if (connection != null)
+ {
+ connection.close();
+ }
+ }
+ catch (JMSException e)
+ {
+ //ignore just want it closed
+ }
+ }
+ }
+
+ public String connectionFactoryValue()
+ {
+ return _connectionFactoryString;
+ }
+
+ public String connectionValue()
+ {
+ return _connectionString;
+ }
+
+ public String topicValue()
+ {
+ return ((AMQTopic) _topic).toURL();
+ }
+
+ public boolean bound()
+ {
+ return _bound;
+ }
+
+ public static void main(String[] args) throws NameAlreadyBoundException, NoInitialContextException
+ {
+ new Bind(true);
+ }
+}
+
diff --git a/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java b/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java
new file mode 100644
index 0000000000..aadc154563
--- /dev/null
+++ b/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java
@@ -0,0 +1,123 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ */
+package org.apache.qpid.test.unit.jndi.referenceabletest;
+
+import org.junit.Test;
+import org.junit.Assert;
+import org.junit.After;
+import org.junit.Before;
+import org.apache.qpid.client.transport.TransportConnection;
+import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException;
+import junit.framework.JUnit4TestAdapter;
+
+import javax.naming.NameAlreadyBoundException;
+import javax.naming.NoInitialContextException;
+
+
+/**
+ * Usage: To run these you need to have the sun JNDI SPI for the FileSystem.
+ * This can be downloaded from sun here:
+ * http://java.sun.com/products/jndi/downloads/index.html
+ * Click : Download JNDI 1.2.1 & More button
+ * Download: File System Service Provider, 1.2 Beta 3
+ * and add the two jars in the lib dir to your class path.
+ * <p/>
+ * Also you need to create the directory /temp/qpid-jndi-test
+ */
+public class JNDIReferenceableTest
+{
+ @Before
+ public void createVMBroker()
+ {
+ try
+ {
+ TransportConnection.createVMBroker(1);
+ }
+ catch (AMQVMBrokerCreationException e)
+ {
+ Assert.fail("Unable to create broker: " + e);
+ }
+ }
+
+ @After
+ public void stopVmBroker()
+ {
+ TransportConnection.killVMBroker(1);
+ }
+
+ @Test
+ public void referenceable()
+ {
+ Bind b = null;
+ try
+ {
+ try
+ {
+ b = new Bind();
+ }
+ catch (NameAlreadyBoundException e)
+ {
+ if (new Unbind().unbound())
+ {
+ try
+ {
+ b = new Bind();
+ }
+ catch (NameAlreadyBoundException ee)
+ {
+ Assert.fail("Unable to clear bound objects for test.");
+ }
+ }
+ else
+ {
+ Assert.fail("Unable to clear bound objects for test.");
+ }
+ }
+ }
+ catch (NoInitialContextException e)
+ {
+ Assert.fail("You don't have the File System SPI on you class path.\n" +
+ "This can be downloaded from sun here:\n" +
+ "http://java.sun.com/products/jndi/downloads/index.html\n" +
+ "Click : Download JNDI 1.2.1 & More button\n" +
+ "Download: File System Service Provider, 1.2 Beta 3\n" +
+ "and add the two jars in the lib dir to your class path.");
+ }
+
+ Assert.assertTrue(b.bound());
+
+ Lookup l = new Lookup();
+
+ Assert.assertTrue(l.connectionFactoryValue().equals(b.connectionFactoryValue()));
+
+ Assert.assertTrue(l.connectionValue().equals(b.connectionValue()));
+
+ Assert.assertTrue(l.topicValue().equals(b.topicValue()));
+
+
+ Unbind u = new Unbind();
+
+ Assert.assertTrue(u.unbound());
+
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(JNDIReferenceableTest.class);
+ }
+}
diff --git a/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Lookup.java b/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Lookup.java
new file mode 100644
index 0000000000..e2aed5d413
--- /dev/null
+++ b/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Lookup.java
@@ -0,0 +1,136 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ */
+package org.apache.qpid.test.unit.jndi.referenceabletest;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.client.AMQTopic;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.jms.JMSException;
+import java.io.File;
+import java.util.Hashtable;
+
+
+/**
+ * Usage: To run these you need to have the sun JNDI SPI for the FileSystem.
+ * This can be downloaded from sun here:
+ * http://java.sun.com/products/jndi/downloads/index.html
+ * Click : Download JNDI 1.2.1 & More button
+ * Download: File System Service Provider, 1.2 Beta 3
+ * and add the two jars in the lib dir to your class path.
+ * <p/>
+ * Also you need to create the directory /temp/qpid-jndi-test
+ */
+class Lookup
+{
+ public static final String DEFAULT_PROVIDER_FILE_PATH = System.getProperty("java.io.tmpdir") + "/JNDITest";
+ public static final String PROVIDER_URL = "file://" + DEFAULT_PROVIDER_FILE_PATH;
+
+ AMQTopic _topic = null;
+ AMQConnection _connection = null;
+ AMQConnectionFactory _connectionFactory = null;
+ private String _connectionURL;
+
+ public Lookup()
+ {
+ // Set up the environment for creating the initial context
+ Hashtable env = new Hashtable(11);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "com.sun.jndi.fscontext.RefFSContextFactory");
+ env.put(Context.PROVIDER_URL, PROVIDER_URL);
+
+ File file = new File(PROVIDER_URL.substring(PROVIDER_URL.indexOf("://") + 3));
+
+ if (file.exists() && !file.isDirectory())
+ {
+ System.out.println("Couldn't make directory file already exists");
+ return;
+ }
+ else
+ {
+ if (!file.exists())
+ {
+ if (!file.mkdirs())
+ {
+ System.out.println("Couldn't make directory");
+ return;
+ }
+ }
+ }
+
+ try
+ {
+ // Create the initial context
+ Context ctx = new InitialContext(env);
+
+ _topic = (AMQTopic) ctx.lookup("Topic");
+
+ _connection = (AMQConnection) ctx.lookup("Connection");
+
+ _connectionURL = _connection.toURL();
+
+ _connectionFactory = (AMQConnectionFactory) ctx.lookup("ConnectionFactory");
+ //System.out.println(topic);
+
+ // Close the context when we're done
+ ctx.close();
+ }
+ catch (NamingException e)
+ {
+ System.out.println("Operation failed: " + e);
+ }
+ finally
+ {
+ try
+ {
+ if (_connection != null)
+ {
+ _connection.close();
+ }
+ }
+ catch (JMSException e)
+ {
+ //ignore just need to close
+ }
+ }
+ }
+
+ public String connectionFactoryValue()
+ {
+ return _connectionFactory.getConnectionURL().toString();
+ }
+
+ public String connectionValue()
+ {
+ return _connectionURL;
+ }
+
+ public String topicValue()
+ {
+ return _topic.toURL();
+ }
+
+ public static void main(String[] args)
+ {
+ new Lookup();
+ }
+}
+
diff --git a/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Unbind.java b/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Unbind.java
new file mode 100644
index 0000000000..34a1454d8a
--- /dev/null
+++ b/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Unbind.java
@@ -0,0 +1,158 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ */
+package org.apache.qpid.test.unit.jndi.referenceabletest;
+
+import javax.naming.Context;
+import javax.naming.InitialContext;
+import javax.naming.NameNotFoundException;
+import javax.naming.NamingException;
+import javax.jms.Connection;
+import javax.jms.JMSException;
+import java.io.File;
+import java.util.Hashtable;
+
+/**
+ * Usage: To run these you need to have the sun JNDI SPI for the FileSystem.
+ * This can be downloaded from sun here:
+ * http://java.sun.com/products/jndi/downloads/index.html
+ * Click : Download JNDI 1.2.1 & More button
+ * Download: File System Service Provider, 1.2 Beta 3
+ * and add the two jars in the lib dir to your class path.
+ * <p/>
+ * Also you need to create the directory /temp/qpid-jndi-test
+ */
+class Unbind
+{
+ public static final String DEFAULT_PROVIDER_FILE_PATH = System.getProperty("java.io.tmpdir") + "/JNDITest";
+ public static final String PROVIDER_URL = "file://" + DEFAULT_PROVIDER_FILE_PATH;
+
+ boolean _unbound = false;
+
+ public Unbind()
+ {
+ this(false);
+ }
+
+ public Unbind(boolean output)
+ {
+ // Set up the environment for creating the initial context
+ Hashtable env = new Hashtable(11);
+ env.put(Context.INITIAL_CONTEXT_FACTORY,
+ "com.sun.jndi.fscontext.RefFSContextFactory");
+ env.put(Context.PROVIDER_URL, PROVIDER_URL);
+
+ File file = new File(PROVIDER_URL.substring(PROVIDER_URL.indexOf("://") + 3));
+
+ if (file.exists() && !file.isDirectory())
+ {
+ System.out.println("Couldn't make directory file already exists");
+ return;
+ }
+ else
+ {
+ if (!file.exists())
+ {
+ if (!file.mkdirs())
+ {
+ System.out.println("Couldn't make directory");
+ return;
+ }
+ }
+ }
+
+ try
+ {
+ // Create the initial context
+ Context ctx = new InitialContext(env);
+
+ // Remove the binding
+ ctx.unbind("ConnectionFactory");
+ ctx.unbind("Connection");
+ ctx.unbind("Topic");
+
+ // Check that it is gone
+ Object obj = null;
+ try
+ {
+ obj = ctx.lookup("ConnectionFactory");
+ }
+ catch (NameNotFoundException ne)
+ {
+ if (output)
+ {
+ System.out.println("unbind ConnectionFactory successful");
+ }
+ try
+ {
+ obj = ctx.lookup("Connection");
+ try
+ {
+ ((Connection) obj).close();
+ }
+ catch (JMSException e)
+ {
+ //ignore just need to close
+ }
+ }
+ catch (NameNotFoundException ne2)
+ {
+ if (output)
+ {
+ System.out.println("unbind Connection successful");
+ }
+
+ try
+ {
+ obj = ctx.lookup("Topic");
+ }
+ catch (NameNotFoundException ne3)
+ {
+ if (output)
+ {
+ System.out.println("unbind Topic successful");
+ }
+ _unbound = true;
+ }
+ }
+ }
+
+ //System.out.println("unbind failed; object still there: " + obj);
+
+ // Close the context when we're done
+
+ ctx.close();
+
+ }
+ catch (NamingException e)
+ {
+ System.out.println("Operation failed: " + e);
+ }
+ }
+
+ public boolean unbound()
+ {
+ return _unbound;
+ }
+
+ public static void main(String[] args)
+ {
+
+ new Unbind(true);
+ }
+}
+
diff --git a/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java b/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java
new file mode 100644
index 0000000000..6dc4d2df0e
--- /dev/null
+++ b/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java
@@ -0,0 +1,32 @@
+/*
+ *
+ * Copyright (c) 2006 The Apache Software Foundation
+ *
+ * Licensed 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.
+ *
+ */
+package org.apache.qpid.test.unit.jndi.referenceabletest;
+
+import org.junit.runner.RunWith;
+import org.junit.runners.Suite;
+import junit.framework.JUnit4TestAdapter;
+
+@RunWith(Suite.class)
+@Suite.SuiteClasses({JNDIReferenceableTest.class})
+public class UnitTests
+{
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(UnitTests.class);
+ }
+}
diff --git a/client/test/src/org/apache/qpid/topic/DurableSubscriptionTest.java b/client/test/src/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
index 0f190c73a9..db872e6742 100644
--- a/client/test/src/org/apache/qpid/topic/DurableSubscriptionTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.topic;
+package org.apache.qpid.test.unit.topic;
import junit.framework.JUnit4TestAdapter;
import org.junit.Assert;
@@ -40,6 +40,26 @@ import javax.jms.TopicSubscriber;
public class DurableSubscriptionTest
{
+
+ @Before
+ public void createVMBroker()
+ {
+ try
+ {
+ TransportConnection.createVMBroker(1);
+ }
+ catch (AMQVMBrokerCreationException e)
+ {
+ Assert.fail("Unable to create broker: " + e);
+ }
+ }
+
+ @After
+ public void stopVmBroker()
+ {
+ TransportConnection.killVMBroker(1);
+ }
+
@Test
public void unsubscribe() throws AMQException, JMSException, URLSyntaxException
{
@@ -52,22 +72,7 @@ public class DurableSubscriptionTest
Session session2 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE);
TopicSubscriber consumer2 = session2.createDurableSubscriber(topic, "MySubscription");
- con.start();
-
- // Sleep to ensure all queues have been created in the Broker.
- try
- {
- System.out.println("Allowing Server to create queues");
- Thread.sleep(2000);
- }
- catch (InterruptedException e)
- {
- //do nothing
- }
- finally
- {
- System.out.println("Setup Complete");
- }
+ con.start();
producer.send(session1.createTextMessage("A"));
diff --git a/client/test/src/org/apache/qpid/transacted/TransactedTest.java b/client/test/src/org/apache/qpid/test/unit/transacted/TransactedTest.java
index 765d3ab168..2040276469 100644
--- a/client/test/src/org/apache/qpid/transacted/TransactedTest.java
+++ b/client/test/src/org/apache/qpid/test/unit/transacted/TransactedTest.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.transacted;
+package org.apache.qpid.test.unit.transacted;
import junit.framework.JUnit4TestAdapter;
import org.apache.qpid.client.AMQConnection;
@@ -48,7 +48,7 @@ public class TransactedTest
private Session prepSession;
private MessageProducer prepProducer1;
- private AMQConnection testCon;
+ private AMQConnection testCon;
private Session testSession;
private MessageConsumer testConsumer1;
private MessageConsumer testConsumer2;
diff --git a/client/test/src/org/apache/qpid/transacted/UnitTests.java b/client/test/src/org/apache/qpid/test/unit/transacted/UnitTests.java
index 8d43287d6f..d3a161820f 100644
--- a/client/test/src/org/apache/qpid/transacted/UnitTests.java
+++ b/client/test/src/org/apache/qpid/test/unit/transacted/UnitTests.java
@@ -15,7 +15,7 @@
* limitations under the License.
*
*/
-package org.apache.qpid.transacted;
+package org.apache.qpid.test.unit.transacted;
import junit.framework.JUnit4TestAdapter;
import org.junit.runner.RunWith;