From 2e13c279b6a75b39a70dfadeb41ca606e12bb279 Mon Sep 17 00:00:00 2001 From: Martin Ritchie Date: Wed, 8 Nov 2006 12:12:24 +0000 Subject: 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@472458 13f79535-47bb-0310-9956-ffa450edef68 --- .../qpid/ack/DisconnectAndRedeliverTest.java | 234 ----------- .../test/src/org/apache/qpid/ack/RecoverTest.java | 134 ------ .../test/src/org/apache/qpid/ack/UnitTests.java | 32 -- .../org/apache/qpid/basic/BytesMessageTest.java | 231 ----------- .../qpid/basic/FieldTableKeyEnumeratorTest.java | 83 ---- .../apache/qpid/basic/FieldTableMessageTest.java | 180 -------- .../apache/qpid/basic/MultipleConnectionTest.java | 218 ---------- .../org/apache/qpid/basic/ObjectMessageTest.java | 230 ----------- .../src/org/apache/qpid/basic/ReceiveTest.java | 80 ---- .../org/apache/qpid/basic/SessionStartTest.java | 132 ------ .../src/org/apache/qpid/basic/TextMessageTest.java | 201 --------- .../test/src/org/apache/qpid/basic/UnitTests.java | 41 -- .../org/apache/qpid/client/AllClientUnitTests.java | 47 --- .../org/apache/qpid/client/TestAMQConnection.java | 138 ------- .../src/org/apache/qpid/client/TestAMQSession.java | 135 ------ .../client/channelclose/ChannelCloseOkTest.java | 235 ----------- .../apache/qpid/client/channelclose/UnitTests.java | 34 -- .../qpid/client/message/ObjectMessageTest.java | 252 ------------ .../qpid/client/message/TestBytesMessage.java | 296 -------------- .../qpid/client/message/TestMessageHelper.java | 34 ++ .../qpid/client/message/TestTextMessage.java | 51 --- .../org/apache/qpid/client/message/UnitTests.java | 32 -- .../client/protocol/TestAMQProtocolSession.java | 114 ------ .../apache/qpid/client/protocol/TestIoSession.java | 96 ----- .../org/apache/qpid/connection/ConnectionTest.java | 101 ----- .../qpid/connection/TestManyConnections.java | 99 ----- .../qpid/connectionurl/ConnectionURLTest.java | 449 -------------------- .../org/apache/qpid/connectionurl/UnitTests.java | 33 -- .../qpid/destinationurl/DestinationURLTest.java | 150 ------- .../org/apache/qpid/destinationurl/UnitTests.java | 33 -- .../apache/qpid/failover/FailoverBrokerTester.java | 268 ------------ .../qpid/failover/FailoverMultiMethodTest.java | 258 ------------ .../qpid/failover/FailoverRoundRobinTest.java | 233 ----------- .../qpid/failover/FailoverSingleServerTest.java | 257 ------------ .../src/org/apache/qpid/failover/FailoverTest.java | 249 ----------- .../org/apache/qpid/failover/FailoverTxTest.java | 179 -------- .../src/org/apache/qpid/forwardall/Client.java | 106 ----- .../src/org/apache/qpid/forwardall/Combined.java | 72 ---- .../src/org/apache/qpid/forwardall/Service.java | 81 ---- .../org/apache/qpid/forwardall/ServiceCreator.java | 103 ----- .../org/apache/qpid/forwardall/SpecialQueue.java | 41 -- .../src/org/apache/qpid/forwardall/UnitTests.java | 34 -- .../org/apache/qpid/framing/FieldTableTest.java | 160 -------- .../test/unit/ack/DisconnectAndRedeliverTest.java | 234 +++++++++++ .../org/apache/qpid/test/unit/ack/RecoverTest.java | 134 ++++++ .../org/apache/qpid/test/unit/ack/UnitTests.java | 32 ++ .../qpid/test/unit/basic/BytesMessageTest.java | 231 +++++++++++ .../unit/basic/FieldTableKeyEnumeratorTest.java | 85 ++++ .../test/unit/basic/FieldTableMessageTest.java | 179 ++++++++ .../test/unit/basic/MultipleConnectionTest.java | 244 +++++++++++ .../qpid/test/unit/basic/ObjectMessageTest.java | 237 +++++++++++ .../apache/qpid/test/unit/basic/ReceiveTest.java | 113 +++++ .../qpid/test/unit/basic/SessionStartTest.java | 139 +++++++ .../qpid/test/unit/basic/TextMessageTest.java | 209 ++++++++++ .../org/apache/qpid/test/unit/basic/UnitTests.java | 41 ++ .../qpid/test/unit/client/AMQConnectionTest.java | 142 +++++++ .../qpid/test/unit/client/AMQSessionTest.java | 139 +++++++ .../qpid/test/unit/client/AllClientUnitTests.java | 47 +++ .../client/channelclose/ChannelCloseOkTest.java | 235 +++++++++++ .../test/unit/client/channelclose/UnitTests.java | 34 ++ .../unit/client/connection/ConnectionTest.java | 135 ++++++ .../client/connection/TestManyConnections.java | 99 +++++ .../client/connectionurl/ConnectionURLTest.java | 455 +++++++++++++++++++++ .../test/unit/client/connectionurl/UnitTests.java | 32 ++ .../client/destinationurl/DestinationURLTest.java | 150 +++++++ .../test/unit/client/destinationurl/UnitTests.java | 32 ++ .../qpid/test/unit/client/forwardall/Client.java | 106 +++++ .../test/unit/client/forwardall/CombinedTest.java | 72 ++++ .../qpid/test/unit/client/forwardall/Service.java | 81 ++++ .../unit/client/forwardall/ServiceCreator.java | 103 +++++ .../test/unit/client/forwardall/SpecialQueue.java | 41 ++ .../test/unit/client/forwardall/UnitTests.java | 34 ++ .../test/unit/client/message/BytesMessageTest.java | 298 ++++++++++++++ .../test/unit/client/message/MessageUnitTests.java | 35 ++ .../unit/client/message/ObjectMessageTest.java | 293 +++++++++++++ .../test/unit/client/message/TextMessageTest.java | 53 +++ .../client/protocol/AMQProtocolSessionTest.java | 116 ++++++ .../test/unit/client/protocol/TestIoSession.java | 96 +++++ .../test/unit/jndi/referenceabletest/Bind.java | 210 ++++++++++ .../referenceabletest/JNDIReferenceableTest.java | 123 ++++++ .../test/unit/jndi/referenceabletest/Lookup.java | 136 ++++++ .../test/unit/jndi/referenceabletest/Unbind.java | 158 +++++++ .../unit/jndi/referenceabletest/UnitTests.java | 32 ++ .../test/unit/topic/DurableSubscriptionTest.java | 157 +++++++ .../qpid/test/unit/transacted/TransactedTest.java | 170 ++++++++ .../qpid/test/unit/transacted/UnitTests.java | 32 ++ .../apache/qpid/topic/DurableSubscriptionTest.java | 152 ------- .../org/apache/qpid/transacted/TransactedTest.java | 170 -------- .../src/org/apache/qpid/transacted/UnitTests.java | 32 -- 89 files changed, 5758 insertions(+), 6486 deletions(-) delete mode 100644 java/client/test/src/org/apache/qpid/ack/DisconnectAndRedeliverTest.java delete mode 100644 java/client/test/src/org/apache/qpid/ack/RecoverTest.java delete mode 100644 java/client/test/src/org/apache/qpid/ack/UnitTests.java delete mode 100644 java/client/test/src/org/apache/qpid/basic/BytesMessageTest.java delete mode 100644 java/client/test/src/org/apache/qpid/basic/FieldTableKeyEnumeratorTest.java delete mode 100644 java/client/test/src/org/apache/qpid/basic/FieldTableMessageTest.java delete mode 100644 java/client/test/src/org/apache/qpid/basic/MultipleConnectionTest.java delete mode 100644 java/client/test/src/org/apache/qpid/basic/ObjectMessageTest.java delete mode 100644 java/client/test/src/org/apache/qpid/basic/ReceiveTest.java delete mode 100644 java/client/test/src/org/apache/qpid/basic/SessionStartTest.java delete mode 100644 java/client/test/src/org/apache/qpid/basic/TextMessageTest.java delete mode 100644 java/client/test/src/org/apache/qpid/basic/UnitTests.java delete mode 100644 java/client/test/src/org/apache/qpid/client/AllClientUnitTests.java delete mode 100644 java/client/test/src/org/apache/qpid/client/TestAMQConnection.java delete mode 100644 java/client/test/src/org/apache/qpid/client/TestAMQSession.java delete mode 100644 java/client/test/src/org/apache/qpid/client/channelclose/ChannelCloseOkTest.java delete mode 100644 java/client/test/src/org/apache/qpid/client/channelclose/UnitTests.java delete mode 100644 java/client/test/src/org/apache/qpid/client/message/ObjectMessageTest.java delete mode 100644 java/client/test/src/org/apache/qpid/client/message/TestBytesMessage.java create mode 100644 java/client/test/src/org/apache/qpid/client/message/TestMessageHelper.java delete mode 100644 java/client/test/src/org/apache/qpid/client/message/TestTextMessage.java delete mode 100644 java/client/test/src/org/apache/qpid/client/message/UnitTests.java delete mode 100644 java/client/test/src/org/apache/qpid/client/protocol/TestAMQProtocolSession.java delete mode 100644 java/client/test/src/org/apache/qpid/client/protocol/TestIoSession.java delete mode 100644 java/client/test/src/org/apache/qpid/connection/ConnectionTest.java delete mode 100644 java/client/test/src/org/apache/qpid/connection/TestManyConnections.java delete mode 100644 java/client/test/src/org/apache/qpid/connectionurl/ConnectionURLTest.java delete mode 100644 java/client/test/src/org/apache/qpid/connectionurl/UnitTests.java delete mode 100644 java/client/test/src/org/apache/qpid/destinationurl/DestinationURLTest.java delete mode 100644 java/client/test/src/org/apache/qpid/destinationurl/UnitTests.java delete mode 100644 java/client/test/src/org/apache/qpid/failover/FailoverBrokerTester.java delete mode 100644 java/client/test/src/org/apache/qpid/failover/FailoverMultiMethodTest.java delete mode 100644 java/client/test/src/org/apache/qpid/failover/FailoverRoundRobinTest.java delete mode 100644 java/client/test/src/org/apache/qpid/failover/FailoverSingleServerTest.java delete mode 100644 java/client/test/src/org/apache/qpid/failover/FailoverTest.java delete mode 100644 java/client/test/src/org/apache/qpid/failover/FailoverTxTest.java delete mode 100644 java/client/test/src/org/apache/qpid/forwardall/Client.java delete mode 100644 java/client/test/src/org/apache/qpid/forwardall/Combined.java delete mode 100644 java/client/test/src/org/apache/qpid/forwardall/Service.java delete mode 100644 java/client/test/src/org/apache/qpid/forwardall/ServiceCreator.java delete mode 100644 java/client/test/src/org/apache/qpid/forwardall/SpecialQueue.java delete mode 100644 java/client/test/src/org/apache/qpid/forwardall/UnitTests.java delete mode 100644 java/client/test/src/org/apache/qpid/framing/FieldTableTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/ack/DisconnectAndRedeliverTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/ack/RecoverTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/ack/UnitTests.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/basic/BytesMessageTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/basic/ObjectMessageTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/basic/ReceiveTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/basic/SessionStartTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/basic/TextMessageTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/basic/UnitTests.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/AMQConnectionTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/AMQSessionTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/AllClientUnitTests.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/channelclose/UnitTests.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/connection/ConnectionTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/connection/TestManyConnections.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/connectionurl/UnitTests.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/destinationurl/UnitTests.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/forwardall/Client.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/forwardall/Service.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/forwardall/ServiceCreator.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/forwardall/SpecialQueue.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/forwardall/UnitTests.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/message/BytesMessageTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/message/MessageUnitTests.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/message/TextMessageTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/client/protocol/TestIoSession.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Lookup.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Unbind.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/transacted/TransactedTest.java create mode 100644 java/client/test/src/org/apache/qpid/test/unit/transacted/UnitTests.java delete mode 100644 java/client/test/src/org/apache/qpid/topic/DurableSubscriptionTest.java delete mode 100644 java/client/test/src/org/apache/qpid/transacted/TransactedTest.java delete mode 100644 java/client/test/src/org/apache/qpid/transacted/UnitTests.java (limited to 'java/client/test/src') diff --git a/java/client/test/src/org/apache/qpid/ack/DisconnectAndRedeliverTest.java b/java/client/test/src/org/apache/qpid/ack/DisconnectAndRedeliverTest.java deleted file mode 100644 index fca04c8330..0000000000 --- a/java/client/test/src/org/apache/qpid/ack/DisconnectAndRedeliverTest.java +++ /dev/null @@ -1,234 +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.ack; - -import junit.framework.JUnit4TestAdapter; -import org.apache.log4j.Logger; -import org.apache.log4j.xml.DOMConfigurator; -import org.apache.qpid.client.AMQConnection; -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.apache.qpid.server.registry.ApplicationRegistry; -import org.apache.qpid.server.store.TestableMemoryMessageStore; -import org.apache.qpid.server.util.TestApplicationRegistry; -import org.junit.After; -import org.junit.Assert; -import org.junit.Before; -import org.junit.Test; - -import javax.jms.*; - -public class DisconnectAndRedeliverTest -{ - private static final Logger _logger = Logger.getLogger(DisconnectAndRedeliverTest.class); - - - static - { - String workdir = System.getProperty("QPID_WORK"); - if (workdir == null || workdir.equals("")) - { - String tempdir = System.getProperty("java.io.tmpdir"); - System.out.println("QPID_WORK not set using tmp directory: " + tempdir); - System.setProperty("QPID_WORK", tempdir); - } - //DOMConfigurator.configure("../etc/log4j.xml"); - DOMConfigurator.configure("broker/etc/log4j.xml"); - } - - @Before - public void resetAppliactionRegistry() throws Exception - { - createVMBroker(); - ApplicationRegistry.initialise(new TestApplicationRegistry(), 1); - } - - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - /** - * This tests that when there are unacknowledged messages on a channel they are requeued for delivery when - * the channel is closed. - * - * @throws Exception - */ - @Test - public void disconnectRedeliversMessages() throws Exception - { - Connection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); - - TestableMemoryMessageStore store = (TestableMemoryMessageStore) ApplicationRegistry.getInstance().getMessageStore(); - - Session consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE); - AMQQueue queue = new AMQQueue("someQ", "someQ", false, false); - MessageConsumer consumer = consumerSession.createConsumer(queue); - //force synch to ensure the consumer has resulted in a bound queue - ((AMQSession) consumerSession).declareExchangeSynch("amq.direct", "direct"); - - Connection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "/test"); - - - Session producerSession = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE); - MessageProducer producer = producerSession.createProducer(queue); - - _logger.info("Sending four messages"); - producer.send(producerSession.createTextMessage("msg1")); - producer.send(producerSession.createTextMessage("msg2")); - producer.send(producerSession.createTextMessage("msg3")); - producer.send(producerSession.createTextMessage("msg4")); - - con2.close(); - - _logger.info("Starting connection"); - con.start(); - TextMessage tm = (TextMessage) consumer.receive(); - tm.acknowledge(); - _logger.info("Received and acknowledged first message"); - consumer.receive(); - consumer.receive(); - consumer.receive(); - _logger.info("Received all four messages. About to disconnect and reconnect"); - - con.close(); - con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); - consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE); - consumer = consumerSession.createConsumer(queue); - - _logger.info("Starting second consumer connection"); - con.start(); - - tm = (TextMessage) consumer.receive(3000); - Assert.assertEquals("msg2", tm.getText()); - - - tm = (TextMessage) consumer.receive(3000); - Assert.assertEquals("msg3", tm.getText()); - - - tm = (TextMessage) consumer.receive(3000); - Assert.assertEquals("msg4", tm.getText()); - - _logger.info("Received redelivery of three messages. Acknowledging last message"); - tm.acknowledge(); - - con.close(); - - con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); - consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE); - consumer = consumerSession.createConsumer(queue); - _logger.info("Starting third consumer connection"); - con.start(); - tm = (TextMessage) consumer.receiveNoWait(); - Assert.assertNull(tm); - _logger.info("No messages redelivered as is expected"); - con.close(); - - con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); - consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE); - consumer = consumerSession.createConsumer(queue); - _logger.info("Starting fourth consumer connection"); - con.start(); - tm = (TextMessage) consumer.receive(3000); - Assert.assertNull(tm); - _logger.info("No messages redelivered as is expected"); - con.close(); - - _logger.info("Actually:" + store.getMessageMap().size()); - // Assert.assertTrue(store.getMessageMap().size() == 0); - } - - /** - * Tests that unacknowledged messages are thrown away when the channel is closed and they cannot be - * requeued (due perhaps to the queue being deleted). - * - * @throws Exception - */ - @Test - public void disconnectWithTransientQueueThrowsAwayMessages() throws Exception - { - - Connection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); - TestableMemoryMessageStore store = (TestableMemoryMessageStore) ApplicationRegistry.getInstance().getMessageStore(); - Session consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE); - Queue queue = new AMQQueue("someQ", "someQ", false, true); - MessageConsumer consumer = consumerSession.createConsumer(queue); - //force synch to ensure the consumer has resulted in a bound queue - ((AMQSession) consumerSession).declareExchangeSynch("amq.direct", "direct"); - - Connection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "/test"); - Session producerSession = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE); - MessageProducer producer = producerSession.createProducer(queue); - - _logger.info("Sending four messages"); - producer.send(producerSession.createTextMessage("msg1")); - producer.send(producerSession.createTextMessage("msg2")); - producer.send(producerSession.createTextMessage("msg3")); - producer.send(producerSession.createTextMessage("msg4")); - - con2.close(); - - _logger.info("Starting connection"); - con.start(); - TextMessage tm = (TextMessage) consumer.receive(); - tm.acknowledge(); - _logger.info("Received and acknowledged first message"); - consumer.receive(); - consumer.receive(); - consumer.receive(); - _logger.info("Received all four messages. About to disconnect and reconnect"); - - con.close(); - con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); - consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE); - consumer = consumerSession.createConsumer(queue); - - _logger.info("Starting second consumer connection"); - con.start(); - - tm = (TextMessage) consumer.receiveNoWait(); - Assert.assertNull(tm); - _logger.info("No messages redelivered as is expected"); - - _logger.info("Actually:" + store.getMessageMap().size()); - Assert.assertTrue(store.getMessageMap().size() == 0); - con.close(); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(DisconnectAndRedeliverTest.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/ack/RecoverTest.java b/java/client/test/src/org/apache/qpid/ack/RecoverTest.java deleted file mode 100644 index 78be978e2e..0000000000 --- a/java/client/test/src/org/apache/qpid/ack/RecoverTest.java +++ /dev/null @@ -1,134 +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.ack; - -import junit.framework.JUnit4TestAdapter; -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQQueue; -import org.apache.qpid.client.AMQSession; -import org.apache.qpid.client.transport.TransportConnection; -import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; -import org.apache.log4j.Logger; -import org.apache.log4j.xml.DOMConfigurator; -import org.junit.Assert; -import org.junit.Test; -import org.junit.Before; -import org.junit.After; - -import javax.jms.*; - -public class RecoverTest -{ - private static final Logger _logger = Logger.getLogger(RecoverTest.class); - - static - { - String workdir = System.getProperty("QPID_WORK"); - if (workdir == null || workdir.equals("")) - { - String tempdir = System.getProperty("java.io.tmpdir"); - System.out.println("QPID_WORK not set using tmp directory: " + tempdir); - System.setProperty("QPID_WORK", tempdir); - } - //DOMConfigurator.configure("../etc/log4j.xml"); - DOMConfigurator.configure("broker/etc/log4j.xml"); - } - - @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 recoverResendsMsgs() throws Exception - { - Connection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); - - Session consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE); - Queue queue = new AMQQueue("someQ", "someQ", false, true); - MessageConsumer consumer = consumerSession.createConsumer(queue); - //force synch to ensure the consumer has resulted in a bound queue - ((AMQSession) consumerSession).declareExchangeSynch("amq.direct", "direct"); - - Connection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "/test"); - Session producerSession = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE); - MessageProducer producer = producerSession.createProducer(queue); - - _logger.info("Sending four messages"); - producer.send(producerSession.createTextMessage("msg1")); - producer.send(producerSession.createTextMessage("msg2")); - producer.send(producerSession.createTextMessage("msg3")); - producer.send(producerSession.createTextMessage("msg4")); - - con2.close(); - - _logger.info("Starting connection"); - con.start(); - TextMessage tm = (TextMessage) consumer.receive(); - tm.acknowledge(); - _logger.info("Received and acknowledged first message"); - consumer.receive(); - consumer.receive(); - consumer.receive(); - _logger.info("Received all four messages. Calling recover with three outstanding messages"); - // no ack for last three messages so when I call recover I expect to get three messages back - consumerSession.recover(); - tm = (TextMessage) consumer.receive(3000); - Assert.assertEquals("msg2", tm.getText()); - - tm = (TextMessage) consumer.receive(3000); - Assert.assertEquals("msg3", tm.getText()); - - tm = (TextMessage) consumer.receive(3000); - Assert.assertEquals("msg4", tm.getText()); - - _logger.info("Received redelivery of three messages. Acknowledging last message"); - tm.acknowledge(); - - _logger.info("Calling acknowledge with no outstanding messages"); - // all acked so no messages to be delivered - consumerSession.recover(); - - tm = (TextMessage) consumer.receiveNoWait(); - Assert.assertNull(tm); - _logger.info("No messages redelivered as is expected"); - - con.close(); - - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(RecoverTest.class); - } -} - diff --git a/java/client/test/src/org/apache/qpid/ack/UnitTests.java b/java/client/test/src/org/apache/qpid/ack/UnitTests.java deleted file mode 100644 index 5caaff69cf..0000000000 --- a/java/client/test/src/org/apache/qpid/ack/UnitTests.java +++ /dev/null @@ -1,32 +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.ack; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({DisconnectAndRedeliverTest.class, RecoverTest.class}) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/basic/BytesMessageTest.java b/java/client/test/src/org/apache/qpid/basic/BytesMessageTest.java deleted file mode 100644 index a832213066..0000000000 --- a/java/client/test/src/org/apache/qpid/basic/BytesMessageTest.java +++ /dev/null @@ -1,231 +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.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.apache.qpid.client.message.JMSBytesMessage; -import org.apache.mina.common.ByteBuffer; -import org.junit.Test; -import org.junit.Before; -import org.junit.Assert; -import org.junit.After; - -import javax.jms.*; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class BytesMessageTest implements MessageListener -{ - private Connection _connection; - private Destination _destination; - private Session _session; - private final List received = new ArrayList(); - private final List messages = new ArrayList(); - private int _count = 100; - public String _connectionString = "vm://:1"; - - @Before - public void init() throws Exception - { - init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); - createVMBroker(); - } - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - void init(AMQConnection connection) throws Exception - { - init(connection, new AMQQueue(randomize("BytesMessageTest"), true)); - } - - void init(AMQConnection connection, AMQDestination destination) throws Exception - { - _connection = connection; - _destination = destination; - _session = connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); - - // Set up a slow consumer. - _session.createConsumer(destination).setMessageListener(this); - connection.start(); - } - - @Test - public void test() throws Exception - { - - try - { - send(_count); - waitFor(_count); - check(); - System.out.println("Completed without failure"); - } - finally - { - _connection.close(); - } - } - - void send(int count) throws JMSException - { - //create a publisher - MessageProducer producer = _session.createProducer(_destination); - for (int i = 0; i < count; i++) - { - BytesMessage msg = _session.createBytesMessage(); - byte[] data = ("Message " + i).getBytes(); - msg.writeBytes(data); - messages.add(data); - producer.send(msg); - } - } - - void waitFor(int count) throws InterruptedException - { - synchronized(received) - { - while (received.size() < count) - { - received.wait(); - } - } - } - - void check() throws JMSException - { - List actual = new ArrayList(); - for (JMSBytesMessage m : received) - { - ByteBuffer buffer = m.getData(); - byte[] data = new byte[buffer.remaining()]; - buffer.get(data); - actual.add(data); - } - - assertEqual(messages.iterator(), actual.iterator()); - } - - private static void assertEqual(Iterator expected, Iterator actual) - { - List errors = new ArrayList(); - while (expected.hasNext() && actual.hasNext()) - { - try - { - assertEquivalent((byte[]) expected.next(), (byte[]) actual.next()); - } - catch (Exception e) - { - errors.add(e.getMessage()); - } - } - while (expected.hasNext()) - { - errors.add("Expected " + expected.next() + " but no more actual values."); - } - while (actual.hasNext()) - { - errors.add("Found " + actual.next() + " but no more expected values."); - } - if (!errors.isEmpty()) - { - throw new RuntimeException(errors.toString()); - } - } - - private static void assertEquivalent(byte[] expected, byte[] actual) - { - if (expected.length != actual.length) - { - throw new RuntimeException("Expected length " + expected.length + " got " + actual.length); - } - for (int i = 0; i < expected.length; i++) - { - if (expected[i] != actual[i]) - { - throw new RuntimeException("Failed on byte " + i + " of " + expected.length); - } - } - } - - public void onMessage(Message message) - { - synchronized(received) - { - received.add((JMSBytesMessage) message); - received.notify(); - } - } - - private static String randomize(String in) - { - return in + System.currentTimeMillis(); - } - - public static void main(String[] argv) throws Exception - { - final String connectionString; - final int count; - if (argv.length == 0) - { - connectionString = "vm://:1"; - count = 100; - } - else - { - connectionString = argv[0]; - count = Integer.parseInt(argv[1]); - } - - System.out.println("connectionString = " + connectionString); - System.out.println("count = " + count); - - BytesMessageTest test = new BytesMessageTest(); - test._connectionString = connectionString; - test._count = count; - test.test(); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(BytesMessageTest.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/basic/FieldTableKeyEnumeratorTest.java b/java/client/test/src/org/apache/qpid/basic/FieldTableKeyEnumeratorTest.java deleted file mode 100644 index 08ff65ea29..0000000000 --- a/java/client/test/src/org/apache/qpid/basic/FieldTableKeyEnumeratorTest.java +++ /dev/null @@ -1,83 +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.client.message; - -import org.junit.Test; -import org.junit.Assert; -import org.apache.qpid.framing.FieldTable; - - -import java.util.Enumeration; - -import junit.framework.JUnit4TestAdapter; - -import javax.jms.JMSException; - -public class FieldTableKeyEnumeratorTest -{ - @Test - public void testKeyEnumeration() - { - FieldTable result = new FieldTable(); - result.put("one", 1L); - result.put("two", 2L); - result.put("three", 3L); - result.put("four", 4L); - result.put("five", 5L); - - Enumeration e = result.keys(); - - Assert.assertTrue("one".equals(e.nextElement())); - Assert.assertTrue("two".equals(e.nextElement())); - Assert.assertTrue("three".equals(e.nextElement())); - Assert.assertTrue("four".equals(e.nextElement())); - Assert.assertTrue("five".equals(e.nextElement())); - } - - @Test - public void testPropertEnu() - { - try - { - JMSTextMessage text = new JMSTextMessage(); - - text.setBooleanProperty("Boolean1", true); - text.setBooleanProperty("Boolean2", true); - text.setIntProperty("Int", 2); - text.setLongProperty("Long", 2); - - Enumeration e = text.getPropertyNames(); - - Assert.assertTrue("Boolean1".equals(e.nextElement())); - Assert.assertTrue("Boolean2".equals(e.nextElement())); - Assert.assertTrue("Int".equals(e.nextElement())); - Assert.assertTrue("Long".equals(e.nextElement())); - } - catch (JMSException e) - { - - } - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(FieldTableKeyEnumeratorTest.class); - } - - -} diff --git a/java/client/test/src/org/apache/qpid/basic/FieldTableMessageTest.java b/java/client/test/src/org/apache/qpid/basic/FieldTableMessageTest.java deleted file mode 100644 index 545f7b1094..0000000000 --- a/java/client/test/src/org/apache/qpid/basic/FieldTableMessageTest.java +++ /dev/null @@ -1,180 +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.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.apache.qpid.client.message.JMSBytesMessage; -import org.apache.qpid.framing.AMQFrameDecodingException; -import org.apache.qpid.framing.FieldTable; -import org.apache.qpid.framing.FieldTableTest; -import org.apache.mina.common.ByteBuffer; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.junit.After; - -import javax.jms.*; -import java.io.IOException; -import java.util.ArrayList; -import java.util.Enumeration; - -public class FieldTableMessageTest implements MessageListener -{ - private AMQConnection _connection; - private AMQDestination _destination; - private AMQSession _session; - private final ArrayList received = new ArrayList(); - private FieldTable _expected; - private int _count = 10; - public String _connectionString = "vm://:1"; - - @Before - public void init() throws Exception - { - init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); - createVMBroker(); - } - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - - private void init(AMQConnection connection) throws Exception - { - init(connection, new AMQQueue(randomize("FieldTableMessageTest"), true)); - } - - private void init(AMQConnection connection, AMQDestination destination) throws Exception - { - _connection = connection; - _destination = destination; - _session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); - - //set up a slow consumer - _session.createConsumer(destination).setMessageListener(this); - connection.start(); - - //_expected = new FieldTableTest().load("FieldTableTest2.properties"); - _expected = load(); - } - - private FieldTable load() throws IOException - { - FieldTable result = new FieldTable(); - result.put("one", 1L); - result.put("two", 2L); - result.put("three", 3L); - result.put("four", 4L); - result.put("five", 5L); - - return result; - } - - @Test - public void test() throws Exception - { - int count = _count; - send(count); - waitFor(count); - check(); - System.out.println("Completed without failure"); - _connection.close(); - } - - void send(int count) throws JMSException, IOException - { - //create a publisher - MessageProducer producer = _session.createProducer(_destination); - for (int i = 0; i < count; i++) - { - BytesMessage msg = _session.createBytesMessage(); - msg.writeBytes(_expected.getDataAsBytes()); - producer.send(msg); - } - } - - void waitFor(int count) throws InterruptedException - { - synchronized(received) - { - while (received.size() < count) - { - received.wait(); - } - } - } - - void check() throws JMSException, AMQFrameDecodingException - { - for (Object m : received) - { - ByteBuffer buffer = ((JMSBytesMessage) m).getData(); - FieldTable actual = new FieldTable(buffer, buffer.remaining()); - new FieldTableTest().assertEquivalent(_expected, actual); - } - } - - public void onMessage(Message message) - { - synchronized(received) - { - received.add((JMSBytesMessage) message); - received.notify(); - } - } - - private static String randomize(String in) - { - return in + System.currentTimeMillis(); - } - - public static void main(String[] argv) throws Exception - { - FieldTableMessageTest test = new FieldTableMessageTest(); - test._connectionString = argv.length == 0 ? "vm://:1" : argv[0]; - test.init(); - test._count = argv.length > 1 ? Integer.parseInt(argv[1]) : 5; - test.test(); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(FieldTableMessageTest.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/basic/MultipleConnectionTest.java b/java/client/test/src/org/apache/qpid/basic/MultipleConnectionTest.java deleted file mode 100644 index 8bf6fc1991..0000000000 --- a/java/client/test/src/org/apache/qpid/basic/MultipleConnectionTest.java +++ /dev/null @@ -1,218 +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.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.junit.Test; - -import javax.jms.*; - -/** - * This is a slow test. - */ -public class MultipleConnectionTest -{ - public static String _connectionString="vm://:1"; - - private static class Receiver - { - private AMQConnection _connection; - private Session[] _sessions; - private MessageCounter[] _counters; - - Receiver(String broker, AMQDestination dest, int sessions) throws Exception - { - this(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test_path"), dest, sessions); - } - - Receiver(AMQConnection connection, AMQDestination dest, int sessions) throws Exception - { - _connection = connection; - _sessions = new AMQSession[sessions]; - _counters = new MessageCounter[sessions]; - for (int i = 0; i < sessions; i++) - { - _sessions[i] = _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); - _counters[i] = new MessageCounter(_sessions[i].toString()); - _sessions[i].createConsumer(dest).setMessageListener(_counters[i]); - } - _connection.start(); - } - - void close() throws JMSException - { - _connection.close(); - } - } - - private static class Publisher - { - private AMQConnection _connection; - private Session _session; - private MessageProducer _producer; - - Publisher(String broker, AMQDestination dest) throws Exception - { - this(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test_path"), dest); - } - - Publisher(AMQConnection connection, AMQDestination dest) throws Exception - { - _connection = connection; - _session = _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); - _producer = _session.createProducer(dest); - } - - void send(String msg) throws JMSException - { - _producer.send(_session.createTextMessage(msg)); - } - - void close() throws JMSException - { - _connection.close(); - } - } - - private static class MessageCounter implements MessageListener - { - private final String _name; - private int _count; - - MessageCounter(String name) - { - _name = name; - } - - public synchronized void onMessage(Message message) - { - _count++; - notifyAll(); - } - - synchronized boolean waitUntil(int expected, long maxWait) throws InterruptedException - { - long start = System.currentTimeMillis(); - long timeLeft = maxWait; - do - { - wait(timeLeft); - timeLeft = maxWait - timeSince(start); - } - while (expected > _count && timeLeft > 0); - return expected <= _count; - } - - private long timeSince(long start) - { - return System.currentTimeMillis() - start; - } - - public synchronized String toString() - { - return _name + ": " + _count; - } - } - - private static void waitForCompletion(int expected, long wait, Receiver[] receivers) throws InterruptedException - { - for(int i = 0; i < receivers.length; i++) - { - waitForCompletion(expected, wait, receivers[i]._counters); - } - } - - private static void waitForCompletion(int expected, long wait, MessageCounter[] counters) throws InterruptedException - { - for(int i = 0; i < counters.length; i++) - { - if(!counters[i].waitUntil(expected, wait)) - { - throw new RuntimeException("Expected: " + expected + " got " + counters[i]); - }; - } - } - - private static String randomize(String in) - { - return in + System.currentTimeMillis(); - } - - public static void main(String[] argv) throws Exception - { - String broker = argv.length > 0 ? argv[0] : "vm://:1"; - - int connections = 7; - int sessions = 2; - - MultipleConnectionTest test = new MultipleConnectionTest(); - test._connectionString = broker; - test.test(); - } - - @Test - public void test() throws Exception - { - String broker = _connectionString; - int messages = 10; - - AMQTopic topic = new AMQTopic("amq.topic"); - - /* - Receiver[] receivers = new Receiver[connections]; - for(int i = 0; i < receivers.length; i++) - { - receivers[i] = new Receiver(broker, topic, sessions); - } - */ - - Receiver[] receivers = new Receiver[]{ - new Receiver(broker, topic, 2), - new Receiver(broker, topic, 14) - }; - - Publisher publisher = new Publisher(broker, topic); - for(int i = 0; i < messages; i++) - { - publisher.send("Message " + (i + 1)); - } - - try - { - waitForCompletion(messages, 5000, receivers); - System.out.println("All receivers received all expected messages"); - } - finally - { - publisher.close(); - for(int i = 0; i < receivers.length; i++) - { - receivers[i].close(); - } - } - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(MultipleConnectionTest.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/basic/ObjectMessageTest.java b/java/client/test/src/org/apache/qpid/basic/ObjectMessageTest.java deleted file mode 100644 index ceb2fa907e..0000000000 --- a/java/client/test/src/org/apache/qpid/basic/ObjectMessageTest.java +++ /dev/null @@ -1,230 +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.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.apache.qpid.client.message.JMSObjectMessage; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.junit.After; - -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.MessageProducer; -import java.io.Serializable; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class ObjectMessageTest implements MessageListener -{ - private AMQConnection _connection; - private AMQDestination _destination; - private AMQSession _session; - private final List received = new ArrayList(); - private final List messages = new ArrayList(); - private int _count = 100; - public String _connectionString = "vm://:1"; - - @Before - public void init() throws Exception - { - String broker = _connectionString; - init(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test_path")); - createVMBroker(); - } - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - private void init(AMQConnection connection) throws Exception - { - init(connection, new AMQQueue(randomize("ObjectMessageTest"), true)); - } - - private void init(AMQConnection connection, AMQDestination destination) throws Exception - { - _connection = connection; - _destination = destination; - _session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); - - //set up a slow consumer - _session.createConsumer(destination).setMessageListener(this); - connection.start(); - } - - @Test - public void test() throws Exception - { - int count = _count; - send(count); - waitFor(count); - check(); - System.out.println("Completed without failure"); - _connection.close(); - } - - void send(int count) throws JMSException - { - //create a publisher - MessageProducer producer = _session.createProducer(_destination); - for (int i = 0; i < count; i++) - { - Payload payload = new Payload("Message " + i); - messages.add(payload); - producer.send(_session.createObjectMessage(payload)); - } - } - - void waitFor(int count) throws InterruptedException - { - synchronized(received) - { - while (received.size() < count) - { - received.wait(); - } - } - } - - void check() throws JMSException - { - List actual = new ArrayList(); - for (JMSObjectMessage m : received) - { - actual.add(m.getObject()); - } - - assertEqual(messages.iterator(), actual.iterator()); - } - - private static void assertEqual(Iterator expected, Iterator actual) - { - List errors = new ArrayList(); - while (expected.hasNext() && actual.hasNext()) - { - try - { - assertEqual(expected.next(), actual.next()); - } - catch (Exception e) - { - errors.add(e.getMessage()); - } - } - while (expected.hasNext()) - { - errors.add("Expected " + expected.next() + " but no more actual values."); - } - while (actual.hasNext()) - { - errors.add("Found " + actual.next() + " but no more expected values."); - } - if (!errors.isEmpty()) - { - throw new RuntimeException(errors.toString()); - } - } - - private static void assertEqual(Object expected, Object actual) - { - if (!expected.equals(actual)) - { - throw new RuntimeException("Expected '" + expected + "' found '" + actual + "'"); - } - } - - public void onMessage(Message message) - { - synchronized(received) - { - received.add((JMSObjectMessage) message); - received.notify(); - } - } - - private static String randomize(String in) - { - return in + System.currentTimeMillis(); - } - - private static class Payload implements Serializable - { - private final String data; - - Payload(String data) - { - this.data = data; - } - - public int hashCode() - { - return data.hashCode(); - } - - public boolean equals(Object o) - { - return o instanceof Payload && ((Payload) o).data.equals(data); - } - - public String toString() - { - return "Payload[" + data + "]"; - } - } - - public static void main(String[] argv) throws Exception - { - ObjectMessageTest test = new ObjectMessageTest(); - test._connectionString = argv.length == 0 ? "vm://:1" : argv[0]; - test.init(); - if (argv.length > 1) - { - test._count = Integer.parseInt(argv[1]); - } - test.test(); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(ObjectMessageTest.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/basic/ReceiveTest.java b/java/client/test/src/org/apache/qpid/basic/ReceiveTest.java deleted file mode 100644 index d72d748935..0000000000 --- a/java/client/test/src/org/apache/qpid/basic/ReceiveTest.java +++ /dev/null @@ -1,80 +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.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.junit.Before; -import org.junit.Test; - -import javax.jms.MessageConsumer; - -public class ReceiveTest -{ - private AMQConnection _connection; - private AMQDestination _destination; - private AMQSession _session; - private MessageConsumer _consumer; - - public String _connectionString = "vm://:1"; - - @Before - public void init() throws Exception - { - String broker = _connectionString; - init(new AMQConnection(broker, "guest", "guest", "ReceiveTestClient", "/test_path")); - } - - private void init(AMQConnection connection) throws Exception - { - init(connection, new AMQQueue("ReceiveTest", true)); - } - - private void init(AMQConnection connection, AMQDestination destination) throws Exception - { - _connection = connection; - _destination = destination; - _session = (AMQSession) connection.createSession(true, AMQSession.NO_ACKNOWLEDGE); - _consumer = _session.createConsumer(_destination); - _connection.start(); - } - - @Test - public void test() throws Exception - { - _consumer.receive(5000); - _connection.close(); - } - - public static void main(String[] argv) throws Exception - { - ReceiveTest test = new ReceiveTest(); - test._connectionString = argv.length == 0 ? "vm://:1" : argv[0]; - test.init(); - test.test(); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(ReceiveTest.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/basic/SessionStartTest.java b/java/client/test/src/org/apache/qpid/basic/SessionStartTest.java deleted file mode 100644 index edd7beae14..0000000000 --- a/java/client/test/src/org/apache/qpid/basic/SessionStartTest.java +++ /dev/null @@ -1,132 +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.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.transport.TransportConnection; -import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; - -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.junit.After; - -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageListener; - -public class SessionStartTest implements MessageListener -{ - private AMQConnection _connection; - private AMQDestination _destination; - private AMQSession _session; - private int count; - public String _connectionString = "vm://:1"; - - @Before - public void init() throws Exception - { - init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); - createVMBroker(); - } - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - private void init(AMQConnection connection) throws Exception - { - init(connection, new AMQQueue(randomize("SessionStartTest"), true)); - } - - private void init(AMQConnection connection, AMQDestination destination) throws Exception - { - _connection = connection; - _destination = destination; - connection.start(); - - _session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); - _session.createConsumer(destination).setMessageListener(this); - } - - @Test - public synchronized void test() throws JMSException, InterruptedException - { - try - { - _session.createProducer(_destination).send(_session.createTextMessage("Message")); - System.out.println("Message sent, waiting for response..."); - wait(1000); - if (count > 0) - { - System.out.println("Got message"); - } - else - { - throw new RuntimeException("Did not get message!"); - } - } - finally - { - _session.close(); - _connection.close(); - } - } - - public synchronized void onMessage(Message message) - { - count++; - notify(); - } - - private static String randomize(String in) - { - return in + System.currentTimeMillis(); - } - - public static void main(String[] argv) throws Exception - { - SessionStartTest test = new SessionStartTest(); - test._connectionString = argv.length == 0 ? "localhost:5672" : argv[0]; - test.init(); - test.test(); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(SessionStartTest.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/basic/TextMessageTest.java b/java/client/test/src/org/apache/qpid/basic/TextMessageTest.java deleted file mode 100644 index 5bf5da2fb7..0000000000 --- a/java/client/test/src/org/apache/qpid/basic/TextMessageTest.java +++ /dev/null @@ -1,201 +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.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.apache.qpid.client.message.JMSTextMessage; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.junit.After; - -import javax.jms.*; -import java.util.ArrayList; -import java.util.Iterator; -import java.util.List; - -public class TextMessageTest implements MessageListener -{ - private AMQConnection _connection; - private Destination _destination; - private AMQSession _session; - private final List received = new ArrayList(); - private final List messages = new ArrayList(); - private int _count = 100; - public String _connectionString = "vm://:1"; - - @Before - public void init() throws Exception - { - init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); - createVMBroker(); - } - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - private void init(AMQConnection connection) throws Exception - { - Destination destination = new AMQQueue(randomize("TextMessageTest"), true); - init(connection, destination); - } - - private void init(AMQConnection connection, Destination destination) throws Exception - { - _connection = connection; - _destination = destination; - _session = (AMQSession) connection.createSession(false, AMQSession.AUTO_ACKNOWLEDGE); - - //set up a slow consumer - _session.createConsumer(destination).setMessageListener(this); - connection.start(); - } - - @Test - public void test() throws Exception - { - int count = _count; - send(count); - waitFor(count); - check(); - System.out.println("Completed without failure"); - _connection.close(); - } - - void send(int count) throws JMSException - { - //create a publisher - MessageProducer producer = _session.createProducer(_destination); - for (int i = 0; i < count; i++) - { - String text = "Message " + i; - messages.add(text); - producer.send(_session.createTextMessage(text)); - } - } - - void waitFor(int count) throws InterruptedException - { - synchronized(received) - { - while (received.size() < count) - { - received.wait(); - } - } - } - - void check() throws JMSException - { - List actual = new ArrayList(); - for (JMSTextMessage m : received) - { - actual.add(m.getText()); - } - - assertEqual(messages.iterator(), actual.iterator()); - } - - private static void assertEqual(Iterator expected, Iterator actual) - { - List errors = new ArrayList(); - while (expected.hasNext() && actual.hasNext()) - { - try - { - assertEqual(expected.next(), actual.next()); - } - catch (Exception e) - { - errors.add(e.getMessage()); - } - } - while (expected.hasNext()) - { - errors.add("Expected " + expected.next() + " but no more actual values."); - } - while (actual.hasNext()) - { - errors.add("Found " + actual.next() + " but no more expected values."); - } - if (!errors.isEmpty()) - { - throw new RuntimeException(errors.toString()); - } - } - - private static void assertEqual(Object expected, Object actual) - { - if (!expected.equals(actual)) - { - throw new RuntimeException("Expected '" + expected + "' found '" + actual + "'"); - } - } - - public void onMessage(Message message) - { - synchronized(received) - { - received.add((JMSTextMessage) message); - received.notify(); - } - } - - private static String randomize(String in) - { - return in + System.currentTimeMillis(); - } - - public static void main(String[] argv) throws Exception - { - TextMessageTest test = new TextMessageTest(); - test._connectionString = argv.length == 0 ? "vm://:1" : argv[0]; - test.init(); - if (argv.length > 1) - { - test._count = Integer.parseInt(argv[1]); - } - test.test(); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(TextMessageTest.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/basic/UnitTests.java b/java/client/test/src/org/apache/qpid/basic/UnitTests.java deleted file mode 100644 index b87254f73a..0000000000 --- a/java/client/test/src/org/apache/qpid/basic/UnitTests.java +++ /dev/null @@ -1,41 +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.basic; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.apache.qpid.client.message.FieldTableKeyEnumeratorTest; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - BytesMessageTest.class, - FieldTableMessageTest.class, - FieldTableKeyEnumeratorTest.class, - MultipleConnectionTest.class, - ObjectMessageTest.class, - SessionStartTest.class, - TextMessageTest.class - }) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/client/AllClientUnitTests.java b/java/client/test/src/org/apache/qpid/client/AllClientUnitTests.java deleted file mode 100644 index 1b2b2ed0aa..0000000000 --- a/java/client/test/src/org/apache/qpid/client/AllClientUnitTests.java +++ /dev/null @@ -1,47 +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.client; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -/** - * All client unit tests - even one in packages like org.apache.qpid.ack. - */ -@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 - }) -public class AllClientUnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(AllClientUnitTests.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/client/TestAMQConnection.java b/java/client/test/src/org/apache/qpid/client/TestAMQConnection.java deleted file mode 100644 index 1858abf536..0000000000 --- a/java/client/test/src/org/apache/qpid/client/TestAMQConnection.java +++ /dev/null @@ -1,138 +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.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); - } -} diff --git a/java/client/test/src/org/apache/qpid/client/TestAMQSession.java b/java/client/test/src/org/apache/qpid/client/TestAMQSession.java deleted file mode 100644 index 99da8c5b10..0000000000 --- a/java/client/test/src/org/apache/qpid/client/TestAMQSession.java +++ /dev/null @@ -1,135 +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.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); - } - - -} diff --git a/java/client/test/src/org/apache/qpid/client/channelclose/ChannelCloseOkTest.java b/java/client/test/src/org/apache/qpid/client/channelclose/ChannelCloseOkTest.java deleted file mode 100644 index 7b714a01b7..0000000000 --- a/java/client/test/src/org/apache/qpid/client/channelclose/ChannelCloseOkTest.java +++ /dev/null @@ -1,235 +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.client.channelclose; - -import junit.framework.JUnit4TestAdapter; -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQQueue; -import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; -import org.apache.qpid.client.transport.TransportConnection; -import org.apache.log4j.Logger; -import org.junit.After; -import static org.junit.Assert.assertEquals; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; - -import javax.jms.*; -import java.util.ArrayList; -import java.util.List; - -/** - * Due to bizarre exception handling all sessions are closed if you get - * a channel close request and no exception listener is registered. - *

- * JIRA issue IBTBLZ-10. - *

- * Simulate by: - *

- * 0. Create two sessions with no exception listener. - * 1. Publish message to queue/topic that does not exist (wrong routing key). - * 2. This will cause a channel close. - * 3. Since client does not have an exception listener, currently all sessions are - * closed. - */ -public class ChannelCloseOkTest -{ - private Connection _connection; - private Destination _destination1; - private Destination _destination2; - private Session _session1; - private Session _session2; - private final List _received1 = new ArrayList(); - private final List _received2 = new ArrayList(); - - private final static Logger _log = Logger.getLogger(ChannelCloseOkTest.class); - public String _connectionString = "vm://:1"; - - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - @Before - public void init() throws Exception - { - createVMBroker(); - - _connection = new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path"); - - _destination1 = new AMQQueue("q1", true); - _destination2 = new AMQQueue("q2", true); - _session1 = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - _session1.createConsumer(_destination1).setMessageListener(new MessageListener() - { - public void onMessage(Message message) - { - _log.debug("consumer 1 got message [" + getTextMessage(message) + "]"); - synchronized(_received1) - { - _received1.add(message); - _received1.notify(); - } - } - }); - _session2 = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); - _session2.createConsumer(_destination2).setMessageListener(new MessageListener() - { - public void onMessage(Message message) - { - _log.debug("consumer 2 got message [" + getTextMessage(message) + "]"); - synchronized(_received2) - { - _received2.add(message); - _received2.notify(); - } - } - }); - - _connection.start(); - } - - private String getTextMessage(Message message) - { - TextMessage tm = (TextMessage) message; - try - { - return tm.getText(); - } - catch (JMSException e) - { - return "oops " + e; - } - } - - @After - public void closeConnection() throws JMSException - { - if (_connection != null) - { - System.out.println(">>>>>>>>>>>>>>.. closing"); - _connection.close(); - } - - stopVmBroker(); - } - - @Test - public void testWithoutExceptionListener() throws Exception - { - test(); - } - - @Test - public void testWithExceptionListener() throws Exception - { - _connection.setExceptionListener(new ExceptionListener() - { - public void onException(JMSException jmsException) - { - _log.error("onException - ", jmsException); - } - }); - - test(); - } - - public void test() throws Exception - { - // Check both sessions are ok. - sendAndWait(_session1, _destination1, "first", _received1, 1); - sendAndWait(_session2, _destination2, "second", _received2, 1); - assertEquals(1, _received1.size()); - assertEquals(1, _received2.size()); - - // Now send message to incorrect destination on session 1. - Destination destination = new AMQQueue("incorrect"); - send(_session1, destination, "third"); // no point waiting as message will never be received. - - // Ensure both sessions are still ok. - // Send a bunch of messages as this give time for the sessions to be erroneously closed. - final int num = 300; - for (int i = 0; i < num; ++i) - { - send(_session1, _destination1, "" + i); - send(_session2, _destination2, "" + i); - } - waitFor(_received1, num + 1); - waitFor(_received2, num + 1); - - // Note that the third message is never received as it is sent to an incorrect destination. - assertEquals(num + 1, _received1.size()); - assertEquals(num + 1, _received2.size()); - } - - private void sendAndWait(Session session, Destination destination, String message, List received, int count) - throws JMSException, InterruptedException - { - send(session, destination, message); - waitFor(received, count); - } - - private void send(Session session, Destination destination, String message) throws JMSException - { - _log.debug("sending message " + message); - MessageProducer producer1 = session.createProducer(destination); - producer1.send(session.createTextMessage(message)); - } - - private void waitFor(List received, int count) throws InterruptedException - { - synchronized(received) - { - while (received.size() < count) - { - received.wait(); - } - } - } - - private static String randomize(String in) - { - return in + System.currentTimeMillis(); - } - - /** - * For Junit 3 compatibility. - */ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(ChannelCloseOkTest.class); - } - - public static void main(String[] args) - { - org.junit.runner.JUnitCore.main(ChannelCloseOkTest.class.getName()); - } -} diff --git a/java/client/test/src/org/apache/qpid/client/channelclose/UnitTests.java b/java/client/test/src/org/apache/qpid/client/channelclose/UnitTests.java deleted file mode 100644 index ed98bc0c30..0000000000 --- a/java/client/test/src/org/apache/qpid/client/channelclose/UnitTests.java +++ /dev/null @@ -1,34 +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.client.channelclose; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - ChannelCloseOkTest.class - }) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/client/message/ObjectMessageTest.java b/java/client/test/src/org/apache/qpid/client/message/ObjectMessageTest.java deleted file mode 100644 index a5e1a0d558..0000000000 --- a/java/client/test/src/org/apache/qpid/client/message/ObjectMessageTest.java +++ /dev/null @@ -1,252 +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.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.junit.Before; -import org.junit.Test; - -import javax.jms.MessageListener; -import javax.jms.MessageProducer; -import javax.jms.Message; -import javax.jms.JMSException; -import javax.jms.ObjectMessage; -import java.io.Serializable; -import java.util.HashMap; -import java.util.ArrayList; - -import junit.framework.JUnit4TestAdapter; - -public class ObjectMessageTest implements MessageListener -{ - private final AMQConnection connection; - private final AMQDestination destination; - private final AMQSession session; - private final Serializable[] data; - private volatile boolean waiting; - private int received; - private final ArrayList items = new ArrayList(); - - ObjectMessageTest(String broker) throws Exception - { - this(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test_path")); - } - - ObjectMessageTest(AMQConnection connection) throws Exception - { - this(connection, new AMQQueue(randomize("LatencyTest"), true)); - } - - ObjectMessageTest(AMQConnection connection, AMQDestination destination) throws Exception - { - this.connection = connection; - this.destination = destination; - session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); - A a1 = new A(1, "A"); - A a2 = new A(2, "a"); - B b = new B(1, "B"); - C c = new C(); - c.put("A1", a1); - c.put("a2", a2); - c.put("B", b); - c.put("String", "String"); - - data = new Serializable[]{a1, a2, b, c, "Hello World!", new Integer(1001)}; - } - - public void test() throws Exception - { - try - { - send(); - waitUntilReceived(data.length); - check(); - System.out.println("All " + data.length + " items matched."); - } - finally - { - close(); - } - } - - private void send() throws Exception - { - //set up a consumer - session.createConsumer(destination).setMessageListener(this); - connection.start(); - - //create a publisher - MessageProducer producer = session.createProducer(destination, false, false, true); - - - for(int i = 0; i < data.length; i++) - { - ObjectMessage msg; - if(i % 2 == 0) - { - msg = session.createObjectMessage(data[i]); - } - else - { - msg = session.createObjectMessage(); - msg.setObject(data[i]); - } - producer.send(msg); - } - } - - public void check() throws Exception - { - Object[] actual = (Object[]) items.toArray(); - if(actual.length != data.length) - { - throw new Exception("Expected " + data.length + " objects, got " + actual.length); - } - for(int i = 0; i < data.length; i++) - { - if(actual[i] instanceof Exception) - { - throw new Exception("Error on receive of " + data[i], ((Exception) actual[i])); - } - if(actual[i] == null) - { - throw new Exception("Expected " + data[i] + " got null"); - } - if(!data[i].equals(actual[i])) - { - throw new Exception("Expected " + data[i] + " got " + actual[i]); - } - } - } - - - private void close() throws Exception - { - session.close(); - connection.close(); - } - - private synchronized void waitUntilReceived(int count) throws InterruptedException - { - waiting = true; - while(received < count) - { - wait(); - } - waiting = false; - } - - public void onMessage(Message message) - { - received++; - try - { - if(message instanceof ObjectMessage) - { - items.add(((ObjectMessage) message).getObject()); - } - else - { - System.out.println("ERROR: Got " + message.getClass().getName() + " not ObjectMessage"); - items.add(message); - } - } - catch (JMSException e) - { - e.printStackTrace(); - items.add(e); - } - - if(waiting){ - synchronized(this) - { - notify(); - } - } - } - - public static void main(String[] argv) throws Exception - { - String broker = argv.length > 0 ? argv[0] : "vm://:1"; - if("-help".equals(broker)) - { - System.out.println("Usage: "); - } - new ObjectMessageTest(broker).test(); - } - private static class A implements Serializable - { - private String sValue; - private int iValue; - - A(int i, String s) - { - sValue = s; - iValue = i; - } - - public int hashCode() - { - return iValue; - } - - public boolean equals(Object o) - { - return o instanceof A && equals((A) o); - } - - protected boolean equals(A a) - { - return areEqual(a.sValue, sValue) && a.iValue == iValue; - } - } - - private static class B extends A - { - private long time; - - B(int i, String s) - { - super(i, s); - time = System.currentTimeMillis(); - } - - protected boolean equals(A a) - { - return super.equals(a) && a instanceof B && time == ((B) a).time; - } - } - - private static class C extends HashMap implements Serializable - { - } - - private static boolean areEqual(Object a, Object b) - { - return a == null ? b == null : a.equals(b); - } - - private static String randomize(String in) - { - return in + System.currentTimeMillis(); - } - -} diff --git a/java/client/test/src/org/apache/qpid/client/message/TestBytesMessage.java b/java/client/test/src/org/apache/qpid/client/message/TestBytesMessage.java deleted file mode 100644 index 03bb65081f..0000000000 --- a/java/client/test/src/org/apache/qpid/client/message/TestBytesMessage.java +++ /dev/null @@ -1,296 +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.client.message; - -import junit.framework.JUnit4TestAdapter; -import org.junit.Test; -import org.junit.Assert; - -import javax.jms.MessageNotReadableException; -import javax.jms.MessageNotWriteableException; -import javax.jms.MessageEOFException; - -public class TestBytesMessage -{ - /** - * Tests that on creation a call to getBodyLength() throws an exception - * if null was passed in during creation - */ - @Test(expected=MessageNotReadableException.class) - public void testNotReadableOnCreationWithNull() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.getBodyLength(); - } - - @Test(expected= MessageNotWriteableException.class) - public void testResetMakesReadble() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeInt(10); - bm.reset(); - bm.writeInt(12); - } - - @Test - public void testClearBodyMakesWritable() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeInt(10); - bm.reset(); - bm.clearBody(); - bm.writeInt(10); - } - - @Test - public void testWriteInt() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeInt(10); - bm.reset(); - long len = bm.getBodyLength(); - Assert.assertTrue(len == 4); - int val = bm.readInt(); - Assert.assertTrue(val == 10); - } - - @Test - public void testWriteString() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeUTF("Bananas"); - bm.reset(); - String res = bm.readUTF(); - Assert.assertEquals("Bananas", res); - } - - @Test(expected=NullPointerException.class) - public void testWriteObjectThrowsNPE() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeObject(null); - } - - @Test - public void testReadBoolean() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeBoolean(true); - bm.reset(); - boolean result = bm.readBoolean(); - Assert.assertTrue(result); - } - - @Test(expected=MessageEOFException.class) - public void testEOFByte() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeByte((byte)1); - bm.reset(); - bm.readByte(); - // should throw - bm.readByte(); - } - - @Test(expected=MessageEOFException.class) - public void testEOFUnsignedByte() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeByte((byte)1); - bm.reset(); - bm.readByte(); - // should throw - bm.readUnsignedByte(); - } - - @Test(expected=MessageEOFException.class) - public void testEOFBoolean() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeBoolean(true); - bm.reset(); - bm.readBoolean(); - // should throw - bm.readBoolean(); - } - - @Test(expected=MessageEOFException.class) - public void testEOFChar() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeChar('A'); - bm.reset(); - bm.readChar(); - // should throw - bm.readChar(); - } - - @Test(expected=MessageEOFException.class) - public void testEOFDouble() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeDouble(1.3d); - bm.reset(); - bm.readDouble(); - // should throw - bm.readDouble(); - } - - @Test(expected=MessageEOFException.class) - public void testEOFFloat() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeFloat(1.3f); - bm.reset(); - bm.readFloat(); - // should throw - bm.readFloat(); - } - - @Test(expected=MessageEOFException.class) - public void testEOFInt() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeInt(99); - bm.reset(); - bm.readInt(); - // should throw - bm.readInt(); - } - - @Test(expected=MessageEOFException.class) - public void testEOFLong() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeLong(4L); - bm.reset(); - bm.readLong(); - // should throw - bm.readLong(); - } - - @Test(expected=MessageEOFException.class) - public void testEOFShort() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeShort((short)4); - bm.reset(); - bm.readShort(); - // should throw - bm.readShort(); - } - - @Test(expected=MessageEOFException.class) - public void testEOFUnsignedShort() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeShort((short)4); - bm.reset(); - bm.readUnsignedShort(); - // should throw - bm.readUnsignedShort(); - } - - /** - * Tests that the readBytes() method populates the passed in array - * correctly - * @throws Exception - */ - @Test - public void testReadBytes() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeByte((byte)3); - bm.writeByte((byte)4); - bm.reset(); - byte[] result = new byte[2]; - int count = bm.readBytes(result); - Assert.assertEquals((byte)3, result[0]); - Assert.assertEquals((byte)4, result[1]); - Assert.assertEquals(2, count); - } - - @Test - public void testReadBytesEOF() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeByte((byte)3); - bm.writeByte((byte)4); - bm.reset(); - byte[] result = new byte[2]; - bm.readBytes(result); - int count = bm.readBytes(result); - Assert.assertEquals(-1, count); - } - - @Test - public void testReadBytesWithLargerArray() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeByte((byte)3); - bm.writeByte((byte)4); - bm.reset(); - byte[] result = new byte[3]; - int count = bm.readBytes(result); - Assert.assertEquals(2, count); - Assert.assertEquals((byte)3, result[0]); - Assert.assertEquals((byte)4, result[1]); - Assert.assertEquals((byte)0, result[2]); - } - - @Test - public void testReadBytesWithCount() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.writeByte((byte)3); - bm.writeByte((byte)4); - bm.writeByte((byte)5); - bm.reset(); - byte[] result = new byte[3]; - int count = bm.readBytes(result, 2); - Assert.assertEquals(2, count); - Assert.assertEquals((byte)3, result[0]); - Assert.assertEquals((byte)4, result[1]); - Assert.assertEquals((byte)0, result[2]); - } - - @Test - public void testToBodyString() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - final String testText = "This is a test"; - bm.writeUTF(testText); - bm.reset(); - String result = bm.toBodyString(); - Assert.assertEquals(testText, result); - } - - @Test - public void testToBodyStringWithNull() throws Exception - { - JMSBytesMessage bm = new JMSBytesMessage(); - bm.reset(); - String result = bm.toBodyString(); - Assert.assertNull(result); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(TestBytesMessage.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/client/message/TestMessageHelper.java b/java/client/test/src/org/apache/qpid/client/message/TestMessageHelper.java new file mode 100644 index 0000000000..669bfd7a5f --- /dev/null +++ b/java/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/java/client/test/src/org/apache/qpid/client/message/TestTextMessage.java b/java/client/test/src/org/apache/qpid/client/message/TestTextMessage.java deleted file mode 100644 index 766f47d841..0000000000 --- a/java/client/test/src/org/apache/qpid/client/message/TestTextMessage.java +++ /dev/null @@ -1,51 +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.client.message; - -import junit.framework.JUnit4TestAdapter; -import org.junit.Test; -import org.junit.Assert; - -public class TestTextMessage -{ - @Test - public void testTextOnConstruction() throws Exception - { - JMSTextMessage tm = new JMSTextMessage(); - tm.setText("pies"); - String val = tm.getText(); - Assert.assertEquals(val, "pies"); - } - - @Test - public void testClearBody() throws Exception - { - JMSTextMessage tm = new JMSTextMessage(); - tm.setText("pies"); - tm.clearBody(); - String val = tm.getText(); - Assert.assertNull(val); - tm.setText("Banana"); - val = tm.getText(); - Assert.assertEquals(val, "Banana"); - } - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(TestTextMessage.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/client/message/UnitTests.java b/java/client/test/src/org/apache/qpid/client/message/UnitTests.java deleted file mode 100644 index 889c437df3..0000000000 --- a/java/client/test/src/org/apache/qpid/client/message/UnitTests.java +++ /dev/null @@ -1,32 +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.client.message; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({TestBytesMessage.class, TestTextMessage.class}) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/client/protocol/TestAMQProtocolSession.java b/java/client/test/src/org/apache/qpid/client/protocol/TestAMQProtocolSession.java deleted file mode 100644 index 15da927a0e..0000000000 --- a/java/client/test/src/org/apache/qpid/client/protocol/TestAMQProtocolSession.java +++ /dev/null @@ -1,114 +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.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; - } -} diff --git a/java/client/test/src/org/apache/qpid/client/protocol/TestIoSession.java b/java/client/test/src/org/apache/qpid/client/protocol/TestIoSession.java deleted file mode 100644 index fd9565ba5f..0000000000 --- a/java/client/test/src/org/apache/qpid/client/protocol/TestIoSession.java +++ /dev/null @@ -1,96 +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.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/java/client/test/src/org/apache/qpid/connection/ConnectionTest.java b/java/client/test/src/org/apache/qpid/connection/ConnectionTest.java deleted file mode 100644 index e86d238dc4..0000000000 --- a/java/client/test/src/org/apache/qpid/connection/ConnectionTest.java +++ /dev/null @@ -1,101 +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.connection; - -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQAuthenticationException; -import org.apache.qpid.AMQException; -import org.apache.qpid.AMQConnectionException; -import org.apache.qpid.AMQUnresolvedAddressException; -import org.junit.Test; -import org.junit.Assert; - -import javax.jms.Connection; - -import junit.framework.JUnit4TestAdapter; - -public class ConnectionTest -{ - @Test - public void simpleConnection() throws Exception - { - Connection connection = new AMQConnection("localhost:5672", "guest", "guest", - "fred", "/test"); - System.out.println("connection = " + connection); - } - - @Test - public void passwordFailureConnection() throws Exception - { - try - { - new AMQConnection("amqp://guest:rubbishpassword@clientid/testpath?brokerlist='tcp://localhost:5672?retries='1''"); - Assert.fail("Connection should not be established"); - } - catch (AMQException amqe) - { - if (!(amqe instanceof AMQAuthenticationException)) - { - Assert.fail("Correct exception not thrown"); - } - } - } - - @Test - public void connectionFailure() throws Exception - { - try - { - new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='tcp://localhost:5673?retries='0''"); - Assert.fail("Connection should not be established"); - } - catch (AMQException amqe) - { - if (!(amqe instanceof AMQConnectionException)) - { - Assert.fail("Correct exception not thrown"); - } - } - } - - @Test - public void unresolvedHostFailure() throws Exception - { - try - { - new AMQConnection("amqp://guest:guest@clientid/testpath?brokerlist='tcp://rubbishhost:5672?retries='0''"); - Assert.fail("Connection should not be established"); - } - catch (AMQException amqe) - { - if (!(amqe instanceof AMQUnresolvedAddressException)) - { - Assert.fail("Correct exception not thrown"); - } - } - } - - /** - * For Junit 3 compatibility. - */ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(ConnectionTest.class); - } - -} diff --git a/java/client/test/src/org/apache/qpid/connection/TestManyConnections.java b/java/client/test/src/org/apache/qpid/connection/TestManyConnections.java deleted file mode 100644 index 4456037c2e..0000000000 --- a/java/client/test/src/org/apache/qpid/connection/TestManyConnections.java +++ /dev/null @@ -1,99 +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.connection; - -import junit.framework.JUnit4TestAdapter; -import org.apache.qpid.AMQException; -import org.apache.qpid.url.URLSyntaxException; -import org.apache.qpid.client.AMQConnection; -import org.apache.log4j.Logger; -import org.junit.Test; - -public class TestManyConnections -{ - private static final Logger _log = Logger.getLogger(TestManyConnections.class); - - private AMQConnection[] _connections; - - private void createConnection(int index, String brokerHosts, String clientID, String username, String password, - String vpath) throws AMQException, URLSyntaxException - { - _connections[index] = new AMQConnection(brokerHosts, username, password, - clientID, vpath); - } - - private void createConnections(int count) throws AMQException, URLSyntaxException - { - _connections = new AMQConnection[count]; - long startTime = System.currentTimeMillis(); - for (int i = 0; i < count; i++) - { - createConnection(i, "vm://:1", "myClient" + i, "guest", "guest", "/test"); - } - long endTime = System.currentTimeMillis(); - _log.info("Time to create " + count + " connections: " + (endTime - startTime) + - "ms"); - } - - @Test - public void create10Connections() throws AMQException, URLSyntaxException - { - createConnections(10); - } - - @Test - public void create50Connections() throws AMQException, URLSyntaxException - { - createConnections(50); - } - - @Test - public void create100Connections() throws AMQException, URLSyntaxException - { - createConnections(100); - } - - @Test - public void create250Connections() throws AMQException, URLSyntaxException - { - createConnections(250); - } - - @Test - public void create500Connections() throws AMQException, URLSyntaxException - { - createConnections(500); - } - - @Test - public void create1000Connections() throws AMQException, URLSyntaxException - { - createConnections(1000); - } - - @Test - public void create5000Connections() throws AMQException, URLSyntaxException - { - createConnections(5000); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(TestManyConnections.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/connectionurl/ConnectionURLTest.java b/java/client/test/src/org/apache/qpid/connectionurl/ConnectionURLTest.java deleted file mode 100644 index cc8442af90..0000000000 --- a/java/client/test/src/org/apache/qpid/connectionurl/ConnectionURLTest.java +++ /dev/null @@ -1,449 +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.connectionurl; - -import org.junit.Test; -import org.junit.Assert; -import org.apache.qpid.client.AMQConnectionURL; -import org.apache.qpid.client.AMQBrokerDetails; -import org.apache.qpid.jms.ConnectionURL; -import org.apache.qpid.jms.BrokerDetails; -import org.apache.qpid.url.URLSyntaxException; -import junit.framework.JUnit4TestAdapter; - -public class ConnectionURLTest -{ - @Test - public void failoverURL() throws URLSyntaxException - { - String url = "amqp://ritchiem:bob@/temp?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - Assert.assertTrue(connectionurl.getFailoverMethod().equals("roundrobin")); - Assert.assertTrue(connectionurl.getUsername().equals("ritchiem")); - Assert.assertTrue(connectionurl.getPassword().equals("bob")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); - - Assert.assertTrue(connectionurl.getBrokerCount() == 2); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - Assert.assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); - - service = connectionurl.getBrokerDetails(1); - - Assert.assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("fancyserver")); - Assert.assertTrue(service.getPort() == 3000); - - } - - @Test - public void singleTransportUsernamePasswordURL() throws URLSyntaxException - { - String url = "amqp://ritchiem:bob@/temp?brokerlist='tcp://localhost:5672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("ritchiem")); - Assert.assertTrue(connectionurl.getPassword().equals("bob")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); - - Assert.assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - Assert.assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); - } - - @Test - public void singleTransportUsernameBlankPasswordURL() throws URLSyntaxException - { - String url = "amqp://ritchiem:@/temp?brokerlist='tcp://localhost:5672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("ritchiem")); - Assert.assertTrue(connectionurl.getPassword().equals("")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); - - Assert.assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - Assert.assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); - } - - @Test - public void failedURLNullPassword() - { - String url = "amqp://ritchiem@/temp?brokerlist='tcp://localhost:5672'"; - - try - { - new AMQConnectionURL(url); - Assert.fail("URL has null password"); - } - catch (URLSyntaxException e) - { - Assert.assertTrue(e.getReason().equals("Null password in user information not allowed.")); - Assert.assertTrue(e.getIndex() == 7); - } - } - - - @Test - public void singleTransportURL() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("guest")); - Assert.assertTrue(connectionurl.getPassword().equals("guest")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/test")); - - - Assert.assertTrue(connectionurl.getBrokerCount() == 1); - - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - Assert.assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); - } - - @Test - public void singleTransportWithClientURLURL() throws URLSyntaxException - { - String url = "amqp://guest:guest@clientname/temp?brokerlist='tcp://localhost:5672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("guest")); - Assert.assertTrue(connectionurl.getPassword().equals("guest")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); - Assert.assertTrue(connectionurl.getClientName().equals("clientname")); - - - Assert.assertTrue(connectionurl.getBrokerCount() == 1); - - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - Assert.assertTrue(service.getTransport().equals("tcp")); - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); - } - - @Test - public void singleTransport1OptionURL() throws URLSyntaxException - { - String url = "amqp://guest:guest@/temp?brokerlist='tcp://localhost:5672',routingkey='jim'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("guest")); - Assert.assertTrue(connectionurl.getPassword().equals("guest")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); - - - Assert.assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - Assert.assertTrue(service.getTransport().equals("tcp")); - - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); - Assert.assertTrue(connectionurl.getOption("routingkey").equals("jim")); - } - - @Test - public void singleTransportDefaultedBroker() throws URLSyntaxException - { - String url = "amqp://guest:guest@/temp?brokerlist='localhost'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("guest")); - Assert.assertTrue(connectionurl.getPassword().equals("guest")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); - - - Assert.assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - Assert.assertTrue(service.getTransport().equals("tcp")); - - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); - } - - - @Test - public void singleTransportMultiOptionURL() throws URLSyntaxException - { - String url = "amqp://guest:guest@/temp?brokerlist='tcp://localhost:5672',routingkey='jim',timeout='200',immediatedelivery='true'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("guest")); - Assert.assertTrue(connectionurl.getPassword().equals("guest")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); - - Assert.assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - Assert.assertTrue(service.getTransport().equals("tcp")); - - Assert.assertTrue(service.getHost().equals("localhost")); - Assert.assertTrue(service.getPort() == 5672); - - Assert.assertTrue(connectionurl.getOption("routingkey").equals("jim")); - Assert.assertTrue(connectionurl.getOption("timeout").equals("200")); - Assert.assertTrue(connectionurl.getOption("immediatedelivery").equals("true")); - } - - @Test - public void singlevmURL() throws URLSyntaxException - { - String url = "amqp://guest:guest@/messages?brokerlist='vm://:2'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - Assert.assertTrue(connectionurl.getFailoverMethod() == null); - Assert.assertTrue(connectionurl.getUsername().equals("guest")); - Assert.assertTrue(connectionurl.getPassword().equals("guest")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/messages")); - - Assert.assertTrue(connectionurl.getBrokerCount() == 1); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - Assert.assertTrue(service.getTransport().equals("vm")); - Assert.assertTrue(service.getHost().equals("")); - Assert.assertTrue(service.getPort() == 2); - - } - - @Test - public void failoverVMURL() throws URLSyntaxException - { - String url = "amqp://ritchiem:bob@/temp?brokerlist='vm://:2;vm://:3',failover='roundrobin'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - Assert.assertTrue(connectionurl.getFailoverMethod().equals("roundrobin")); - Assert.assertTrue(connectionurl.getUsername().equals("ritchiem")); - Assert.assertTrue(connectionurl.getPassword().equals("bob")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); - - Assert.assertTrue(connectionurl.getBrokerCount() == 2); - - BrokerDetails service = connectionurl.getBrokerDetails(0); - - Assert.assertTrue(service.getTransport().equals("vm")); - Assert.assertTrue(service.getHost().equals("")); - Assert.assertTrue(service.getPort() == 2); - - service = connectionurl.getBrokerDetails(1); - Assert.assertTrue(service.getTransport().equals("vm")); - Assert.assertTrue(service.getHost().equals("")); - Assert.assertTrue(service.getPort() == 3); - } - - - @Test - public void noVirtualHostURL() - { - String url = "amqp://user@?brokerlist='tcp://localhost:5672'"; - - try - { - new AMQConnectionURL(url); - Assert.fail("URL has no virtual host should not parse"); - } - catch (URLSyntaxException e) - { - // This should occur. - } - } - - @Test - public void noClientID() throws URLSyntaxException - { - String url = "amqp://user:@/test?brokerlist='tcp://localhost:5672'"; - - ConnectionURL connectionurl = new AMQConnectionURL(url); - - Assert.assertTrue(connectionurl.getUsername().equals("user")); - Assert.assertTrue(connectionurl.getPassword().equals("")); - Assert.assertTrue(connectionurl.getVirtualHost().equals("/test")); - - Assert.assertTrue(connectionurl.getBrokerCount() == 1); - } - - @Test - public void wrongOptionSeperatorInBroker() - { - String url = "amqp://user:@/test?brokerlist='tcp://localhost:5672+option='value''"; - - try - { - 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"); - } - } - catch (URLSyntaxException urise) - { - Assert.assertTrue(urise.getReason().equals("Illegal character in port number")); - } - - } - - @Test - public void wrongOptionSeperatorInOptions() - { - String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'+failover='roundrobin'"; - try - { - new AMQConnectionURL(url); - Assert.fail("URL Should not parse"); - } - catch (URLSyntaxException urise) - { - Assert.assertTrue(urise.getReason().equals("Unterminated option. Possible illegal option separator:'+'")); - } - - } - - @Test - public void transportsDefaultToTCP() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test?brokerlist='localhost:5672;myhost:5673'&failover='roundrobin'"; - - AMQConnectionURL connection = new AMQConnectionURL(url); - - BrokerDetails broker = connection.getBrokerDetails(0); - Assert.assertTrue(broker.getTransport().equals("tcp")); - - broker = connection.getBrokerDetails(1); - Assert.assertTrue(broker.getTransport().equals("tcp")); - } - - @Test - public void noUserDetailsProvidedWithClientID() - - { - String url = "amqp://clientID/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'"; - try - { - new AMQConnectionURL(url); - Assert.fail("URL Should not parse"); - } - catch (URLSyntaxException urise) - { - Assert.assertTrue(urise.getMessage().startsWith("User information not found on url")); - } - - } - - @Test - public void noUserDetailsProvidedNOClientID() - - { - String url = "amqp:///test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'"; - try - { - new AMQConnectionURL(url); - Assert.fail("URL Should not parse"); - } - catch (URLSyntaxException urise) - { - Assert.assertTrue(urise.getMessage().startsWith("User information not found on url")); - } - - } - - @Test - public void checkVirtualhostFormat() throws URLSyntaxException - { - String url = "amqp://guest:guest@/t.-_+!=:?brokerlist='tcp://localhost:5672'"; - - AMQConnectionURL connection = new AMQConnectionURL(url); - Assert.assertTrue(connection.getVirtualHost().equals("/t.-_+!=:")); - } - - @Test - public void checkDefaultPort() throws URLSyntaxException - { - String url = "amqp://guest:guest@/test=:?brokerlist='tcp://localhost'"; - - AMQConnectionURL connection = new AMQConnectionURL(url); - - BrokerDetails broker = connection.getBrokerDetails(0); - Assert.assertTrue(broker.getPort() == AMQBrokerDetails.DEFAULT_PORT); - - } - - @Test - public void checkMissingFinalQuote() throws URLSyntaxException - { - String url = "amqp://guest:guest@id/test" + "?brokerlist='tcp://localhost:5672"; - - try{ - new AMQConnectionURL(url); - }catch(URLSyntaxException e) - { - Assert.assertEquals(e.getMessage(),"Unterminated option at index 32: brokerlist='tcp://localhost:5672"); - } - - - - } - - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(ConnectionURLTest.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/connectionurl/UnitTests.java b/java/client/test/src/org/apache/qpid/connectionurl/UnitTests.java deleted file mode 100644 index f4f269330e..0000000000 --- a/java/client/test/src/org/apache/qpid/connectionurl/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.connectionurl; - -import org.junit.runner.RunWith; -import org.junit.runners.Suite; -import org.apache.qpid.ack.*; -import junit.framework.JUnit4TestAdapter; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ConnectionURLTest.class}) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(org.apache.qpid.connectionurl.UnitTests.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/destinationurl/DestinationURLTest.java b/java/client/test/src/org/apache/qpid/destinationurl/DestinationURLTest.java deleted file mode 100644 index 8369fa9e75..0000000000 --- a/java/client/test/src/org/apache/qpid/destinationurl/DestinationURLTest.java +++ /dev/null @@ -1,150 +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.Test; -import org.junit.Assert; -import org.apache.qpid.url.AMQBindingURL; -import org.apache.qpid.url.URLSyntaxException; -import org.apache.qpid.exchange.ExchangeDefaults; -import junit.framework.JUnit4TestAdapter; - -public class DestinationURLTest -{ - @Test - public void fullURL() throws URLSyntaxException - { - - String url = "exchange.Class://exchangeName/Destination/Queue"; - - AMQBindingURL dest = new AMQBindingURL(url); - - Assert.assertTrue(url.equals(dest.toString())); - - Assert.assertTrue(dest.getExchangeClass().equals("exchange.Class")); - Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); - Assert.assertTrue(dest.getDestinationName().equals("Destination")); - Assert.assertTrue(dest.getQueueName().equals("Queue")); - } - - @Test - public void queue() throws URLSyntaxException - { - - String url = "exchangeClass://exchangeName//Queue"; - - AMQBindingURL dest = new AMQBindingURL(url); - - Assert.assertTrue(url.equals(dest.toString())); - - Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); - Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); - Assert.assertTrue(dest.getDestinationName().equals("")); - Assert.assertTrue(dest.getQueueName().equals("Queue")); - } - - @Test - public void queueWithOption() throws URLSyntaxException - { - - String url = "exchangeClass://exchangeName//Queue?option='value'"; - - AMQBindingURL dest = new AMQBindingURL(url); - - Assert.assertTrue(url.equals(dest.toString())); - - Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); - Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); - Assert.assertTrue(dest.getDestinationName().equals("")); - Assert.assertTrue(dest.getQueueName().equals("Queue")); - Assert.assertTrue(dest.getOption("option").equals("value")); - } - - - @Test - public void destination() throws URLSyntaxException - { - - String url = "exchangeClass://exchangeName/Destination/"; - - AMQBindingURL dest = new AMQBindingURL(url); - - Assert.assertTrue(url.equals(dest.toString())); - - Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); - Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); - Assert.assertTrue(dest.getDestinationName().equals("Destination")); - Assert.assertTrue(dest.getQueueName().equals("")); - } - - @Test - public void destinationWithOption() throws URLSyntaxException - { - - String url = "exchangeClass://exchangeName/Destination/?option='value'"; - - AMQBindingURL dest = new AMQBindingURL(url); - - Assert.assertTrue(url.equals(dest.toString())); - - Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); - Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); - Assert.assertTrue(dest.getDestinationName().equals("Destination")); - Assert.assertTrue(dest.getQueueName().equals("")); - - Assert.assertTrue(dest.getOption("option").equals("value")); - } - - @Test - public void destinationWithMultiOption() throws URLSyntaxException - { - - String url = "exchangeClass://exchangeName/Destination/?option='value',option2='value2'"; - - AMQBindingURL dest = new AMQBindingURL(url); - - Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); - Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); - Assert.assertTrue(dest.getDestinationName().equals("Destination")); - Assert.assertTrue(dest.getQueueName().equals("")); - - Assert.assertTrue(dest.getOption("option").equals("value")); - Assert.assertTrue(dest.getOption("option2").equals("value2")); - } - - @Test - public void destinationWithNoExchangeDefaultsToDirect() throws URLSyntaxException - { - - String url = "IBMPerfQueue1?durable='true'"; - - AMQBindingURL dest = new AMQBindingURL(url); - - Assert.assertTrue(dest.getExchangeClass().equals(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)); - Assert.assertTrue(dest.getExchangeName().equals(ExchangeDefaults.DIRECT_EXCHANGE_NAME)); - Assert.assertTrue(dest.getDestinationName().equals("")); - Assert.assertTrue(dest.getQueueName().equals("IBMPerfQueue1")); - - Assert.assertTrue(dest.getOption("durable").equals("true")); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(DestinationURLTest.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/destinationurl/UnitTests.java b/java/client/test/src/org/apache/qpid/destinationurl/UnitTests.java deleted file mode 100644 index 12760aef94..0000000000 --- a/java/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/java/client/test/src/org/apache/qpid/failover/FailoverBrokerTester.java b/java/client/test/src/org/apache/qpid/failover/FailoverBrokerTester.java deleted file mode 100644 index 96c863fae4..0000000000 --- a/java/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/java/client/test/src/org/apache/qpid/failover/FailoverMultiMethodTest.java b/java/client/test/src/org/apache/qpid/failover/FailoverMultiMethodTest.java deleted file mode 100644 index b9f4c1c0dc..0000000000 --- a/java/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/java/client/test/src/org/apache/qpid/failover/FailoverRoundRobinTest.java b/java/client/test/src/org/apache/qpid/failover/FailoverRoundRobinTest.java deleted file mode 100644 index 23119f2394..0000000000 --- a/java/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/java/client/test/src/org/apache/qpid/failover/FailoverSingleServerTest.java b/java/client/test/src/org/apache/qpid/failover/FailoverSingleServerTest.java deleted file mode 100644 index 7f3b058438..0000000000 --- a/java/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/java/client/test/src/org/apache/qpid/failover/FailoverTest.java b/java/client/test/src/org/apache/qpid/failover/FailoverTest.java deleted file mode 100644 index 4905bf5614..0000000000 --- a/java/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/java/client/test/src/org/apache/qpid/failover/FailoverTxTest.java b/java/client/test/src/org/apache/qpid/failover/FailoverTxTest.java deleted file mode 100644 index 10ec682bf5..0000000000 --- a/java/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/java/client/test/src/org/apache/qpid/forwardall/Client.java b/java/client/test/src/org/apache/qpid/forwardall/Client.java deleted file mode 100644 index 4ad8587ae0..0000000000 --- a/java/client/test/src/org/apache/qpid/forwardall/Client.java +++ /dev/null @@ -1,106 +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.forwardall; - -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQQueue; -import org.apache.qpid.client.AMQSession; - -import javax.jms.Message; -import javax.jms.MessageListener; - -/** - * Declare a private temporary response queue, - * send a message to amq.direct with a well known routing key with the - * private response queue as the reply-to destination - * consume responses. - */ -public class Client implements MessageListener -{ - private final AMQConnection _connection; - private final AMQSession _session; - private final int _expected; - private int _count; - - Client(String broker, int expected) throws Exception - { - this(connect(broker), expected); - } - - Client(AMQConnection connection, int expected) throws Exception - { - _connection = connection; - _expected = expected; - _session = (AMQSession) _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); - AMQQueue response = new AMQQueue("ResponseQueue", true); - _session.createConsumer(response).setMessageListener(this); - _connection.start(); - AMQQueue service = new SpecialQueue("ServiceQueue"); - Message request = _session.createTextMessage("Request!"); - request.setJMSReplyTo(response); - _session.createProducer(service).send(request); - } - - void shutdownWhenComplete() throws Exception - { - waitUntilComplete(); - _connection.close(); - } - - public void onMessage(Message response) - { - System.out.println("Received " + (++_count) + " of " + _expected + " responses."); - if(_count == _expected) - { - synchronized(this) - { - notifyAll(); - } - } - } - - synchronized void waitUntilComplete() throws InterruptedException - { - while(_count < _expected) - { - wait(); - } - } - - static AMQConnection connect(String broker) throws Exception - { - return new AMQConnection(broker, "guest", "guest", "Client" + System.currentTimeMillis(), "/test_path"); - } - - public static void main(String[] argv) throws Exception - { - final String connectionString; - final int expected; - if (argv.length == 0) { - connectionString = "localhost:5672"; - expected = 100; - } - else - { - connectionString = argv[0]; - expected = Integer.parseInt(argv[1]); - } - - new Client(connect(connectionString), expected).shutdownWhenComplete(); - } -} diff --git a/java/client/test/src/org/apache/qpid/forwardall/Combined.java b/java/client/test/src/org/apache/qpid/forwardall/Combined.java deleted file mode 100644 index f767e8b1e8..0000000000 --- a/java/client/test/src/org/apache/qpid/forwardall/Combined.java +++ /dev/null @@ -1,72 +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.forwardall; - -import junit.framework.JUnit4TestAdapter; -import org.junit.Test; -import org.junit.Before; -import org.junit.Assert; -import org.junit.After; -import org.apache.qpid.client.transport.TransportConnection; -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 -{ - - @Before - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() - { - ServiceCreator.closeAll(); - TransportConnection.killVMBroker(1); - } - - @Test - public void forwardAll() throws Exception - { - int services = 2; - ServiceCreator.start("vm://:1", services); - - System.out.println("Starting client..."); - - new Client("vm://:1", services).shutdownWhenComplete(); - - System.out.println("Completed successfully!"); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(Combined.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/forwardall/Service.java b/java/client/test/src/org/apache/qpid/forwardall/Service.java deleted file mode 100644 index f0a62456f5..0000000000 --- a/java/client/test/src/org/apache/qpid/forwardall/Service.java +++ /dev/null @@ -1,81 +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.forwardall; - -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQQueue; -import org.apache.qpid.client.AMQSession; - -import javax.jms.Destination; -import javax.jms.Message; -import javax.jms.MessageListener; -import javax.jms.JMSException; - -/** - * Declare a queue and bind it to amq.direct with a 'well known' routing key, - * register a consumer for this queue and send a response to every message received. - */ -public class Service implements MessageListener -{ - private final AMQConnection _connection; - private final AMQSession _session; - - Service(String broker) throws Exception - { - this(connect(broker)); - } - - Service(AMQConnection connection) throws Exception - { - _connection = connection; - AMQQueue queue = new SpecialQueue("ServiceQueue"); - _session = (AMQSession) _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); - _session.createConsumer(queue).setMessageListener(this); - _connection.start(); - } - - public void onMessage(Message request) - { - try - { - Message response = _session.createTextMessage("Response!"); - Destination replyTo = request.getJMSReplyTo(); - _session.createProducer(replyTo).send(response); - } - catch (Exception e) - { - e.printStackTrace(System.out); - } - } - - public void close() throws JMSException - { - _connection.close(); - } - - static AMQConnection connect(String broker) throws Exception - { - return new AMQConnection(broker, "guest", "guest", "Client" + System.currentTimeMillis(), "/test_path"); - } - -// public static void main(String[] argv) throws Exception -// { -// String broker = argv.length == 0? "localhost:5672" : argv[0]; -// new Service(broker); -// } -} diff --git a/java/client/test/src/org/apache/qpid/forwardall/ServiceCreator.java b/java/client/test/src/org/apache/qpid/forwardall/ServiceCreator.java deleted file mode 100644 index e58cc924d4..0000000000 --- a/java/client/test/src/org/apache/qpid/forwardall/ServiceCreator.java +++ /dev/null @@ -1,103 +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.forwardall; - -import javax.jms.JMSException; - -public class ServiceCreator implements Runnable -{ - private static Thread[] threads; - private static ServiceCreator[] _services; - - private final String broker; - private Service service; - - ServiceCreator(String broker) - { - this.broker = broker; - } - - public void run() - { - try - { - service = new Service(broker); - } - catch (Exception e) - { - e.printStackTrace(System.out); - } - } - - public void closeSC() throws JMSException - { - service.close(); - } - - static void closeAll() - { - for (int i = 0; i < _services.length; i++) - { - try - { - _services[i].closeSC(); - } - catch (JMSException e) - { - //ignore - } - } - } - - static void start(String broker, int services) throws InterruptedException - { - threads = new Thread[services]; - _services = new ServiceCreator[services]; - ServiceCreator runner = new ServiceCreator(broker); - //start services - System.out.println("Starting " + services + " services..."); - for (int i = 0; i < services; i++) - { - threads[i] = new Thread(runner); - _services[i] = runner; - threads[i].start(); - } - - for (int i = 0; i < threads.length; i++) - { - threads[i].join(); - } - } - - public static void main(String[] argv) throws Exception - { - final String connectionString; - final int services; - if (argv.length == 0) - { - connectionString = "localhost:5672"; - services = 100; - } - else - { - connectionString = argv[0]; - services = Integer.parseInt(argv[1]); - } - start(connectionString, services); - } -} diff --git a/java/client/test/src/org/apache/qpid/forwardall/SpecialQueue.java b/java/client/test/src/org/apache/qpid/forwardall/SpecialQueue.java deleted file mode 100644 index efa633033f..0000000000 --- a/java/client/test/src/org/apache/qpid/forwardall/SpecialQueue.java +++ /dev/null @@ -1,41 +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.forwardall; - -import org.apache.qpid.client.AMQQueue; - -/** - * Queue that allows several private queues to be registered and bound - * to an exchange with the same routing key. - * - */ -class SpecialQueue extends AMQQueue -{ - private final String name; - - SpecialQueue(String name) - { - super(name, true); - this.name = name; - } - - public String getRoutingKey() - { - return name; - } -} diff --git a/java/client/test/src/org/apache/qpid/forwardall/UnitTests.java b/java/client/test/src/org/apache/qpid/forwardall/UnitTests.java deleted file mode 100644 index c62acce11d..0000000000 --- a/java/client/test/src/org/apache/qpid/forwardall/UnitTests.java +++ /dev/null @@ -1,34 +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.forwardall; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({ - Combined.class -}) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} diff --git a/java/client/test/src/org/apache/qpid/framing/FieldTableTest.java b/java/client/test/src/org/apache/qpid/framing/FieldTableTest.java deleted file mode 100644 index c76596ac5c..0000000000 --- a/java/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/java/client/test/src/org/apache/qpid/test/unit/ack/DisconnectAndRedeliverTest.java b/java/client/test/src/org/apache/qpid/test/unit/ack/DisconnectAndRedeliverTest.java new file mode 100644 index 0000000000..4e96695d23 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/ack/DisconnectAndRedeliverTest.java @@ -0,0 +1,234 @@ +/* + * + * 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.ack; + +import junit.framework.JUnit4TestAdapter; +import org.apache.log4j.Logger; +import org.apache.log4j.xml.DOMConfigurator; +import org.apache.qpid.client.AMQConnection; +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.apache.qpid.server.registry.ApplicationRegistry; +import org.apache.qpid.server.store.TestableMemoryMessageStore; +import org.apache.qpid.server.util.TestApplicationRegistry; +import org.junit.After; +import org.junit.Assert; +import org.junit.Before; +import org.junit.Test; + +import javax.jms.*; + +public class DisconnectAndRedeliverTest +{ + private static final Logger _logger = Logger.getLogger(DisconnectAndRedeliverTest.class); + + + static + { + String workdir = System.getProperty("QPID_WORK"); + if (workdir == null || workdir.equals("")) + { + String tempdir = System.getProperty("java.io.tmpdir"); + System.out.println("QPID_WORK not set using tmp directory: " + tempdir); + System.setProperty("QPID_WORK", tempdir); + } + //DOMConfigurator.configure("../etc/log4j.xml"); + DOMConfigurator.configure("broker/etc/log4j.xml"); + } + + @Before + public void resetAppliactionRegistry() throws Exception + { + createVMBroker(); + ApplicationRegistry.initialise(new TestApplicationRegistry(), 1); + } + + + public void createVMBroker() + { + try + { + TransportConnection.createVMBroker(1); + } + catch (AMQVMBrokerCreationException e) + { + Assert.fail("Unable to create broker: " + e); + } + } + + @After + public void stopVmBroker() + { + TransportConnection.killVMBroker(1); + } + + /** + * This tests that when there are unacknowledged messages on a channel they are requeued for delivery when + * the channel is closed. + * + * @throws Exception + */ + @Test + public void disconnectRedeliversMessages() throws Exception + { + Connection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); + + TestableMemoryMessageStore store = (TestableMemoryMessageStore) ApplicationRegistry.getInstance().getMessageStore(); + + Session consumerSession = (AMQSession) con.createSession(false, Session.CLIENT_ACKNOWLEDGE); + AMQQueue queue = new AMQQueue("someQ", "someQ", false, false); + MessageConsumer consumer = consumerSession.createConsumer(queue); + //force synch to ensure the consumer has resulted in a bound queue + ((AMQSession) consumerSession).declareExchangeSynch("amq.direct", "direct"); + + Connection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "/test"); + + + Session producerSession = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE); + MessageProducer producer = producerSession.createProducer(queue); + + _logger.info("Sending four messages"); + producer.send(producerSession.createTextMessage("msg1")); + producer.send(producerSession.createTextMessage("msg2")); + producer.send(producerSession.createTextMessage("msg3")); + producer.send(producerSession.createTextMessage("msg4")); + + con2.close(); + + _logger.info("Starting connection"); + con.start(); + TextMessage tm = (TextMessage) consumer.receive(); + tm.acknowledge(); + _logger.info("Received and acknowledged first message"); + consumer.receive(); + consumer.receive(); + consumer.receive(); + _logger.info("Received all four messages. About to disconnect and reconnect"); + + con.close(); + con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); + consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE); + consumer = consumerSession.createConsumer(queue); + + _logger.info("Starting second consumer connection"); + con.start(); + + tm = (TextMessage) consumer.receive(3000); + Assert.assertEquals("msg2", tm.getText()); + + + tm = (TextMessage) consumer.receive(3000); + Assert.assertEquals("msg3", tm.getText()); + + + tm = (TextMessage) consumer.receive(3000); + Assert.assertEquals("msg4", tm.getText()); + + _logger.info("Received redelivery of three messages. Acknowledging last message"); + tm.acknowledge(); + + con.close(); + + con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); + consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE); + consumer = consumerSession.createConsumer(queue); + _logger.info("Starting third consumer connection"); + con.start(); + tm = (TextMessage) consumer.receiveNoWait(); + Assert.assertNull(tm); + _logger.info("No messages redelivered as is expected"); + con.close(); + + con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); + consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE); + consumer = consumerSession.createConsumer(queue); + _logger.info("Starting fourth consumer connection"); + con.start(); + tm = (TextMessage) consumer.receive(3000); + Assert.assertNull(tm); + _logger.info("No messages redelivered as is expected"); + con.close(); + + _logger.info("Actually:" + store.getMessageMap().size()); + // Assert.assertTrue(store.getMessageMap().size() == 0); + } + + /** + * Tests that unacknowledged messages are thrown away when the channel is closed and they cannot be + * requeued (due perhaps to the queue being deleted). + * + * @throws Exception + */ + @Test + public void disconnectWithTransientQueueThrowsAwayMessages() throws Exception + { + + Connection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); + TestableMemoryMessageStore store = (TestableMemoryMessageStore) ApplicationRegistry.getInstance().getMessageStore(); + Session consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE); + Queue queue = new AMQQueue("someQ", "someQ", false, true); + MessageConsumer consumer = consumerSession.createConsumer(queue); + //force synch to ensure the consumer has resulted in a bound queue + ((AMQSession) consumerSession).declareExchangeSynch("amq.direct", "direct"); + + Connection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "/test"); + Session producerSession = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE); + MessageProducer producer = producerSession.createProducer(queue); + + _logger.info("Sending four messages"); + producer.send(producerSession.createTextMessage("msg1")); + producer.send(producerSession.createTextMessage("msg2")); + producer.send(producerSession.createTextMessage("msg3")); + producer.send(producerSession.createTextMessage("msg4")); + + con2.close(); + + _logger.info("Starting connection"); + con.start(); + TextMessage tm = (TextMessage) consumer.receive(); + tm.acknowledge(); + _logger.info("Received and acknowledged first message"); + consumer.receive(); + consumer.receive(); + consumer.receive(); + _logger.info("Received all four messages. About to disconnect and reconnect"); + + con.close(); + con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); + consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE); + consumer = consumerSession.createConsumer(queue); + + _logger.info("Starting second consumer connection"); + con.start(); + + tm = (TextMessage) consumer.receiveNoWait(); + Assert.assertNull(tm); + _logger.info("No messages redelivered as is expected"); + + _logger.info("Actually:" + store.getMessageMap().size()); + Assert.assertTrue(store.getMessageMap().size() == 0); + con.close(); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(DisconnectAndRedeliverTest.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/ack/RecoverTest.java b/java/client/test/src/org/apache/qpid/test/unit/ack/RecoverTest.java new file mode 100644 index 0000000000..4322a53b21 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/ack/RecoverTest.java @@ -0,0 +1,134 @@ +/* + * + * 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.ack; + +import junit.framework.JUnit4TestAdapter; +import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.client.AMQQueue; +import org.apache.qpid.client.AMQSession; +import org.apache.qpid.client.transport.TransportConnection; +import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; +import org.apache.log4j.Logger; +import org.apache.log4j.xml.DOMConfigurator; +import org.junit.Assert; +import org.junit.Test; +import org.junit.Before; +import org.junit.After; + +import javax.jms.*; + +public class RecoverTest +{ + private static final Logger _logger = Logger.getLogger(RecoverTest.class); + + static + { + String workdir = System.getProperty("QPID_WORK"); + if (workdir == null || workdir.equals("")) + { + String tempdir = System.getProperty("java.io.tmpdir"); + System.out.println("QPID_WORK not set using tmp directory: " + tempdir); + System.setProperty("QPID_WORK", tempdir); + } + //DOMConfigurator.configure("../etc/log4j.xml"); + DOMConfigurator.configure("broker/etc/log4j.xml"); + } + + @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 recoverResendsMsgs() throws Exception + { + Connection con = new AMQConnection("vm://:1", "guest", "guest", "consumer1", "/test"); + + Session consumerSession = con.createSession(false, Session.CLIENT_ACKNOWLEDGE); + Queue queue = new AMQQueue("someQ", "someQ", false, true); + MessageConsumer consumer = consumerSession.createConsumer(queue); + //force synch to ensure the consumer has resulted in a bound queue + ((AMQSession) consumerSession).declareExchangeSynch("amq.direct", "direct"); + + Connection con2 = new AMQConnection("vm://:1", "guest", "guest", "producer1", "/test"); + Session producerSession = con2.createSession(false, Session.CLIENT_ACKNOWLEDGE); + MessageProducer producer = producerSession.createProducer(queue); + + _logger.info("Sending four messages"); + producer.send(producerSession.createTextMessage("msg1")); + producer.send(producerSession.createTextMessage("msg2")); + producer.send(producerSession.createTextMessage("msg3")); + producer.send(producerSession.createTextMessage("msg4")); + + con2.close(); + + _logger.info("Starting connection"); + con.start(); + TextMessage tm = (TextMessage) consumer.receive(); + tm.acknowledge(); + _logger.info("Received and acknowledged first message"); + consumer.receive(); + consumer.receive(); + consumer.receive(); + _logger.info("Received all four messages. Calling recover with three outstanding messages"); + // no ack for last three messages so when I call recover I expect to get three messages back + consumerSession.recover(); + tm = (TextMessage) consumer.receive(3000); + Assert.assertEquals("msg2", tm.getText()); + + tm = (TextMessage) consumer.receive(3000); + Assert.assertEquals("msg3", tm.getText()); + + tm = (TextMessage) consumer.receive(3000); + Assert.assertEquals("msg4", tm.getText()); + + _logger.info("Received redelivery of three messages. Acknowledging last message"); + tm.acknowledge(); + + _logger.info("Calling acknowledge with no outstanding messages"); + // all acked so no messages to be delivered + consumerSession.recover(); + + tm = (TextMessage) consumer.receiveNoWait(); + Assert.assertNull(tm); + _logger.info("No messages redelivered as is expected"); + + con.close(); + + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(RecoverTest.class); + } +} + diff --git a/java/client/test/src/org/apache/qpid/test/unit/ack/UnitTests.java b/java/client/test/src/org/apache/qpid/test/unit/ack/UnitTests.java new file mode 100644 index 0000000000..394817c3f9 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/ack/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.ack; + +import junit.framework.JUnit4TestAdapter; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({DisconnectAndRedeliverTest.class, RecoverTest.class}) +public class UnitTests +{ + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(UnitTests.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/basic/BytesMessageTest.java b/java/client/test/src/org/apache/qpid/test/unit/basic/BytesMessageTest.java new file mode 100644 index 0000000000..29a1b57e26 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/basic/BytesMessageTest.java @@ -0,0 +1,231 @@ +/* + * + * 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.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.apache.qpid.client.message.JMSBytesMessage; +import org.apache.mina.common.ByteBuffer; +import org.junit.Test; +import org.junit.Before; +import org.junit.Assert; +import org.junit.After; + +import javax.jms.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class BytesMessageTest implements MessageListener +{ + private Connection _connection; + private Destination _destination; + private Session _session; + private final List received = new ArrayList(); + private final List messages = new ArrayList(); + private int _count = 100; + public String _connectionString = "vm://:1"; + + @Before + public void init() throws Exception + { + createVMBroker(); + init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); + } + + public void createVMBroker() + { + try + { + TransportConnection.createVMBroker(1); + } + catch (AMQVMBrokerCreationException e) + { + Assert.fail("Unable to create broker: " + e); + } + } + + @After + public void stopVmBroker() + { + TransportConnection.killVMBroker(1); + } + + void init(AMQConnection connection) throws Exception + { + init(connection, new AMQQueue(randomize("BytesMessageTest"), true)); + } + + void init(AMQConnection connection, AMQDestination destination) throws Exception + { + _connection = connection; + _destination = destination; + _session = connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); + + // Set up a slow consumer. + _session.createConsumer(destination).setMessageListener(this); + connection.start(); + } + + @Test + public void test() throws Exception + { + + try + { + send(_count); + waitFor(_count); + check(); + System.out.println("Completed without failure"); + } + finally + { + _connection.close(); + } + } + + void send(int count) throws JMSException + { + //create a publisher + MessageProducer producer = _session.createProducer(_destination); + for (int i = 0; i < count; i++) + { + BytesMessage msg = _session.createBytesMessage(); + byte[] data = ("Message " + i).getBytes(); + msg.writeBytes(data); + messages.add(data); + producer.send(msg); + } + } + + void waitFor(int count) throws InterruptedException + { + synchronized(received) + { + while (received.size() < count) + { + received.wait(); + } + } + } + + void check() throws JMSException + { + List actual = new ArrayList(); + for (JMSBytesMessage m : received) + { + ByteBuffer buffer = m.getData(); + byte[] data = new byte[buffer.remaining()]; + buffer.get(data); + actual.add(data); + } + + assertEqual(messages.iterator(), actual.iterator()); + } + + private static void assertEqual(Iterator expected, Iterator actual) + { + List errors = new ArrayList(); + while (expected.hasNext() && actual.hasNext()) + { + try + { + assertEquivalent((byte[]) expected.next(), (byte[]) actual.next()); + } + catch (Exception e) + { + errors.add(e.getMessage()); + } + } + while (expected.hasNext()) + { + errors.add("Expected " + expected.next() + " but no more actual values."); + } + while (actual.hasNext()) + { + errors.add("Found " + actual.next() + " but no more expected values."); + } + if (!errors.isEmpty()) + { + throw new RuntimeException(errors.toString()); + } + } + + private static void assertEquivalent(byte[] expected, byte[] actual) + { + if (expected.length != actual.length) + { + throw new RuntimeException("Expected length " + expected.length + " got " + actual.length); + } + for (int i = 0; i < expected.length; i++) + { + if (expected[i] != actual[i]) + { + throw new RuntimeException("Failed on byte " + i + " of " + expected.length); + } + } + } + + public void onMessage(Message message) + { + synchronized(received) + { + received.add((JMSBytesMessage) message); + received.notify(); + } + } + + private static String randomize(String in) + { + return in + System.currentTimeMillis(); + } + + public static void main(String[] argv) throws Exception + { + final String connectionString; + final int count; + if (argv.length == 0) + { + connectionString = "vm://:1"; + count = 100; + } + else + { + connectionString = argv[0]; + count = Integer.parseInt(argv[1]); + } + + System.out.println("connectionString = " + connectionString); + System.out.println("count = " + count); + + BytesMessageTest test = new BytesMessageTest(); + test._connectionString = connectionString; + test._count = count; + test.test(); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(BytesMessageTest.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java b/java/client/test/src/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java new file mode 100644 index 0000000000..d4e073d9ca --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/basic/FieldTableKeyEnumeratorTest.java @@ -0,0 +1,85 @@ +/* + * + * 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.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; + +import junit.framework.JUnit4TestAdapter; + +import javax.jms.JMSException; + +public class FieldTableKeyEnumeratorTest +{ + @Test + public void testKeyEnumeration() + { + FieldTable result = new FieldTable(); + result.put("one", 1L); + result.put("two", 2L); + result.put("three", 3L); + result.put("four", 4L); + result.put("five", 5L); + + Enumeration e = result.keys(); + + Assert.assertTrue("one".equals(e.nextElement())); + Assert.assertTrue("two".equals(e.nextElement())); + Assert.assertTrue("three".equals(e.nextElement())); + Assert.assertTrue("four".equals(e.nextElement())); + Assert.assertTrue("five".equals(e.nextElement())); + } + + @Test + public void testPropertEnu() + { + try + { + JMSTextMessage text = TestMessageHelper.newJMSTextMessage(); + + text.setBooleanProperty("Boolean1", true); + text.setBooleanProperty("Boolean2", true); + text.setIntProperty("Int", 2); + text.setLongProperty("Long", 2); + + Enumeration e = text.getPropertyNames(); + + Assert.assertTrue("Boolean1".equals(e.nextElement())); + Assert.assertTrue("Boolean2".equals(e.nextElement())); + Assert.assertTrue("Int".equals(e.nextElement())); + Assert.assertTrue("Long".equals(e.nextElement())); + } + catch (JMSException e) + { + + } + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(FieldTableKeyEnumeratorTest.class); + } + + +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java b/java/client/test/src/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java new file mode 100644 index 0000000000..472ec4d210 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/basic/FieldTableMessageTest.java @@ -0,0 +1,179 @@ +/* + * + * 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.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.apache.qpid.client.message.JMSBytesMessage; +import org.apache.qpid.framing.AMQFrameDecodingException; +import org.apache.qpid.framing.FieldTable; +import org.apache.qpid.framing.FieldTableTest; +import org.apache.mina.common.ByteBuffer; +import org.junit.Before; +import org.junit.Test; +import org.junit.Assert; +import org.junit.After; + +import javax.jms.*; +import java.io.IOException; +import java.util.ArrayList; + +public class FieldTableMessageTest implements MessageListener +{ + private AMQConnection _connection; + private AMQDestination _destination; + private AMQSession _session; + private final ArrayList received = new ArrayList(); + private FieldTable _expected; + private int _count = 10; + public String _connectionString = "vm://:1"; + + @Before + public void init() throws Exception + { + createVMBroker(); + init(new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path")); + } + + public void createVMBroker() + { + try + { + TransportConnection.createVMBroker(1); + } + catch (AMQVMBrokerCreationException e) + { + Assert.fail("Unable to create broker: " + e); + } + } + + @After + public void stopVmBroker() + { + TransportConnection.killVMBroker(1); + } + + + private void init(AMQConnection connection) throws Exception + { + init(connection, new AMQQueue(randomize("FieldTableMessageTest"), true)); + } + + private void init(AMQConnection connection, AMQDestination destination) throws Exception + { + _connection = connection; + _destination = destination; + _session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); + + //set up a slow consumer + _session.createConsumer(destination).setMessageListener(this); + connection.start(); + + //_expected = new FieldTableTest().load("FieldTableTest2.properties"); + _expected = load(); + } + + private FieldTable load() throws IOException + { + FieldTable result = new FieldTable(); + result.put("one", 1L); + result.put("two", 2L); + result.put("three", 3L); + result.put("four", 4L); + result.put("five", 5L); + + return result; + } + + @Test + public void test() throws Exception + { + int count = _count; + send(count); + waitFor(count); + check(); + System.out.println("Completed without failure"); + _connection.close(); + } + + void send(int count) throws JMSException, IOException + { + //create a publisher + MessageProducer producer = _session.createProducer(_destination); + for (int i = 0; i < count; i++) + { + BytesMessage msg = _session.createBytesMessage(); + msg.writeBytes(_expected.getDataAsBytes()); + producer.send(msg); + } + } + + void waitFor(int count) throws InterruptedException + { + synchronized(received) + { + while (received.size() < count) + { + received.wait(); + } + } + } + + void check() throws JMSException, AMQFrameDecodingException + { + for (Object m : received) + { + ByteBuffer buffer = ((JMSBytesMessage) m).getData(); + FieldTable actual = new FieldTable(buffer, buffer.remaining()); + new FieldTableTest().assertEquivalent(_expected, actual); + } + } + + public void onMessage(Message message) + { + synchronized(received) + { + received.add((JMSBytesMessage) message); + received.notify(); + } + } + + private static String randomize(String in) + { + return in + System.currentTimeMillis(); + } + + public static void main(String[] argv) throws Exception + { + FieldTableMessageTest test = new FieldTableMessageTest(); + test._connectionString = argv.length == 0 ? "vm://:1" : argv[0]; + test.init(); + test._count = argv.length > 1 ? Integer.parseInt(argv[1]) : 5; + test.test(); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(FieldTableMessageTest.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java b/java/client/test/src/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java new file mode 100644 index 0000000000..ef4d6f829b --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/basic/MultipleConnectionTest.java @@ -0,0 +1,244 @@ +/* + * + * 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.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.*; + +/** + * This is a slow test. + */ +public class MultipleConnectionTest +{ + public static String _connectionString = "vm://:1"; + + private static class Receiver + { + private AMQConnection _connection; + private Session[] _sessions; + private MessageCounter[] _counters; + + Receiver(String broker, AMQDestination dest, int sessions) throws Exception + { + this(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test_path"), dest, sessions); + } + + Receiver(AMQConnection connection, AMQDestination dest, int sessions) throws Exception + { + _connection = connection; + _sessions = new AMQSession[sessions]; + _counters = new MessageCounter[sessions]; + for (int i = 0; i < sessions; i++) + { + _sessions[i] = _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); + _counters[i] = new MessageCounter(_sessions[i].toString()); + _sessions[i].createConsumer(dest).setMessageListener(_counters[i]); + } + _connection.start(); + } + + void close() throws JMSException + { + _connection.close(); + } + } + + private static class Publisher + { + private AMQConnection _connection; + private Session _session; + private MessageProducer _producer; + + Publisher(String broker, AMQDestination dest) throws Exception + { + this(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test_path"), dest); + } + + Publisher(AMQConnection connection, AMQDestination dest) throws Exception + { + _connection = connection; + _session = _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); + _producer = _session.createProducer(dest); + } + + void send(String msg) throws JMSException + { + _producer.send(_session.createTextMessage(msg)); + } + + void close() throws JMSException + { + _connection.close(); + } + } + + private static class MessageCounter implements MessageListener + { + private final String _name; + private int _count; + + MessageCounter(String name) + { + _name = name; + } + + public synchronized void onMessage(Message message) + { + _count++; + notifyAll(); + } + + synchronized boolean waitUntil(int expected, long maxWait) throws InterruptedException + { + long start = System.currentTimeMillis(); + long timeLeft = maxWait; + do + { + wait(timeLeft); + timeLeft = maxWait - timeSince(start); + } + while (expected > _count && timeLeft > 0); + return expected <= _count; + } + + private long timeSince(long start) + { + return System.currentTimeMillis() - start; + } + + public synchronized String toString() + { + return _name + ": " + _count; + } + } + + private static void waitForCompletion(int expected, long wait, Receiver[] receivers) throws InterruptedException + { + for (int i = 0; i < receivers.length; i++) + { + waitForCompletion(expected, wait, receivers[i]._counters); + } + } + + private static void waitForCompletion(int expected, long wait, MessageCounter[] counters) throws InterruptedException + { + for (int i = 0; i < counters.length; i++) + { + if (!counters[i].waitUntil(expected, wait)) + { + throw new RuntimeException("Expected: " + expected + " got " + counters[i]); + } + ; + } + } + + private static String randomize(String in) + { + return in + System.currentTimeMillis(); + } + + public static void main(String[] argv) throws Exception + { + String broker = argv.length > 0 ? argv[0] : "vm://:1"; + + int connections = 7; + int sessions = 2; + + MultipleConnectionTest test = new MultipleConnectionTest(); + test._connectionString = broker; + test.test(); + } + + @Test + public void test() throws Exception + { + String broker = _connectionString; + int messages = 10; + + AMQTopic topic = new AMQTopic("amq.topic"); + + /* + Receiver[] receivers = new Receiver[connections]; + for(int i = 0; i < receivers.length; i++) + { + receivers[i] = new Receiver(broker, topic, sessions); + } + */ + + Receiver[] receivers = new Receiver[]{ + new Receiver(broker, topic, 2), + new Receiver(broker, topic, 14) + }; + + Publisher publisher = new Publisher(broker, topic); + for (int i = 0; i < messages; i++) + { + publisher.send("Message " + (i + 1)); + } + + try + { + waitForCompletion(messages, 5000, receivers); + System.out.println("All receivers received all expected messages"); + } + finally + { + publisher.close(); + 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/java/client/test/src/org/apache/qpid/test/unit/basic/ObjectMessageTest.java b/java/client/test/src/org/apache/qpid/test/unit/basic/ObjectMessageTest.java new file mode 100644 index 0000000000..3e0d37d9b0 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/basic/ObjectMessageTest.java @@ -0,0 +1,237 @@ +/* + * + * 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.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.apache.qpid.client.message.JMSObjectMessage; +import org.junit.Before; +import org.junit.Test; +import org.junit.Assert; +import org.junit.After; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.MessageProducer; +import java.io.Serializable; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class ObjectMessageTest implements MessageListener +{ + private AMQConnection _connection; + private AMQDestination _destination; + private AMQSession _session; + private final List received = new ArrayList(); + private final List messages = new ArrayList(); + private int _count = 100; + public String _connectionString = "vm://:1"; + + @Before + public void init() + { + String broker = _connectionString; + createVMBroker(); + try + { + init(new AMQConnection(broker, "guest", "guest", randomize("Client"), "/test_path")); + } + catch (Exception e) + { + Assert.fail("Uable to initialise: " + e); + } + } + + public void createVMBroker() + { + try + { + TransportConnection.createVMBroker(1); + } + catch (AMQVMBrokerCreationException e) + { + Assert.fail("Unable to create broker: " + e); + } + } + + @After + public void stopVmBroker() + { + TransportConnection.killVMBroker(1); + } + + private void init(AMQConnection connection) throws Exception + { + init(connection, new AMQQueue(randomize("ObjectMessageTest"), true)); + } + + private void init(AMQConnection connection, AMQDestination destination) throws Exception + { + _connection = connection; + _destination = destination; + _session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); + + //set up a slow consumer + _session.createConsumer(destination).setMessageListener(this); + connection.start(); + } + + @Test + public void test() throws Exception + { + int count = _count; + send(count); + waitFor(count); + check(); + System.out.println("Completed without failure"); + _connection.close(); + } + + void send(int count) throws JMSException + { + //create a publisher + MessageProducer producer = _session.createProducer(_destination); + for (int i = 0; i < count; i++) + { + Payload payload = new Payload("Message " + i); + messages.add(payload); + producer.send(_session.createObjectMessage(payload)); + } + } + + void waitFor(int count) throws InterruptedException + { + synchronized(received) + { + while (received.size() < count) + { + received.wait(); + } + } + } + + void check() throws JMSException + { + List actual = new ArrayList(); + for (JMSObjectMessage m : received) + { + actual.add(m.getObject()); + } + + assertEqual(messages.iterator(), actual.iterator()); + } + + private static void assertEqual(Iterator expected, Iterator actual) + { + List errors = new ArrayList(); + while (expected.hasNext() && actual.hasNext()) + { + try + { + assertEqual(expected.next(), actual.next()); + } + catch (Exception e) + { + errors.add(e.getMessage()); + } + } + while (expected.hasNext()) + { + errors.add("Expected " + expected.next() + " but no more actual values."); + } + while (actual.hasNext()) + { + errors.add("Found " + actual.next() + " but no more expected values."); + } + if (!errors.isEmpty()) + { + throw new RuntimeException(errors.toString()); + } + } + + private static void assertEqual(Object expected, Object actual) + { + if (!expected.equals(actual)) + { + throw new RuntimeException("Expected '" + expected + "' found '" + actual + "'"); + } + } + + public void onMessage(Message message) + { + synchronized(received) + { + received.add((JMSObjectMessage) message); + received.notify(); + } + } + + private static String randomize(String in) + { + return in + System.currentTimeMillis(); + } + + private static class Payload implements Serializable + { + private final String data; + + Payload(String data) + { + this.data = data; + } + + public int hashCode() + { + return data.hashCode(); + } + + public boolean equals(Object o) + { + return o instanceof Payload && ((Payload) o).data.equals(data); + } + + public String toString() + { + return "Payload[" + data + "]"; + } + } + + public static void main(String[] argv) throws Exception + { + ObjectMessageTest test = new ObjectMessageTest(); + test._connectionString = argv.length == 0 ? "vm://:1" : argv[0]; + test.init(); + if (argv.length > 1) + { + test._count = Integer.parseInt(argv[1]); + } + test.test(); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(ObjectMessageTest.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/basic/ReceiveTest.java b/java/client/test/src/org/apache/qpid/test/unit/basic/ReceiveTest.java new file mode 100644 index 0000000000..e781ceee2c --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/basic/ReceiveTest.java @@ -0,0 +1,113 @@ +/* + * + * 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.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; + +public class ReceiveTest +{ + private AMQConnection _connection; + private AMQDestination _destination; + private AMQSession _session; + private MessageConsumer _consumer; + + 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)); + } + + private void init(AMQConnection connection, AMQDestination destination) throws Exception + { + _connection = connection; + _destination = destination; + _session = (AMQSession) connection.createSession(true, AMQSession.NO_ACKNOWLEDGE); + _consumer = _session.createConsumer(_destination); + _connection.start(); + } + + @Test + public void test() throws Exception + { + _consumer.receive(5000); + _connection.close(); + } + + public static void main(String[] argv) throws Exception + { + ReceiveTest test = new ReceiveTest(); + test._connectionString = argv.length == 0 ? VM_BROKER : argv[0]; + test.init(); + test.test(); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(ReceiveTest.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/basic/SessionStartTest.java b/java/client/test/src/org/apache/qpid/test/unit/basic/SessionStartTest.java new file mode 100644 index 0000000000..3cdb1e8cca --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/basic/SessionStartTest.java @@ -0,0 +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.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.transport.TransportConnection; +import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; + +import org.junit.Before; +import org.junit.Test; +import org.junit.Assert; +import org.junit.After; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageListener; + +public class SessionStartTest implements MessageListener +{ + private AMQConnection _connection; + private AMQDestination _destination; + private AMQSession _session; + private int count; + public String _connectionString = "vm://:1"; + + @Before + public void init() + { + 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() + { + try + { + TransportConnection.createVMBroker(1); + } + catch (AMQVMBrokerCreationException e) + { + Assert.fail("Unable to create broker: " + e); + } + } + + @After + public void stopVmBroker() + { + TransportConnection.killVMBroker(1); + } + + private void init(AMQConnection connection) throws Exception + { + init(connection, new AMQQueue(randomize("SessionStartTest"), true)); + } + + private void init(AMQConnection connection, AMQDestination destination) throws Exception + { + _connection = connection; + _destination = destination; + connection.start(); + + _session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); + _session.createConsumer(destination).setMessageListener(this); + } + + @Test + public synchronized void test() throws JMSException, InterruptedException + { + try + { + _session.createProducer(_destination).send(_session.createTextMessage("Message")); + System.out.println("Message sent, waiting for response..."); + wait(1000); + if (count > 0) + { + System.out.println("Got message"); + } + else + { + throw new RuntimeException("Did not get message!"); + } + } + finally + { + _session.close(); + _connection.close(); + } + } + + public synchronized void onMessage(Message message) + { + count++; + notify(); + } + + private static String randomize(String in) + { + return in + System.currentTimeMillis(); + } + + public static void main(String[] argv) throws Exception + { + SessionStartTest test = new SessionStartTest(); + test._connectionString = argv.length == 0 ? "localhost:5672" : argv[0]; + test.init(); + test.test(); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(SessionStartTest.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/basic/TextMessageTest.java b/java/client/test/src/org/apache/qpid/test/unit/basic/TextMessageTest.java new file mode 100644 index 0000000000..d4f1eeb9b1 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/basic/TextMessageTest.java @@ -0,0 +1,209 @@ +/* + * + * 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.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.apache.qpid.client.message.JMSTextMessage; +import org.junit.Before; +import org.junit.Test; +import org.junit.Assert; +import org.junit.After; + +import javax.jms.*; +import java.util.ArrayList; +import java.util.Iterator; +import java.util.List; + +public class TextMessageTest implements MessageListener +{ + private AMQConnection _connection; + private Destination _destination; + private AMQSession _session; + private final List received = new ArrayList(); + private final List messages = new ArrayList(); + private int _count = 100; + public String _connectionString = "vm://:1"; + + @Before + public void init() + { + 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() + { + try + { + TransportConnection.createVMBroker(1); + } + catch (AMQVMBrokerCreationException e) + { + Assert.fail("Unable to create broker: " + e); + } + } + + @After + public void stopVmBroker() + { + TransportConnection.killVMBroker(1); + } + + private void init(AMQConnection connection) throws Exception + { + Destination destination = new AMQQueue(randomize("TextMessageTest"), true); + init(connection, destination); + } + + private void init(AMQConnection connection, Destination destination) throws Exception + { + _connection = connection; + _destination = destination; + _session = (AMQSession) connection.createSession(false, AMQSession.AUTO_ACKNOWLEDGE); + + //set up a slow consumer + _session.createConsumer(destination).setMessageListener(this); + connection.start(); + } + + @Test + public void test() throws Exception + { + int count = _count; + send(count); + waitFor(count); + check(); + System.out.println("Completed without failure"); + _connection.close(); + } + + void send(int count) throws JMSException + { + //create a publisher + MessageProducer producer = _session.createProducer(_destination); + for (int i = 0; i < count; i++) + { + String text = "Message " + i; + messages.add(text); + producer.send(_session.createTextMessage(text)); + } + } + + void waitFor(int count) throws InterruptedException + { + synchronized(received) + { + while (received.size() < count) + { + received.wait(); + } + } + } + + void check() throws JMSException + { + List actual = new ArrayList(); + for (JMSTextMessage m : received) + { + actual.add(m.getText()); + } + + assertEqual(messages.iterator(), actual.iterator()); + } + + private static void assertEqual(Iterator expected, Iterator actual) + { + List errors = new ArrayList(); + while (expected.hasNext() && actual.hasNext()) + { + try + { + assertEqual(expected.next(), actual.next()); + } + catch (Exception e) + { + errors.add(e.getMessage()); + } + } + while (expected.hasNext()) + { + errors.add("Expected " + expected.next() + " but no more actual values."); + } + while (actual.hasNext()) + { + errors.add("Found " + actual.next() + " but no more expected values."); + } + if (!errors.isEmpty()) + { + throw new RuntimeException(errors.toString()); + } + } + + private static void assertEqual(Object expected, Object actual) + { + if (!expected.equals(actual)) + { + throw new RuntimeException("Expected '" + expected + "' found '" + actual + "'"); + } + } + + public void onMessage(Message message) + { + synchronized(received) + { + received.add((JMSTextMessage) message); + received.notify(); + } + } + + private static String randomize(String in) + { + return in + System.currentTimeMillis(); + } + + public static void main(String[] argv) throws Exception + { + TextMessageTest test = new TextMessageTest(); + test._connectionString = argv.length == 0 ? "vm://:1" : argv[0]; + test.init(); + if (argv.length > 1) + { + test._count = Integer.parseInt(argv[1]); + } + test.test(); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(TextMessageTest.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/basic/UnitTests.java b/java/client/test/src/org/apache/qpid/test/unit/basic/UnitTests.java new file mode 100644 index 0000000000..9e17510eb6 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/basic/UnitTests.java @@ -0,0 +1,41 @@ +/* + * + * 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.basic; + +import junit.framework.JUnit4TestAdapter; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import org.apache.qpid.client.message.FieldTableKeyEnumeratorTest; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + BytesMessageTest.class, + FieldTableMessageTest.class, + FieldTableKeyEnumeratorTest.class, + MultipleConnectionTest.class, + ObjectMessageTest.class, + SessionStartTest.class, + TextMessageTest.class + }) +public class UnitTests +{ + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(UnitTests.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/AMQConnectionTest.java b/java/client/test/src/org/apache/qpid/test/unit/client/AMQConnectionTest.java new file mode 100644 index 0000000000..3dbfe39bdc --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/AMQConnectionTest.java @@ -0,0 +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.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/java/client/test/src/org/apache/qpid/test/unit/client/AMQSessionTest.java b/java/client/test/src/org/apache/qpid/test/unit/client/AMQSessionTest.java new file mode 100644 index 0000000000..cf33e7443b --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/AMQSessionTest.java @@ -0,0 +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.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/java/client/test/src/org/apache/qpid/test/unit/client/AllClientUnitTests.java b/java/client/test/src/org/apache/qpid/test/unit/client/AllClientUnitTests.java new file mode 100644 index 0000000000..6e9f173ea8 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/AllClientUnitTests.java @@ -0,0 +1,47 @@ +/* + * + * 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 junit.framework.JUnit4TestAdapter; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +/** + * All client unit tests - even one in packages like org.apache.qpid.ack. + */ +@RunWith(Suite.class) +@Suite.SuiteClasses({ + 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 +{ + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(AllClientUnitTests.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java b/java/client/test/src/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java new file mode 100644 index 0000000000..cb3093e22c --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/channelclose/ChannelCloseOkTest.java @@ -0,0 +1,235 @@ +/* + * + * 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.channelclose; + +import junit.framework.JUnit4TestAdapter; +import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.client.AMQQueue; +import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; +import org.apache.qpid.client.transport.TransportConnection; +import org.apache.log4j.Logger; +import org.junit.After; +import static org.junit.Assert.assertEquals; +import org.junit.Before; +import org.junit.Test; +import org.junit.Assert; + +import javax.jms.*; +import java.util.ArrayList; +import java.util.List; + +/** + * Due to bizarre exception handling all sessions are closed if you get + * a channel close request and no exception listener is registered. + *

+ * JIRA issue IBTBLZ-10. + *

+ * Simulate by: + *

+ * 0. Create two sessions with no exception listener. + * 1. Publish message to queue/topic that does not exist (wrong routing key). + * 2. This will cause a channel close. + * 3. Since client does not have an exception listener, currently all sessions are + * closed. + */ +public class ChannelCloseOkTest +{ + private Connection _connection; + private Destination _destination1; + private Destination _destination2; + private Session _session1; + private Session _session2; + private final List _received1 = new ArrayList(); + private final List _received2 = new ArrayList(); + + private final static Logger _log = Logger.getLogger(ChannelCloseOkTest.class); + public String _connectionString = "vm://:1"; + + + public void createVMBroker() + { + try + { + TransportConnection.createVMBroker(1); + } + catch (AMQVMBrokerCreationException e) + { + Assert.fail("Unable to create broker: " + e); + } + } + + public void stopVmBroker() + { + TransportConnection.killVMBroker(1); + } + + @Before + public void init() throws Exception + { + createVMBroker(); + + _connection = new AMQConnection(_connectionString, "guest", "guest", randomize("Client"), "/test_path"); + + _destination1 = new AMQQueue("q1", true); + _destination2 = new AMQQueue("q2", true); + _session1 = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + _session1.createConsumer(_destination1).setMessageListener(new MessageListener() + { + public void onMessage(Message message) + { + _log.debug("consumer 1 got message [" + getTextMessage(message) + "]"); + synchronized(_received1) + { + _received1.add(message); + _received1.notify(); + } + } + }); + _session2 = _connection.createSession(false, Session.AUTO_ACKNOWLEDGE); + _session2.createConsumer(_destination2).setMessageListener(new MessageListener() + { + public void onMessage(Message message) + { + _log.debug("consumer 2 got message [" + getTextMessage(message) + "]"); + synchronized(_received2) + { + _received2.add(message); + _received2.notify(); + } + } + }); + + _connection.start(); + } + + private String getTextMessage(Message message) + { + TextMessage tm = (TextMessage) message; + try + { + return tm.getText(); + } + catch (JMSException e) + { + return "oops " + e; + } + } + + @After + public void closeConnection() throws JMSException + { + if (_connection != null) + { + System.out.println(">>>>>>>>>>>>>>.. closing"); + _connection.close(); + } + + stopVmBroker(); + } + + @Test + public void testWithoutExceptionListener() throws Exception + { + test(); + } + + @Test + public void testWithExceptionListener() throws Exception + { + _connection.setExceptionListener(new ExceptionListener() + { + public void onException(JMSException jmsException) + { + _log.error("onException - ", jmsException); + } + }); + + test(); + } + + public void test() throws Exception + { + // Check both sessions are ok. + sendAndWait(_session1, _destination1, "first", _received1, 1); + sendAndWait(_session2, _destination2, "second", _received2, 1); + assertEquals(1, _received1.size()); + assertEquals(1, _received2.size()); + + // Now send message to incorrect destination on session 1. + Destination destination = new AMQQueue("incorrect"); + send(_session1, destination, "third"); // no point waiting as message will never be received. + + // Ensure both sessions are still ok. + // Send a bunch of messages as this give time for the sessions to be erroneously closed. + final int num = 300; + for (int i = 0; i < num; ++i) + { + send(_session1, _destination1, "" + i); + send(_session2, _destination2, "" + i); + } + waitFor(_received1, num + 1); + waitFor(_received2, num + 1); + + // Note that the third message is never received as it is sent to an incorrect destination. + assertEquals(num + 1, _received1.size()); + assertEquals(num + 1, _received2.size()); + } + + private void sendAndWait(Session session, Destination destination, String message, List received, int count) + throws JMSException, InterruptedException + { + send(session, destination, message); + waitFor(received, count); + } + + private void send(Session session, Destination destination, String message) throws JMSException + { + _log.debug("sending message " + message); + MessageProducer producer1 = session.createProducer(destination); + producer1.send(session.createTextMessage(message)); + } + + private void waitFor(List received, int count) throws InterruptedException + { + synchronized(received) + { + while (received.size() < count) + { + received.wait(); + } + } + } + + private static String randomize(String in) + { + return in + System.currentTimeMillis(); + } + + /** + * For Junit 3 compatibility. + */ + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(ChannelCloseOkTest.class); + } + + public static void main(String[] args) + { + org.junit.runner.JUnitCore.main(ChannelCloseOkTest.class.getName()); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/channelclose/UnitTests.java b/java/client/test/src/org/apache/qpid/test/unit/client/channelclose/UnitTests.java new file mode 100644 index 0000000000..8f97c723f7 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/channelclose/UnitTests.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.test.unit.client.channelclose; + +import junit.framework.JUnit4TestAdapter; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + ChannelCloseOkTest.class + }) +public class UnitTests +{ + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(UnitTests.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/connection/ConnectionTest.java b/java/client/test/src/org/apache/qpid/test/unit/client/connection/ConnectionTest.java new file mode 100644 index 0000000000..d88ca8322d --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/connection/ConnectionTest.java @@ -0,0 +1,135 @@ +/* + * + * 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.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; + +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() + { + try + { + Connection connection = new AMQConnection(_broker, "guest", "guest", + "fred", "/test"); + } + catch (Exception e) + { + Assert.fail("Connection to " + _broker + " should succeed. Reason: " + e); + } + } + + @Test + public void passwordFailureConnection() throws Exception + { + try + { + 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. Excpected 'AMQAuthenticationException' got: " + amqe); + } + } + } + + @Test + public void connectionFailure() throws Exception + { + try + { + 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. Excpected 'AMQConnectionException' got: " + amqe); + } + } + } + + @Test + public void unresolvedHostFailure() throws Exception + { + try + { + 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. Excpected 'AMQUnresolvedAddressException' got: " + amqe); + } + } + } + + /** + * For Junit 3 compatibility. + */ + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(ConnectionTest.class); + } + +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/connection/TestManyConnections.java b/java/client/test/src/org/apache/qpid/test/unit/client/connection/TestManyConnections.java new file mode 100644 index 0000000000..700645f242 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/connection/TestManyConnections.java @@ -0,0 +1,99 @@ +/* + * + * 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.connection; + +import junit.framework.JUnit4TestAdapter; +import org.apache.qpid.AMQException; +import org.apache.qpid.url.URLSyntaxException; +import org.apache.qpid.client.AMQConnection; +import org.apache.log4j.Logger; +import org.junit.Test; + +public class TestManyConnections +{ + private static final Logger _log = Logger.getLogger(TestManyConnections.class); + + private AMQConnection[] _connections; + + private void createConnection(int index, String brokerHosts, String clientID, String username, String password, + String vpath) throws AMQException, URLSyntaxException + { + _connections[index] = new AMQConnection(brokerHosts, username, password, + clientID, vpath); + } + + private void createConnections(int count) throws AMQException, URLSyntaxException + { + _connections = new AMQConnection[count]; + long startTime = System.currentTimeMillis(); + for (int i = 0; i < count; i++) + { + createConnection(i, "vm://:1", "myClient" + i, "guest", "guest", "/test"); + } + long endTime = System.currentTimeMillis(); + _log.info("Time to create " + count + " connections: " + (endTime - startTime) + + "ms"); + } + + @Test + public void create10Connections() throws AMQException, URLSyntaxException + { + createConnections(10); + } + + @Test + public void create50Connections() throws AMQException, URLSyntaxException + { + createConnections(50); + } + + @Test + public void create100Connections() throws AMQException, URLSyntaxException + { + createConnections(100); + } + + @Test + public void create250Connections() throws AMQException, URLSyntaxException + { + createConnections(250); + } + + @Test + public void create500Connections() throws AMQException, URLSyntaxException + { + createConnections(500); + } + + @Test + public void create1000Connections() throws AMQException, URLSyntaxException + { + createConnections(1000); + } + + @Test + public void create5000Connections() throws AMQException, URLSyntaxException + { + createConnections(5000); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(TestManyConnections.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java b/java/client/test/src/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java new file mode 100644 index 0000000000..d9e01204bc --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/connectionurl/ConnectionURLTest.java @@ -0,0 +1,455 @@ +/* + * + * 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.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; +import junit.framework.JUnit4TestAdapter; + +public class ConnectionURLTest +{ + + @Test + public void failoverURL() throws URLSyntaxException + { + String url = "amqp://ritchiem:bob@/temp?brokerlist='tcp://localhost:5672;tcp://fancyserver:3000/',failover='roundrobin'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + Assert.assertTrue(connectionurl.getFailoverMethod().equals("roundrobin")); + Assert.assertTrue(connectionurl.getUsername().equals("ritchiem")); + Assert.assertTrue(connectionurl.getPassword().equals("bob")); + Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + + Assert.assertTrue(connectionurl.getBrokerCount() == 2); + + BrokerDetails service = connectionurl.getBrokerDetails(0); + + Assert.assertTrue(service.getTransport().equals("tcp")); + Assert.assertTrue(service.getHost().equals("localhost")); + Assert.assertTrue(service.getPort() == 5672); + + service = connectionurl.getBrokerDetails(1); + + Assert.assertTrue(service.getTransport().equals("tcp")); + Assert.assertTrue(service.getHost().equals("fancyserver")); + Assert.assertTrue(service.getPort() == 3000); + + } + + @Test + public void singleTransportUsernamePasswordURL() throws URLSyntaxException + { + String url = "amqp://ritchiem:bob@/temp?brokerlist='tcp://localhost:5672'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + Assert.assertTrue(connectionurl.getFailoverMethod() == null); + Assert.assertTrue(connectionurl.getUsername().equals("ritchiem")); + Assert.assertTrue(connectionurl.getPassword().equals("bob")); + Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + + Assert.assertTrue(connectionurl.getBrokerCount() == 1); + + BrokerDetails service = connectionurl.getBrokerDetails(0); + + Assert.assertTrue(service.getTransport().equals("tcp")); + Assert.assertTrue(service.getHost().equals("localhost")); + Assert.assertTrue(service.getPort() == 5672); + } + + @Test + public void singleTransportUsernameBlankPasswordURL() throws URLSyntaxException + { + String url = "amqp://ritchiem:@/temp?brokerlist='tcp://localhost:5672'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + Assert.assertTrue(connectionurl.getFailoverMethod() == null); + Assert.assertTrue(connectionurl.getUsername().equals("ritchiem")); + Assert.assertTrue(connectionurl.getPassword().equals("")); + Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + + Assert.assertTrue(connectionurl.getBrokerCount() == 1); + + BrokerDetails service = connectionurl.getBrokerDetails(0); + + Assert.assertTrue(service.getTransport().equals("tcp")); + Assert.assertTrue(service.getHost().equals("localhost")); + Assert.assertTrue(service.getPort() == 5672); + } + + @Test + public void failedURLNullPassword() + { + String url = "amqp://ritchiem@/temp?brokerlist='tcp://localhost:5672'"; + + try + { + new AMQConnectionURL(url); + Assert.fail("URL has null password"); + } + catch (URLSyntaxException e) + { + Assert.assertTrue(e.getReason().equals("Null password in user information not allowed.")); + Assert.assertTrue(e.getIndex() == 7); + } + } + + + @Test + public void singleTransportURL() throws URLSyntaxException + { + String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + + Assert.assertTrue(connectionurl.getFailoverMethod() == null); + Assert.assertTrue(connectionurl.getUsername().equals("guest")); + Assert.assertTrue(connectionurl.getPassword().equals("guest")); + Assert.assertTrue(connectionurl.getVirtualHost().equals("/test")); + + + Assert.assertTrue(connectionurl.getBrokerCount() == 1); + + + BrokerDetails service = connectionurl.getBrokerDetails(0); + + Assert.assertTrue(service.getTransport().equals("tcp")); + Assert.assertTrue(service.getHost().equals("localhost")); + Assert.assertTrue(service.getPort() == 5672); + } + + @Test + public void singleTransportWithClientURLURL() throws URLSyntaxException + { + String url = "amqp://guest:guest@clientname/temp?brokerlist='tcp://localhost:5672'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + + Assert.assertTrue(connectionurl.getFailoverMethod() == null); + Assert.assertTrue(connectionurl.getUsername().equals("guest")); + Assert.assertTrue(connectionurl.getPassword().equals("guest")); + Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + Assert.assertTrue(connectionurl.getClientName().equals("clientname")); + + + Assert.assertTrue(connectionurl.getBrokerCount() == 1); + + + BrokerDetails service = connectionurl.getBrokerDetails(0); + + Assert.assertTrue(service.getTransport().equals("tcp")); + Assert.assertTrue(service.getHost().equals("localhost")); + Assert.assertTrue(service.getPort() == 5672); + } + + @Test + public void singleTransport1OptionURL() throws URLSyntaxException + { + String url = "amqp://guest:guest@/temp?brokerlist='tcp://localhost:5672',routingkey='jim'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + Assert.assertTrue(connectionurl.getFailoverMethod() == null); + Assert.assertTrue(connectionurl.getUsername().equals("guest")); + Assert.assertTrue(connectionurl.getPassword().equals("guest")); + Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + + + Assert.assertTrue(connectionurl.getBrokerCount() == 1); + + BrokerDetails service = connectionurl.getBrokerDetails(0); + + Assert.assertTrue(service.getTransport().equals("tcp")); + + Assert.assertTrue(service.getHost().equals("localhost")); + Assert.assertTrue(service.getPort() == 5672); + Assert.assertTrue(connectionurl.getOption("routingkey").equals("jim")); + } + + @Test + public void singleTransportDefaultedBroker() throws URLSyntaxException + { + String url = "amqp://guest:guest@/temp?brokerlist='localhost'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + Assert.assertTrue(connectionurl.getFailoverMethod() == null); + Assert.assertTrue(connectionurl.getUsername().equals("guest")); + Assert.assertTrue(connectionurl.getPassword().equals("guest")); + Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + + + Assert.assertTrue(connectionurl.getBrokerCount() == 1); + + BrokerDetails service = connectionurl.getBrokerDetails(0); + + Assert.assertTrue(service.getTransport().equals("tcp")); + + Assert.assertTrue(service.getHost().equals("localhost")); + Assert.assertTrue(service.getPort() == 5672); + } + + + @Test + public void singleTransportMultiOptionURL() throws URLSyntaxException + { + String url = "amqp://guest:guest@/temp?brokerlist='tcp://localhost:5672',routingkey='jim',timeout='200',immediatedelivery='true'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + Assert.assertTrue(connectionurl.getFailoverMethod() == null); + Assert.assertTrue(connectionurl.getUsername().equals("guest")); + Assert.assertTrue(connectionurl.getPassword().equals("guest")); + Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + + Assert.assertTrue(connectionurl.getBrokerCount() == 1); + + BrokerDetails service = connectionurl.getBrokerDetails(0); + + Assert.assertTrue(service.getTransport().equals("tcp")); + + Assert.assertTrue(service.getHost().equals("localhost")); + Assert.assertTrue(service.getPort() == 5672); + + Assert.assertTrue(connectionurl.getOption("routingkey").equals("jim")); + Assert.assertTrue(connectionurl.getOption("timeout").equals("200")); + Assert.assertTrue(connectionurl.getOption("immediatedelivery").equals("true")); + } + + @Test + public void singlevmURL() throws URLSyntaxException + { + String url = "amqp://guest:guest@/messages?brokerlist='vm://:2'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + Assert.assertTrue(connectionurl.getFailoverMethod() == null); + Assert.assertTrue(connectionurl.getUsername().equals("guest")); + Assert.assertTrue(connectionurl.getPassword().equals("guest")); + Assert.assertTrue(connectionurl.getVirtualHost().equals("/messages")); + + Assert.assertTrue(connectionurl.getBrokerCount() == 1); + + BrokerDetails service = connectionurl.getBrokerDetails(0); + + Assert.assertTrue(service.getTransport().equals("vm")); + Assert.assertTrue(service.getHost().equals("")); + Assert.assertTrue(service.getPort() == 2); + + } + + @Test + public void failoverVMURL() throws URLSyntaxException + { + String url = "amqp://ritchiem:bob@/temp?brokerlist='vm://:2;vm://:3',failover='roundrobin'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + Assert.assertTrue(connectionurl.getFailoverMethod().equals("roundrobin")); + Assert.assertTrue(connectionurl.getUsername().equals("ritchiem")); + Assert.assertTrue(connectionurl.getPassword().equals("bob")); + Assert.assertTrue(connectionurl.getVirtualHost().equals("/temp")); + + Assert.assertTrue(connectionurl.getBrokerCount() == 2); + + BrokerDetails service = connectionurl.getBrokerDetails(0); + + Assert.assertTrue(service.getTransport().equals("vm")); + Assert.assertTrue(service.getHost().equals("")); + Assert.assertTrue(service.getPort() == 2); + + service = connectionurl.getBrokerDetails(1); + Assert.assertTrue(service.getTransport().equals("vm")); + Assert.assertTrue(service.getHost().equals("")); + Assert.assertTrue(service.getPort() == 3); + } + + + @Test + public void noVirtualHostURL() + { + String url = "amqp://user@?brokerlist='tcp://localhost:5672'"; + + try + { + new AMQConnectionURL(url); + Assert.fail("URL has no virtual host should not parse"); + } + catch (URLSyntaxException e) + { + // This should occur. + } + } + + @Test + public void noClientID() throws URLSyntaxException + { + String url = "amqp://user:@/test?brokerlist='tcp://localhost:5672'"; + + ConnectionURL connectionurl = new AMQConnectionURL(url); + + Assert.assertTrue(connectionurl.getUsername().equals("user")); + Assert.assertTrue(connectionurl.getPassword().equals("")); + Assert.assertTrue(connectionurl.getVirtualHost().equals("/test")); + + Assert.assertTrue(connectionurl.getBrokerCount() == 1); + } + + @Test + public void wrongOptionSeperatorInBroker() + { + String url = "amqp://user:@/test?brokerlist='tcp://localhost:5672+option='value''"; + + try + { + 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 " + version + " Connection is:" + connection); + } + } + catch (URLSyntaxException urise) + { + Assert.assertTrue(urise.getReason().equals("Illegal character in port number")); + } + + } + + @Test + public void wrongOptionSeperatorInOptions() + { + String url = "amqp://guest:guest@/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'+failover='roundrobin'"; + try + { + new AMQConnectionURL(url); + Assert.fail("URL Should not parse"); + } + catch (URLSyntaxException urise) + { + Assert.assertTrue(urise.getReason().equals("Unterminated option. Possible illegal option separator:'+'")); + } + + } + + @Test + public void transportsDefaultToTCP() throws URLSyntaxException + { + String url = "amqp://guest:guest@/test?brokerlist='localhost:5672;myhost:5673'&failover='roundrobin'"; + + AMQConnectionURL connection = new AMQConnectionURL(url); + + BrokerDetails broker = connection.getBrokerDetails(0); + Assert.assertTrue(broker.getTransport().equals("tcp")); + + broker = connection.getBrokerDetails(1); + Assert.assertTrue(broker.getTransport().equals("tcp")); + } + + @Test + public void noUserDetailsProvidedWithClientID() + + { + String url = "amqp://clientID/test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'"; + try + { + new AMQConnectionURL(url); + Assert.fail("URL Should not parse"); + } + catch (URLSyntaxException urise) + { + Assert.assertTrue(urise.getMessage().startsWith("User information not found on url")); + } + + } + + @Test + public void noUserDetailsProvidedNOClientID() + + { + String url = "amqp:///test?brokerlist='tcp://localhost:5672;tcp://localhost:5673'"; + try + { + new AMQConnectionURL(url); + Assert.fail("URL Should not parse"); + } + catch (URLSyntaxException urise) + { + Assert.assertTrue(urise.getMessage().startsWith("User information not found on url")); + } + + } + + @Test + public void checkVirtualhostFormat() throws URLSyntaxException + { + String url = "amqp://guest:guest@/t.-_+!=:?brokerlist='tcp://localhost:5672'"; + + AMQConnectionURL connection = new AMQConnectionURL(url); + Assert.assertTrue(connection.getVirtualHost().equals("/t.-_+!=:")); + } + + @Test + public void checkDefaultPort() throws URLSyntaxException + { + String url = "amqp://guest:guest@/test=:?brokerlist='tcp://localhost'"; + + AMQConnectionURL connection = new AMQConnectionURL(url); + + BrokerDetails broker = connection.getBrokerDetails(0); + Assert.assertTrue(broker.getPort() == AMQBrokerDetails.DEFAULT_PORT); + + } + + @Test + public void checkMissingFinalQuote() throws URLSyntaxException + { + String url = "amqp://guest:guest@id/test" + "?brokerlist='tcp://localhost:5672"; + + try + { + new AMQConnectionURL(url); + } + catch (URLSyntaxException e) + { + Assert.assertEquals(e.getMessage(), "Unterminated option at index 32: brokerlist='tcp://localhost:5672"); + } + + + } + + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(ConnectionURLTest.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/connectionurl/UnitTests.java b/java/client/test/src/org/apache/qpid/test/unit/client/connectionurl/UnitTests.java new file mode 100644 index 0000000000..06995c9de3 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/connectionurl/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.client.connectionurl; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import junit.framework.JUnit4TestAdapter; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ConnectionURLTest.class}) +public class UnitTests +{ + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(org.apache.qpid.test.unit.client.connectionurl.UnitTests.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java b/java/client/test/src/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java new file mode 100644 index 0000000000..fbb6920503 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/destinationurl/DestinationURLTest.java @@ -0,0 +1,150 @@ +/* + * + * 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.destinationurl; + +import org.junit.Test; +import org.junit.Assert; +import org.apache.qpid.url.AMQBindingURL; +import org.apache.qpid.url.URLSyntaxException; +import org.apache.qpid.exchange.ExchangeDefaults; +import junit.framework.JUnit4TestAdapter; + +public class DestinationURLTest +{ + @Test + public void fullURL() throws URLSyntaxException + { + + String url = "exchange.Class://exchangeName/Destination/Queue"; + + AMQBindingURL dest = new AMQBindingURL(url); + + Assert.assertTrue(url.equals(dest.toString())); + + Assert.assertTrue(dest.getExchangeClass().equals("exchange.Class")); + Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); + Assert.assertTrue(dest.getDestinationName().equals("Destination")); + Assert.assertTrue(dest.getQueueName().equals("Queue")); + } + + @Test + public void queue() throws URLSyntaxException + { + + String url = "exchangeClass://exchangeName//Queue"; + + AMQBindingURL dest = new AMQBindingURL(url); + + Assert.assertTrue(url.equals(dest.toString())); + + Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); + Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); + Assert.assertTrue(dest.getDestinationName().equals("")); + Assert.assertTrue(dest.getQueueName().equals("Queue")); + } + + @Test + public void queueWithOption() throws URLSyntaxException + { + + String url = "exchangeClass://exchangeName//Queue?option='value'"; + + AMQBindingURL dest = new AMQBindingURL(url); + + Assert.assertTrue(url.equals(dest.toString())); + + Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); + Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); + Assert.assertTrue(dest.getDestinationName().equals("")); + Assert.assertTrue(dest.getQueueName().equals("Queue")); + Assert.assertTrue(dest.getOption("option").equals("value")); + } + + + @Test + public void destination() throws URLSyntaxException + { + + String url = "exchangeClass://exchangeName/Destination/"; + + AMQBindingURL dest = new AMQBindingURL(url); + + Assert.assertTrue(url.equals(dest.toString())); + + Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); + Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); + Assert.assertTrue(dest.getDestinationName().equals("Destination")); + Assert.assertTrue(dest.getQueueName().equals("")); + } + + @Test + public void destinationWithOption() throws URLSyntaxException + { + + String url = "exchangeClass://exchangeName/Destination/?option='value'"; + + AMQBindingURL dest = new AMQBindingURL(url); + + Assert.assertTrue(url.equals(dest.toString())); + + Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); + Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); + Assert.assertTrue(dest.getDestinationName().equals("Destination")); + Assert.assertTrue(dest.getQueueName().equals("")); + + Assert.assertTrue(dest.getOption("option").equals("value")); + } + + @Test + public void destinationWithMultiOption() throws URLSyntaxException + { + + String url = "exchangeClass://exchangeName/Destination/?option='value',option2='value2'"; + + AMQBindingURL dest = new AMQBindingURL(url); + + Assert.assertTrue(dest.getExchangeClass().equals("exchangeClass")); + Assert.assertTrue(dest.getExchangeName().equals("exchangeName")); + Assert.assertTrue(dest.getDestinationName().equals("Destination")); + Assert.assertTrue(dest.getQueueName().equals("")); + + Assert.assertTrue(dest.getOption("option").equals("value")); + Assert.assertTrue(dest.getOption("option2").equals("value2")); + } + + @Test + public void destinationWithNoExchangeDefaultsToDirect() throws URLSyntaxException + { + + String url = "IBMPerfQueue1?durable='true'"; + + AMQBindingURL dest = new AMQBindingURL(url); + + Assert.assertTrue(dest.getExchangeClass().equals(ExchangeDefaults.DIRECT_EXCHANGE_CLASS)); + Assert.assertTrue(dest.getExchangeName().equals(ExchangeDefaults.DIRECT_EXCHANGE_NAME)); + Assert.assertTrue(dest.getDestinationName().equals("")); + Assert.assertTrue(dest.getQueueName().equals("IBMPerfQueue1")); + + Assert.assertTrue(dest.getOption("durable").equals("true")); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(DestinationURLTest.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/destinationurl/UnitTests.java b/java/client/test/src/org/apache/qpid/test/unit/client/destinationurl/UnitTests.java new file mode 100644 index 0000000000..12c6813f2a --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/destinationurl/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.client.destinationurl; + +import org.junit.runner.RunWith; +import org.junit.runners.Suite; +import junit.framework.JUnit4TestAdapter; + +@RunWith(Suite.class) +@Suite.SuiteClasses({DestinationURLTest.class}) +public class UnitTests +{ + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(UnitTests.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/Client.java b/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/Client.java new file mode 100644 index 0000000000..d1384e3c05 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/Client.java @@ -0,0 +1,106 @@ +/* + * + * 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.forwardall; + +import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.client.AMQQueue; +import org.apache.qpid.client.AMQSession; + +import javax.jms.Message; +import javax.jms.MessageListener; + +/** + * Declare a private temporary response queue, + * send a message to amq.direct with a well known routing key with the + * private response queue as the reply-to destination + * consume responses. + */ +public class Client implements MessageListener +{ + private final AMQConnection _connection; + private final AMQSession _session; + private final int _expected; + private int _count; + + Client(String broker, int expected) throws Exception + { + this(connect(broker), expected); + } + + Client(AMQConnection connection, int expected) throws Exception + { + _connection = connection; + _expected = expected; + _session = (AMQSession) _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); + AMQQueue response = new AMQQueue("ResponseQueue", true); + _session.createConsumer(response).setMessageListener(this); + _connection.start(); + AMQQueue service = new SpecialQueue("ServiceQueue"); + Message request = _session.createTextMessage("Request!"); + request.setJMSReplyTo(response); + _session.createProducer(service).send(request); + } + + void shutdownWhenComplete() throws Exception + { + waitUntilComplete(); + _connection.close(); + } + + public void onMessage(Message response) + { + System.out.println("Received " + (++_count) + " of " + _expected + " responses."); + if(_count == _expected) + { + synchronized(this) + { + notifyAll(); + } + } + } + + synchronized void waitUntilComplete() throws InterruptedException + { + while(_count < _expected) + { + wait(); + } + } + + static AMQConnection connect(String broker) throws Exception + { + return new AMQConnection(broker, "guest", "guest", "Client" + System.currentTimeMillis(), "/test_path"); + } + + public static void main(String[] argv) throws Exception + { + final String connectionString; + final int expected; + if (argv.length == 0) { + connectionString = "localhost:5672"; + expected = 100; + } + else + { + connectionString = argv[0]; + expected = Integer.parseInt(argv[1]); + } + + new Client(connect(connectionString), expected).shutdownWhenComplete(); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java b/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java new file mode 100644 index 0000000000..4620fe13b0 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/CombinedTest.java @@ -0,0 +1,72 @@ +/* + * + * 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.forwardall; + +import junit.framework.JUnit4TestAdapter; +import org.junit.Test; +import org.junit.Before; +import org.junit.Assert; +import org.junit.After; +import org.apache.qpid.client.transport.TransportConnection; +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 CombinedTest +{ + + @Before + public void createVMBroker() + { + try + { + TransportConnection.createVMBroker(1); + } + catch (AMQVMBrokerCreationException e) + { + Assert.fail("Unable to create broker: " + e); + } + } + + @After + public void stopVmBroker() + { + ServiceCreator.closeAll(); + TransportConnection.killVMBroker(1); + } + + @Test + public void forwardAll() throws Exception + { + int services = 2; + ServiceCreator.start("vm://:1", services); + + System.out.println("Starting client..."); + + new Client("vm://:1", services).shutdownWhenComplete(); + + System.out.println("Completed successfully!"); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(CombinedTest.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/Service.java b/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/Service.java new file mode 100644 index 0000000000..d9cc374835 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/Service.java @@ -0,0 +1,81 @@ +/* + * + * 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.forwardall; + +import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.client.AMQQueue; +import org.apache.qpid.client.AMQSession; + +import javax.jms.Destination; +import javax.jms.Message; +import javax.jms.MessageListener; +import javax.jms.JMSException; + +/** + * Declare a queue and bind it to amq.direct with a 'well known' routing key, + * register a consumer for this queue and send a response to every message received. + */ +public class Service implements MessageListener +{ + private final AMQConnection _connection; + private final AMQSession _session; + + Service(String broker) throws Exception + { + this(connect(broker)); + } + + Service(AMQConnection connection) throws Exception + { + _connection = connection; + AMQQueue queue = new SpecialQueue("ServiceQueue"); + _session = (AMQSession) _connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); + _session.createConsumer(queue).setMessageListener(this); + _connection.start(); + } + + public void onMessage(Message request) + { + try + { + Message response = _session.createTextMessage("Response!"); + Destination replyTo = request.getJMSReplyTo(); + _session.createProducer(replyTo).send(response); + } + catch (Exception e) + { + e.printStackTrace(System.out); + } + } + + public void close() throws JMSException + { + _connection.close(); + } + + static AMQConnection connect(String broker) throws Exception + { + return new AMQConnection(broker, "guest", "guest", "Client" + System.currentTimeMillis(), "/test_path"); + } + +// public static void main(String[] argv) throws Exception +// { +// String broker = argv.length == 0? "localhost:5672" : argv[0]; +// new Service(broker); +// } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/ServiceCreator.java b/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/ServiceCreator.java new file mode 100644 index 0000000000..3995b26e7d --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/ServiceCreator.java @@ -0,0 +1,103 @@ +/* + * + * 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.forwardall; + +import javax.jms.JMSException; + +public class ServiceCreator implements Runnable +{ + private static Thread[] threads; + private static ServiceCreator[] _services; + + private final String broker; + private Service service; + + ServiceCreator(String broker) + { + this.broker = broker; + } + + public void run() + { + try + { + service = new Service(broker); + } + catch (Exception e) + { + e.printStackTrace(System.out); + } + } + + public void closeSC() throws JMSException + { + service.close(); + } + + static void closeAll() + { + for (int i = 0; i < _services.length; i++) + { + try + { + _services[i].closeSC(); + } + catch (JMSException e) + { + //ignore + } + } + } + + static void start(String broker, int services) throws InterruptedException + { + threads = new Thread[services]; + _services = new ServiceCreator[services]; + ServiceCreator runner = new ServiceCreator(broker); + //start services + System.out.println("Starting " + services + " services..."); + for (int i = 0; i < services; i++) + { + threads[i] = new Thread(runner); + _services[i] = runner; + threads[i].start(); + } + + for (int i = 0; i < threads.length; i++) + { + threads[i].join(); + } + } + + public static void main(String[] argv) throws Exception + { + final String connectionString; + final int services; + if (argv.length == 0) + { + connectionString = "localhost:5672"; + services = 100; + } + else + { + connectionString = argv[0]; + services = Integer.parseInt(argv[1]); + } + start(connectionString, services); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/SpecialQueue.java b/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/SpecialQueue.java new file mode 100644 index 0000000000..e4cd3108d4 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/SpecialQueue.java @@ -0,0 +1,41 @@ +/* + * + * 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.forwardall; + +import org.apache.qpid.client.AMQQueue; + +/** + * Queue that allows several private queues to be registered and bound + * to an exchange with the same routing key. + * + */ +class SpecialQueue extends AMQQueue +{ + private final String name; + + SpecialQueue(String name) + { + super(name, true); + this.name = name; + } + + public String getRoutingKey() + { + return name; + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/UnitTests.java b/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/UnitTests.java new file mode 100644 index 0000000000..14fc2e7cd4 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/forwardall/UnitTests.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.test.unit.client.forwardall; + +import junit.framework.JUnit4TestAdapter; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({ + CombinedTest.class +}) +public class UnitTests +{ + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(UnitTests.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/message/BytesMessageTest.java b/java/client/test/src/org/apache/qpid/test/unit/client/message/BytesMessageTest.java new file mode 100644 index 0000000000..8599b6338f --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/message/BytesMessageTest.java @@ -0,0 +1,298 @@ +/* + * + * 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.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 BytesMessageTest +{ + /** + * Tests that on creation a call to getBodyLength() throws an exception + * if null was passed in during creation + */ + @Test(expected=MessageNotReadableException.class) + public void testNotReadableOnCreationWithNull() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.getBodyLength(); + } + + @Test(expected= MessageNotWriteableException.class) + public void testResetMakesReadble() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeInt(10); + bm.reset(); + bm.writeInt(12); + } + + @Test + public void testClearBodyMakesWritable() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeInt(10); + bm.reset(); + bm.clearBody(); + bm.writeInt(10); + } + + @Test + public void testWriteInt() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeInt(10); + bm.reset(); + long len = bm.getBodyLength(); + Assert.assertTrue(len == 4); + int val = bm.readInt(); + Assert.assertTrue(val == 10); + } + + @Test + public void testWriteString() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeUTF("Bananas"); + bm.reset(); + String res = bm.readUTF(); + Assert.assertEquals("Bananas", res); + } + + @Test(expected=NullPointerException.class) + public void testWriteObjectThrowsNPE() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeObject(null); + } + + @Test + public void testReadBoolean() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeBoolean(true); + bm.reset(); + boolean result = bm.readBoolean(); + Assert.assertTrue(result); + } + + @Test(expected=MessageEOFException.class) + public void testEOFByte() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeByte((byte)1); + bm.reset(); + bm.readByte(); + // should throw + bm.readByte(); + } + + @Test(expected=MessageEOFException.class) + public void testEOFUnsignedByte() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeByte((byte)1); + bm.reset(); + bm.readByte(); + // should throw + bm.readUnsignedByte(); + } + + @Test(expected=MessageEOFException.class) + public void testEOFBoolean() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeBoolean(true); + bm.reset(); + bm.readBoolean(); + // should throw + bm.readBoolean(); + } + + @Test(expected=MessageEOFException.class) + public void testEOFChar() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeChar('A'); + bm.reset(); + bm.readChar(); + // should throw + bm.readChar(); + } + + @Test(expected=MessageEOFException.class) + public void testEOFDouble() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeDouble(1.3d); + bm.reset(); + bm.readDouble(); + // should throw + bm.readDouble(); + } + + @Test(expected=MessageEOFException.class) + public void testEOFFloat() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeFloat(1.3f); + bm.reset(); + bm.readFloat(); + // should throw + bm.readFloat(); + } + + @Test(expected=MessageEOFException.class) + public void testEOFInt() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeInt(99); + bm.reset(); + bm.readInt(); + // should throw + bm.readInt(); + } + + @Test(expected=MessageEOFException.class) + public void testEOFLong() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeLong(4L); + bm.reset(); + bm.readLong(); + // should throw + bm.readLong(); + } + + @Test(expected=MessageEOFException.class) + public void testEOFShort() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeShort((short)4); + bm.reset(); + bm.readShort(); + // should throw + bm.readShort(); + } + + @Test(expected=MessageEOFException.class) + public void testEOFUnsignedShort() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeShort((short)4); + bm.reset(); + bm.readUnsignedShort(); + // should throw + bm.readUnsignedShort(); + } + + /** + * Tests that the readBytes() method populates the passed in array + * correctly + * @throws Exception + */ + @Test + public void testReadBytes() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeByte((byte)3); + bm.writeByte((byte)4); + bm.reset(); + byte[] result = new byte[2]; + int count = bm.readBytes(result); + Assert.assertEquals((byte)3, result[0]); + Assert.assertEquals((byte)4, result[1]); + Assert.assertEquals(2, count); + } + + @Test + public void testReadBytesEOF() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeByte((byte)3); + bm.writeByte((byte)4); + bm.reset(); + byte[] result = new byte[2]; + bm.readBytes(result); + int count = bm.readBytes(result); + Assert.assertEquals(-1, count); + } + + @Test + public void testReadBytesWithLargerArray() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeByte((byte)3); + bm.writeByte((byte)4); + bm.reset(); + byte[] result = new byte[3]; + int count = bm.readBytes(result); + Assert.assertEquals(2, count); + Assert.assertEquals((byte)3, result[0]); + Assert.assertEquals((byte)4, result[1]); + Assert.assertEquals((byte)0, result[2]); + } + + @Test + public void testReadBytesWithCount() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.writeByte((byte)3); + bm.writeByte((byte)4); + bm.writeByte((byte)5); + bm.reset(); + byte[] result = new byte[3]; + int count = bm.readBytes(result, 2); + Assert.assertEquals(2, count); + Assert.assertEquals((byte)3, result[0]); + Assert.assertEquals((byte)4, result[1]); + Assert.assertEquals((byte)0, result[2]); + } + + @Test + public void testToBodyString() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + final String testText = "This is a test"; + bm.writeUTF(testText); + bm.reset(); + String result = bm.toBodyString(); + Assert.assertEquals(testText, result); + } + + @Test + public void testToBodyStringWithNull() throws Exception + { + JMSBytesMessage bm = TestMessageHelper.newJMSBytesMessage(); + bm.reset(); + String result = bm.toBodyString(); + Assert.assertNull(result); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(BytesMessageTest.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/message/MessageUnitTests.java b/java/client/test/src/org/apache/qpid/test/unit/client/message/MessageUnitTests.java new file mode 100644 index 0000000000..a0aecee224 --- /dev/null +++ b/java/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/java/client/test/src/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java b/java/client/test/src/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java new file mode 100644 index 0000000000..cd9299122d --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/message/ObjectMessageTest.java @@ -0,0 +1,293 @@ +/* + * + * 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 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; +import javax.jms.Message; +import javax.jms.JMSException; +import javax.jms.ObjectMessage; +import java.io.Serializable; +import java.util.HashMap; +import java.util.ArrayList; + +import junit.framework.JUnit4TestAdapter; + +public class ObjectMessageTest implements MessageListener +{ + private final AMQConnection connection; + private final AMQDestination destination; + private final AMQSession session; + private final Serializable[] data; + private volatile boolean waiting; + 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")); + } + + ObjectMessageTest(AMQConnection connection) throws Exception + { + this(connection, new AMQQueue(randomize("LatencyTest"), true)); + } + + ObjectMessageTest(AMQConnection connection, AMQDestination destination) throws Exception + { + this.connection = connection; + this.destination = destination; + session = (AMQSession) connection.createSession(false, AMQSession.NO_ACKNOWLEDGE); + A a1 = new A(1, "A"); + A a2 = new A(2, "a"); + B b = new B(1, "B"); + C c = new C(); + c.put("A1", a1); + c.put("a2", a2); + c.put("B", b); + c.put("String", "String"); + + data = new Serializable[]{a1, a2, b, c, "Hello World!", new Integer(1001)}; + } + + + public void test() throws Exception + { + try + { + send(); + waitUntilReceived(data.length); + check(); + System.out.println("All " + data.length + " items matched."); + } + finally + { + close(); + } + } + + private void send() throws Exception + { + //set up a consumer + session.createConsumer(destination).setMessageListener(this); + connection.start(); + + //create a publisher + MessageProducer producer = session.createProducer(destination, false, false, true); + + + for (int i = 0; i < data.length; i++) + { + ObjectMessage msg; + if (i % 2 == 0) + { + msg = session.createObjectMessage(data[i]); + } + else + { + msg = session.createObjectMessage(); + msg.setObject(data[i]); + } + producer.send(msg); + } + } + + public void check() throws Exception + { + Object[] actual = (Object[]) items.toArray(); + if (actual.length != data.length) + { + throw new Exception("Expected " + data.length + " objects, got " + actual.length); + } + for (int i = 0; i < data.length; i++) + { + if (actual[i] instanceof Exception) + { + throw new Exception("Error on receive of " + data[i], ((Exception) actual[i])); + } + if (actual[i] == null) + { + throw new Exception("Expected " + data[i] + " got null"); + } + if (!data[i].equals(actual[i])) + { + throw new Exception("Expected " + data[i] + " got " + actual[i]); + } + } + } + + + private void close() throws Exception + { + session.close(); + connection.close(); + } + + private synchronized void waitUntilReceived(int count) throws InterruptedException + { + waiting = true; + while (received < count) + { + wait(); + } + waiting = false; + } + + public void onMessage(Message message) + { + received++; + try + { + if (message instanceof ObjectMessage) + { + items.add(((ObjectMessage) message).getObject()); + } + else + { + System.out.println("ERROR: Got " + message.getClass().getName() + " not ObjectMessage"); + items.add(message); + } + } + catch (JMSException e) + { + e.printStackTrace(); + items.add(e); + } + + if (waiting) + { + synchronized(this) + { + notify(); + } + } + } + + + @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)) + { + System.out.println("Usage: "); + } + new ObjectMessageTest(broker).test(); + } + + private static class A implements Serializable + { + private String sValue; + private int iValue; + + A(int i, String s) + { + sValue = s; + iValue = i; + } + + public int hashCode() + { + return iValue; + } + + public boolean equals(Object o) + { + return o instanceof A && equals((A) o); + } + + protected boolean equals(A a) + { + return areEqual(a.sValue, sValue) && a.iValue == iValue; + } + } + + private static class B extends A + { + private long time; + + B(int i, String s) + { + super(i, s); + time = System.currentTimeMillis(); + } + + protected boolean equals(A a) + { + return super.equals(a) && a instanceof B && time == ((B) a).time; + } + } + + private static class C extends HashMap implements Serializable + { + } + + private static boolean areEqual(Object a, Object b) + { + return a == null ? b == null : a.equals(b); + } + + private static String randomize(String in) + { + return in + System.currentTimeMillis(); + } + +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/message/TextMessageTest.java b/java/client/test/src/org/apache/qpid/test/unit/client/message/TextMessageTest.java new file mode 100644 index 0000000000..e5768b51b3 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/message/TextMessageTest.java @@ -0,0 +1,53 @@ +/* + * + * 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.Test; +import org.junit.Assert; +import org.apache.qpid.client.message.TestMessageHelper; +import org.apache.qpid.client.message.JMSTextMessage; + +public class TextMessageTest +{ + @Test + public void testTextOnConstruction() throws Exception + { + JMSTextMessage tm = TestMessageHelper.newJMSTextMessage(); + tm.setText("pies"); + String val = tm.getText(); + Assert.assertEquals(val, "pies"); + } + + @Test + public void testClearBody() throws Exception + { + JMSTextMessage tm = TestMessageHelper.newJMSTextMessage(); + tm.setText("pies"); + tm.clearBody(); + String val = tm.getText(); + Assert.assertNull(val); + tm.setText("Banana"); + val = tm.getText(); + Assert.assertEquals(val, "Banana"); + } + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(TextMessageTest.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java b/java/client/test/src/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java new file mode 100644 index 0000000000..7134abc1f8 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/protocol/AMQProtocolSessionTest.java @@ -0,0 +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.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/java/client/test/src/org/apache/qpid/test/unit/client/protocol/TestIoSession.java b/java/client/test/src/org/apache/qpid/test/unit/client/protocol/TestIoSession.java new file mode 100644 index 0000000000..7a54a7039c --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/client/protocol/TestIoSession.java @@ -0,0 +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.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/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java b/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Bind.java new file mode 100644 index 0000000000..a867a6d6e3 --- /dev/null +++ b/java/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. + *

+ * 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/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java b/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/JNDIReferenceableTest.java new file mode 100644 index 0000000000..aadc154563 --- /dev/null +++ b/java/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. + *

+ * 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/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Lookup.java b/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Lookup.java new file mode 100644 index 0000000000..e2aed5d413 --- /dev/null +++ b/java/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. + *

+ * 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/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Unbind.java b/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/Unbind.java new file mode 100644 index 0000000000..34a1454d8a --- /dev/null +++ b/java/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. + *

+ * 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/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java b/java/client/test/src/org/apache/qpid/test/unit/jndi/referenceabletest/UnitTests.java new file mode 100644 index 0000000000..6dc4d2df0e --- /dev/null +++ b/java/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/java/client/test/src/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java b/java/client/test/src/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java new file mode 100644 index 0000000000..db872e6742 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/topic/DurableSubscriptionTest.java @@ -0,0 +1,157 @@ +/* + * + * 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.topic; + +import junit.framework.JUnit4TestAdapter; +import org.junit.Assert; +import org.junit.Test; +import org.junit.Before; +import org.junit.After; +import org.apache.qpid.AMQException; +import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; +import org.apache.qpid.url.URLSyntaxException; +import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.client.AMQSession; +import org.apache.qpid.client.AMQTopic; +import org.apache.qpid.client.transport.TransportConnection; + +import javax.jms.JMSException; +import javax.jms.Message; +import javax.jms.MessageConsumer; +import javax.jms.MessageProducer; +import javax.jms.Session; +import javax.jms.TextMessage; +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 + { + AMQTopic topic = new AMQTopic("MyTopic"); + AMQConnection con = new AMQConnection("vm://:1", "guest", "guest", "test", "/test"); + Session session1 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE); + MessageConsumer consumer1 = session1.createConsumer(topic); + MessageProducer producer = session1.createProducer(topic); + + Session session2 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE); + TopicSubscriber consumer2 = session2.createDurableSubscriber(topic, "MySubscription"); + + con.start(); + + producer.send(session1.createTextMessage("A")); + + Message msg; + msg = consumer1.receive(); + Assert.assertEquals("A", ((TextMessage) msg).getText()); + msg = consumer1.receive(1000); + Assert.assertEquals(null, msg); + + msg = consumer2.receive(); + Assert.assertEquals("A", ((TextMessage) msg).getText()); + msg = consumer2.receive(1000); + Assert.assertEquals(null, msg); + + session2.unsubscribe("MySubscription"); + + producer.send(session1.createTextMessage("B")); + + msg = consumer1.receive(); + Assert.assertEquals("B", ((TextMessage) msg).getText()); + msg = consumer1.receive(1000); + Assert.assertEquals(null, msg); + + msg = consumer2.receive(1000); + Assert.assertEquals(null, msg); + + con.close(); + } + + @Test + public void durability() throws AMQException, JMSException, URLSyntaxException + { + AMQTopic topic = new AMQTopic("MyTopic"); + AMQConnection con = new AMQConnection("vm://:1", "guest", "guest", "test", "/test"); + Session session1 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE); + MessageConsumer consumer1 = session1.createConsumer(topic); + MessageProducer producer = session1.createProducer(topic); + + Session session2 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE); + TopicSubscriber consumer2 = session2.createDurableSubscriber(topic, "MySubscription"); + + con.start(); + + producer.send(session1.createTextMessage("A")); + + Message msg; + msg = consumer1.receive(); + Assert.assertEquals("A", ((TextMessage) msg).getText()); + msg = consumer1.receive(1000); + Assert.assertEquals(null, msg); + + msg = consumer2.receive(); + Assert.assertEquals("A", ((TextMessage) msg).getText()); + msg = consumer2.receive(1000); + Assert.assertEquals(null, msg); + + consumer2.close(); + + Session session3 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE); + MessageConsumer consumer3 = session3.createDurableSubscriber(topic, "MySubscription"); + + producer.send(session1.createTextMessage("B")); + + msg = consumer1.receive(); + Assert.assertEquals("B", ((TextMessage) msg).getText()); + msg = consumer1.receive(1000); + Assert.assertEquals(null, msg); + + msg = consumer3.receive(); + Assert.assertEquals("B", ((TextMessage) msg).getText()); + msg = consumer3.receive(1000); + Assert.assertEquals(null, msg); + + con.close(); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(DurableSubscriptionTest.class); + } + +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/transacted/TransactedTest.java b/java/client/test/src/org/apache/qpid/test/unit/transacted/TransactedTest.java new file mode 100644 index 0000000000..2040276469 --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/transacted/TransactedTest.java @@ -0,0 +1,170 @@ +/* + * + * 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.transacted; + +import junit.framework.JUnit4TestAdapter; +import org.apache.qpid.client.AMQConnection; +import org.apache.qpid.client.AMQQueue; +import org.apache.qpid.client.AMQSession; +import org.apache.qpid.client.transport.TransportConnection; +import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; +import org.junit.After; +import static org.junit.Assert.assertEquals; +import static org.junit.Assert.assertTrue; +import org.junit.Before; +import org.junit.Test; +import org.junit.Assert; +import org.junit.BeforeClass; +import org.junit.AfterClass; + +import javax.jms.*; + +public class TransactedTest +{ + private AMQQueue queue1; + private AMQQueue queue2; + + private AMQConnection con; + private Session session; + private MessageConsumer consumer1; + private MessageProducer producer2; + + private AMQConnection prepCon; + private Session prepSession; + private MessageProducer prepProducer1; + + private AMQConnection testCon; + private Session testSession; + private MessageConsumer testConsumer1; + private MessageConsumer testConsumer2; + + + public void createVMBroker() + { + try + { + TransportConnection.createVMBroker(1); + } + catch (AMQVMBrokerCreationException e) + { + Assert.fail("Unable to create broker: " + e); + } + } + + @After + public void stopVmBroker() + { + TransportConnection.killVMBroker(1); + } + + @Before + public void setup() throws Exception + { + createVMBroker(); + queue1 = new AMQQueue("Q1", false); + queue2 = new AMQQueue("Q2", false); + + con = new AMQConnection("vm://:1", "guest", "guest", "TransactedTest", "/test"); + session = con.createSession(true, 0); + consumer1 = session.createConsumer(queue1); + producer2 = session.createProducer(queue2); + con.start(); + + prepCon = new AMQConnection("vm://:1", "guest", "guest", "PrepConnection", "/test"); + prepSession = prepCon.createSession(false, AMQSession.NO_ACKNOWLEDGE); + prepProducer1 = prepSession.createProducer(queue1); + prepCon.start(); + + + //add some messages + prepProducer1.send(prepSession.createTextMessage("A")); + prepProducer1.send(prepSession.createTextMessage("B")); + prepProducer1.send(prepSession.createTextMessage("C")); + + testCon = new AMQConnection("vm://:1", "guest", "guest", "TestConnection", "/test"); + testSession = testCon.createSession(false, AMQSession.NO_ACKNOWLEDGE); + testConsumer1 = testSession.createConsumer(queue1); + testConsumer2 = testSession.createConsumer(queue2); + testCon.start(); + } + + @After + public void shutdown() throws Exception + { + con.close(); + testCon.close(); + prepCon.close(); + } + + @Test + public void commit() throws Exception + { + //send and receive some messages + producer2.send(session.createTextMessage("X")); + producer2.send(session.createTextMessage("Y")); + producer2.send(session.createTextMessage("Z")); + expect("A", consumer1.receive(1000)); + expect("B", consumer1.receive(1000)); + expect("C", consumer1.receive(1000)); + + //commit + session.commit(); + + //ensure sent messages can be received and received messages are gone + expect("X", testConsumer2.receive(1000)); + expect("Y", testConsumer2.receive(1000)); + expect("Z", testConsumer2.receive(1000)); + + assertTrue(null == testConsumer1.receive(1000)); + assertTrue(null == testConsumer2.receive(1000)); + } + + @Test + public void rollback() throws Exception + { + producer2.send(session.createTextMessage("X")); + producer2.send(session.createTextMessage("Y")); + producer2.send(session.createTextMessage("Z")); + expect("A", consumer1.receive(1000)); + expect("B", consumer1.receive(1000)); + expect("C", consumer1.receive(1000)); + + //rollback + session.rollback(); + + //ensure sent messages are not visible and received messages are requeued + expect("A", consumer1.receive(1000)); + expect("B", consumer1.receive(1000)); + expect("C", consumer1.receive(1000)); + + assertTrue(null == testConsumer1.receive(1000)); + assertTrue(null == testConsumer2.receive(1000)); + } + + private void expect(String text, Message msg) throws JMSException + { + assertTrue(msg instanceof TextMessage); + assertEquals(text, ((TextMessage) msg).getText()); + } + + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(TransactedTest.class); + } + +} diff --git a/java/client/test/src/org/apache/qpid/test/unit/transacted/UnitTests.java b/java/client/test/src/org/apache/qpid/test/unit/transacted/UnitTests.java new file mode 100644 index 0000000000..d3a161820f --- /dev/null +++ b/java/client/test/src/org/apache/qpid/test/unit/transacted/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.transacted; + +import junit.framework.JUnit4TestAdapter; +import org.junit.runner.RunWith; +import org.junit.runners.Suite; + +@RunWith(Suite.class) +@Suite.SuiteClasses({TransactedTest.class}) +public class UnitTests +{ + public static junit.framework.Test suite() + { + return new JUnit4TestAdapter(UnitTests.class); + } +} diff --git a/java/client/test/src/org/apache/qpid/topic/DurableSubscriptionTest.java b/java/client/test/src/org/apache/qpid/topic/DurableSubscriptionTest.java deleted file mode 100644 index 0f190c73a9..0000000000 --- a/java/client/test/src/org/apache/qpid/topic/DurableSubscriptionTest.java +++ /dev/null @@ -1,152 +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.topic; - -import junit.framework.JUnit4TestAdapter; -import org.junit.Assert; -import org.junit.Test; -import org.junit.Before; -import org.junit.After; -import org.apache.qpid.AMQException; -import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; -import org.apache.qpid.url.URLSyntaxException; -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQSession; -import org.apache.qpid.client.AMQTopic; -import org.apache.qpid.client.transport.TransportConnection; - -import javax.jms.JMSException; -import javax.jms.Message; -import javax.jms.MessageConsumer; -import javax.jms.MessageProducer; -import javax.jms.Session; -import javax.jms.TextMessage; -import javax.jms.TopicSubscriber; - -public class DurableSubscriptionTest -{ - @Test - public void unsubscribe() throws AMQException, JMSException, URLSyntaxException - { - AMQTopic topic = new AMQTopic("MyTopic"); - AMQConnection con = new AMQConnection("vm://:1", "guest", "guest", "test", "/test"); - Session session1 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE); - MessageConsumer consumer1 = session1.createConsumer(topic); - MessageProducer producer = session1.createProducer(topic); - - 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"); - } - - producer.send(session1.createTextMessage("A")); - - Message msg; - msg = consumer1.receive(); - Assert.assertEquals("A", ((TextMessage) msg).getText()); - msg = consumer1.receive(1000); - Assert.assertEquals(null, msg); - - msg = consumer2.receive(); - Assert.assertEquals("A", ((TextMessage) msg).getText()); - msg = consumer2.receive(1000); - Assert.assertEquals(null, msg); - - session2.unsubscribe("MySubscription"); - - producer.send(session1.createTextMessage("B")); - - msg = consumer1.receive(); - Assert.assertEquals("B", ((TextMessage) msg).getText()); - msg = consumer1.receive(1000); - Assert.assertEquals(null, msg); - - msg = consumer2.receive(1000); - Assert.assertEquals(null, msg); - - con.close(); - } - - @Test - public void durability() throws AMQException, JMSException, URLSyntaxException - { - AMQTopic topic = new AMQTopic("MyTopic"); - AMQConnection con = new AMQConnection("vm://:1", "guest", "guest", "test", "/test"); - Session session1 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE); - MessageConsumer consumer1 = session1.createConsumer(topic); - MessageProducer producer = session1.createProducer(topic); - - Session session2 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE); - TopicSubscriber consumer2 = session2.createDurableSubscriber(topic, "MySubscription"); - - con.start(); - - producer.send(session1.createTextMessage("A")); - - Message msg; - msg = consumer1.receive(); - Assert.assertEquals("A", ((TextMessage) msg).getText()); - msg = consumer1.receive(1000); - Assert.assertEquals(null, msg); - - msg = consumer2.receive(); - Assert.assertEquals("A", ((TextMessage) msg).getText()); - msg = consumer2.receive(1000); - Assert.assertEquals(null, msg); - - consumer2.close(); - - Session session3 = con.createSession(false, AMQSession.NO_ACKNOWLEDGE); - MessageConsumer consumer3 = session3.createDurableSubscriber(topic, "MySubscription"); - - producer.send(session1.createTextMessage("B")); - - msg = consumer1.receive(); - Assert.assertEquals("B", ((TextMessage) msg).getText()); - msg = consumer1.receive(1000); - Assert.assertEquals(null, msg); - - msg = consumer3.receive(); - Assert.assertEquals("B", ((TextMessage) msg).getText()); - msg = consumer3.receive(1000); - Assert.assertEquals(null, msg); - - con.close(); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(DurableSubscriptionTest.class); - } - -} diff --git a/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java b/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java deleted file mode 100644 index 765d3ab168..0000000000 --- a/java/client/test/src/org/apache/qpid/transacted/TransactedTest.java +++ /dev/null @@ -1,170 +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.transacted; - -import junit.framework.JUnit4TestAdapter; -import org.apache.qpid.client.AMQConnection; -import org.apache.qpid.client.AMQQueue; -import org.apache.qpid.client.AMQSession; -import org.apache.qpid.client.transport.TransportConnection; -import org.apache.qpid.client.vmbroker.AMQVMBrokerCreationException; -import org.junit.After; -import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; -import org.junit.Before; -import org.junit.Test; -import org.junit.Assert; -import org.junit.BeforeClass; -import org.junit.AfterClass; - -import javax.jms.*; - -public class TransactedTest -{ - private AMQQueue queue1; - private AMQQueue queue2; - - private AMQConnection con; - private Session session; - private MessageConsumer consumer1; - private MessageProducer producer2; - - private AMQConnection prepCon; - private Session prepSession; - private MessageProducer prepProducer1; - - private AMQConnection testCon; - private Session testSession; - private MessageConsumer testConsumer1; - private MessageConsumer testConsumer2; - - - public void createVMBroker() - { - try - { - TransportConnection.createVMBroker(1); - } - catch (AMQVMBrokerCreationException e) - { - Assert.fail("Unable to create broker: " + e); - } - } - - @After - public void stopVmBroker() - { - TransportConnection.killVMBroker(1); - } - - @Before - public void setup() throws Exception - { - createVMBroker(); - queue1 = new AMQQueue("Q1", false); - queue2 = new AMQQueue("Q2", false); - - con = new AMQConnection("vm://:1", "guest", "guest", "TransactedTest", "/test"); - session = con.createSession(true, 0); - consumer1 = session.createConsumer(queue1); - producer2 = session.createProducer(queue2); - con.start(); - - prepCon = new AMQConnection("vm://:1", "guest", "guest", "PrepConnection", "/test"); - prepSession = prepCon.createSession(false, AMQSession.NO_ACKNOWLEDGE); - prepProducer1 = prepSession.createProducer(queue1); - prepCon.start(); - - - //add some messages - prepProducer1.send(prepSession.createTextMessage("A")); - prepProducer1.send(prepSession.createTextMessage("B")); - prepProducer1.send(prepSession.createTextMessage("C")); - - testCon = new AMQConnection("vm://:1", "guest", "guest", "TestConnection", "/test"); - testSession = testCon.createSession(false, AMQSession.NO_ACKNOWLEDGE); - testConsumer1 = testSession.createConsumer(queue1); - testConsumer2 = testSession.createConsumer(queue2); - testCon.start(); - } - - @After - public void shutdown() throws Exception - { - con.close(); - testCon.close(); - prepCon.close(); - } - - @Test - public void commit() throws Exception - { - //send and receive some messages - producer2.send(session.createTextMessage("X")); - producer2.send(session.createTextMessage("Y")); - producer2.send(session.createTextMessage("Z")); - expect("A", consumer1.receive(1000)); - expect("B", consumer1.receive(1000)); - expect("C", consumer1.receive(1000)); - - //commit - session.commit(); - - //ensure sent messages can be received and received messages are gone - expect("X", testConsumer2.receive(1000)); - expect("Y", testConsumer2.receive(1000)); - expect("Z", testConsumer2.receive(1000)); - - assertTrue(null == testConsumer1.receive(1000)); - assertTrue(null == testConsumer2.receive(1000)); - } - - @Test - public void rollback() throws Exception - { - producer2.send(session.createTextMessage("X")); - producer2.send(session.createTextMessage("Y")); - producer2.send(session.createTextMessage("Z")); - expect("A", consumer1.receive(1000)); - expect("B", consumer1.receive(1000)); - expect("C", consumer1.receive(1000)); - - //rollback - session.rollback(); - - //ensure sent messages are not visible and received messages are requeued - expect("A", consumer1.receive(1000)); - expect("B", consumer1.receive(1000)); - expect("C", consumer1.receive(1000)); - - assertTrue(null == testConsumer1.receive(1000)); - assertTrue(null == testConsumer2.receive(1000)); - } - - private void expect(String text, Message msg) throws JMSException - { - assertTrue(msg instanceof TextMessage); - assertEquals(text, ((TextMessage) msg).getText()); - } - - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(TransactedTest.class); - } - -} diff --git a/java/client/test/src/org/apache/qpid/transacted/UnitTests.java b/java/client/test/src/org/apache/qpid/transacted/UnitTests.java deleted file mode 100644 index 8d43287d6f..0000000000 --- a/java/client/test/src/org/apache/qpid/transacted/UnitTests.java +++ /dev/null @@ -1,32 +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.transacted; - -import junit.framework.JUnit4TestAdapter; -import org.junit.runner.RunWith; -import org.junit.runners.Suite; - -@RunWith(Suite.class) -@Suite.SuiteClasses({TransactedTest.class}) -public class UnitTests -{ - public static junit.framework.Test suite() - { - return new JUnit4TestAdapter(UnitTests.class); - } -} -- cgit v1.2.1