You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@qpid.apache.org by rh...@apache.org on 2006/09/20 00:07:25 UTC
svn commit: r447994 [25/46] - in /incubator/qpid/trunk/qpid: ./ cpp/
cpp/bin/ cpp/broker/ cpp/broker/inc/ cpp/broker/src/ cpp/broker/test/
cpp/client/ cpp/client/inc/ cpp/client/src/ cpp/client/test/ cpp/common/
cpp/common/concurrent/ cpp/common/concur...
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/ObjectMessageTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/ObjectMessageTest.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/ObjectMessageTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/ObjectMessageTest.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,247 @@
+/*
+ *
+ * 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 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;
+
+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] : "localhost:5672";
+ if("-help".equals(broker))
+ {
+ System.out.println("Usage: <broker>");
+ }
+ 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();
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/ObjectMessageTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/TestBytesMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/TestBytesMessage.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/TestBytesMessage.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/TestBytesMessage.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,92 @@
+/*
+ *
+ * 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;
+
+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);
+ }
+
+ public static junit.framework.Test suite()
+ {
+ return new JUnit4TestAdapter(TestBytesMessage.class);
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/TestBytesMessage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/TestTextMessage.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/TestTextMessage.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/TestTextMessage.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/TestTextMessage.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,51 @@
+/*
+ *
+ * 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);
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/TestTextMessage.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/UnitTests.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/UnitTests.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/UnitTests.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/UnitTests.java Tue Sep 19 15:06:50 2006
@@ -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.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);
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/message/UnitTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/testutil/VmOrRemoteTestCase.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/testutil/VmOrRemoteTestCase.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/testutil/VmOrRemoteTestCase.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/testutil/VmOrRemoteTestCase.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,56 @@
+/*
+ *
+ * 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.testutil;
+
+import org.apache.qpid.vmbroker.VmPipeBroker;
+import org.junit.After;
+import org.junit.Before;
+
+public class VmOrRemoteTestCase
+{
+ String _connectionString = "vm:1";
+
+ VmPipeBroker _vmBroker;
+
+ public boolean isVm() {
+ return "vm:1".equals(_connectionString);
+ }
+
+ public void setConnectionString(final String connectionString) {
+ this._connectionString = connectionString;
+ }
+
+ public String getConnectionString()
+ {
+ return _connectionString;
+ }
+
+ @Before
+ public void startVmBroker() throws Exception {
+ if (isVm()) {
+ _vmBroker = new VmPipeBroker();
+ _vmBroker.initialiseBroker();
+ }
+ }
+
+ @After
+ public void stopVmBroker() {
+ _vmBroker.killBroker();
+ }
+
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/client/testutil/VmOrRemoteTestCase.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cluster/Client.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cluster/Client.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cluster/Client.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cluster/Client.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,122 @@
+/*
+ *
+ * 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.cluster;
+
+import org.apache.qpid.client.AMQConnection;
+import org.apache.qpid.client.AMQSession;
+import org.apache.qpid.client.AMQTopic;
+import org.apache.qpid.client.AMQQueue;
+import org.apache.qpid.AMQException;
+import org.apache.qpid.url.URLSyntaxException;
+
+import javax.jms.MessageListener;
+import javax.jms.Message;
+import javax.jms.Session;
+import javax.jms.JMSException;
+import javax.jms.MessageProducer;
+import javax.jms.TextMessage;
+import java.util.Random;
+
+public class Client
+{
+ private final Random random = new Random();
+ private final String name;
+ private final Session session;
+ private final MessageProducer topicProducer;
+ private final MessageProducer queueProducer;
+
+ Client(AMQConnection connection, String name) throws JMSException, InterruptedException
+ {
+ this.name = name;
+ session = connection.createSession(false, AMQSession.NO_ACKNOWLEDGE);
+
+ AMQTopic topic = new AMQTopic("cluster_test_topic");
+ AMQQueue queue = new AMQQueue("cluster_test_queue");
+
+ topicProducer = session.createProducer(topic);
+ queueProducer = session.createProducer(queue);
+
+ //subscribe to a known topic
+ session.createConsumer(topic).setMessageListener(new TopicHandler());
+ //subscribe to a known queue
+ session.createConsumer(queue).setMessageListener(new QueueHandler());
+
+ connection.start();
+
+ while(true)
+ {
+ Thread.sleep(random.nextInt(60000));
+ sendToQueue(name + ":" + randomString(5));
+ }
+ }
+
+ private synchronized void sendToTopic(String message) throws JMSException
+ {
+ topicProducer.send(session.createTextMessage(message));
+ }
+
+ private synchronized void sendToQueue(String message) throws JMSException
+ {
+ queueProducer.send(session.createTextMessage(message));
+ }
+
+ private String randomString(int length){
+ char[] c = new char[length];
+ for(int i = 0; i < length; i++)
+ {
+ c[i] = (char) ('A' + random.nextInt(26));
+ }
+ return new String(c);
+ }
+
+ private class QueueHandler implements MessageListener
+ {
+ public void onMessage(Message message)
+ {
+ try
+ {
+ sendToTopic(((TextMessage) message).getText());
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ private class TopicHandler implements MessageListener
+ {
+ public void onMessage(Message message)
+ {
+ try
+ {
+ System.out.println(((TextMessage) message).getText());
+ }
+ catch (JMSException e)
+ {
+ e.printStackTrace();
+ }
+ }
+ }
+
+ public static void main(String[] argv) throws AMQException, JMSException, InterruptedException, URLSyntaxException
+ {
+ //assume args describe the set of brokers to try
+ new Client(new AMQConnection(argv[0], "guest", "guest", argv[1], "/test"), argv[1]);
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cluster/Client.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/BasicDeliverTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/BasicDeliverTest.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/BasicDeliverTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/BasicDeliverTest.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,257 @@
+/*
+ *
+ * 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.codec;
+
+import org.apache.qpid.framing.*;
+import org.apache.mina.common.*;
+import org.apache.mina.common.support.BaseIoSession;
+import org.apache.mina.filter.codec.ProtocolDecoderOutput;
+import org.apache.mina.filter.codec.ProtocolEncoderOutput;
+
+import java.net.SocketAddress;
+
+/**
+ */
+public class BasicDeliverTest
+{
+ public static void main(String[] argv) throws Exception
+ {
+ BasicDeliverTest test = new BasicDeliverTest();
+
+ //warm up:
+ test.encode(512, 100000);
+
+ //real tests:
+ test.encode(16, 10000, 15);
+ test.encode(32, 10000, 15);
+ test.encode(64, 10000, 15);
+ test.encode(128, 10000, 15);
+ test.encode(256, 10000, 15);
+ test.encode(512, 10000, 15);
+ test.encode(1024, 10000, 15);
+ test.encode(2048, 10000, 15);
+
+ test.decode(16, 10000, 15);
+ test.decode(32, 10000, 15);
+ test.decode(64, 10000, 15);
+ test.decode(128, 10000, 15);
+ test.decode(256, 10000, 15);
+ test.decode(512, 10000, 15);
+ test.decode(1024, 10000, 15);
+ test.decode(2048, 10000, 15);
+ }
+
+ void decode(int size, int count, int iterations) throws Exception
+ {
+ long min = Long.MAX_VALUE;
+ long max = 0;
+ long total = 0;
+ for(int i = 0; i < iterations; i++)
+ {
+ long time = decode(size, count);
+ total += time;
+ if(time < min) min = time;
+ if(time > max) max = time;
+ }
+ System.out.println("Decoded " + count + " messages of " + size +
+ " bytes: avg=" + (total / iterations) + ", min=" + min + ", max=" + max) ;
+ }
+
+
+ long decode(int size, int count) throws Exception
+ {
+ AMQDataBlock block = getDataBlock(size);
+ ByteBuffer data = ByteBuffer.allocate((int) block.getSize()); // XXX: Is cast a problem?
+ block.writePayload(data);
+ data.flip();
+ AMQDecoder decoder = new AMQDecoder(false);
+ long start = System.currentTimeMillis();
+ for(int i = 0; i < count; i++)
+ {
+ decoder.decode(session, data, decoderOutput);
+ data.rewind();
+ }
+ return System.currentTimeMillis() - start;
+ }
+
+ void encode(int size, int count, int iterations) throws Exception
+ {
+ long min = Long.MAX_VALUE;
+ long max = 0;
+ long total = 0;
+ for(int i = 0; i < iterations; i++)
+ {
+ long time = encode(size, count);
+ total += time;
+ if(time < min) min = time;
+ if(time > max) max = time;
+ }
+ System.out.println("Encoded " + count + " messages of " + size +
+ " bytes: avg=" + (total / iterations) + ", min=" + min + ", max=" + max) ;
+ }
+
+ long encode(int size, int count) throws Exception
+ {
+ IoSession session = null;
+ AMQDataBlock block = getDataBlock(size);
+ AMQEncoder encoder = new AMQEncoder();
+ long start = System.currentTimeMillis();
+ for(int i = 0; i < count; i++)
+ {
+ encoder.encode(session, block, encoderOutput);
+ }
+ return System.currentTimeMillis() - start;
+ }
+
+ private final ProtocolEncoderOutput encoderOutput = new ProtocolEncoderOutput(){
+
+ public void write(ByteBuffer byteBuffer)
+ {
+ }
+
+ public void mergeAll()
+ {
+ }
+
+ public WriteFuture flush()
+ {
+ return null;
+ }
+ };
+
+ private final ProtocolDecoderOutput decoderOutput = new ProtocolDecoderOutput(){
+ public void write(Object object)
+ {
+ }
+
+ public void flush()
+ {
+ }
+ };
+
+ private final IoSession session = new BaseIoSession(){
+
+ protected void updateTrafficMask()
+ {
+ //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public IoService getService()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public IoHandler getHandler()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public IoSessionConfig getConfig()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public IoFilterChain getFilterChain()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public TransportType getTransportType()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public SocketAddress getRemoteAddress()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public SocketAddress getLocalAddress()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public SocketAddress getServiceAddress()
+ {
+ return null; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public int getScheduledWriteRequests()
+ {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+
+ public int getScheduledWriteBytes()
+ {
+ return 0; //To change body of implemented methods use File | Settings | File Templates.
+ }
+ };
+
+ private static final char[] DATA = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ".toCharArray();
+
+ static CompositeAMQDataBlock getDataBlock(int size)
+ {
+ //create a frame representing message delivery
+ AMQFrame[] frames = new AMQFrame[3];
+ frames[0] = wrapBody( createBasicDeliverBody() );
+ frames[1] = wrapBody( createContentHeaderBody() );
+ frames[2] = wrapBody( createContentBody(size) );
+
+ return new CompositeAMQDataBlock(frames);
+ }
+
+ static AMQFrame wrapBody(AMQBody body)
+ {
+ AMQFrame frame = new AMQFrame();
+ frame.bodyFrame = body;
+ frame.channel = 1;
+
+ return frame;
+ }
+
+ static ContentBody createContentBody(int size)
+ {
+ ContentBody body = new ContentBody();
+ body.payload = ByteBuffer.allocate(size);
+ for(int i = 0; i < size; i++)
+ {
+ body.payload.put((byte) DATA[i % DATA.length]);
+ }
+ return body;
+ }
+
+ static ContentHeaderBody createContentHeaderBody()
+ {
+ ContentHeaderBody body = new ContentHeaderBody();
+ body.properties = new BasicContentHeaderProperties();
+ body.weight = 1;
+ body.classId = 6;
+ return body;
+ }
+
+ static BasicDeliverBody createBasicDeliverBody()
+ {
+ BasicDeliverBody body = new BasicDeliverBody();
+ body.consumerTag = "myConsumerTag";
+ body.deliveryTag = 1;
+ body.exchange = "myExchange";
+ body.redelivered = false;
+ body.routingKey = "myRoutingKey";
+ return body;
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/BasicDeliverTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/Client.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/Client.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/Client.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/Client.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,130 @@
+/*
+ *
+ * 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.codec;
+
+import org.apache.mina.transport.socket.nio.SocketConnector;
+import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.qpid.framing.AMQDataBlock;
+import org.apache.qpid.framing.AMQFrame;
+import org.apache.qpid.framing.BasicDeliverBody;
+import org.apache.qpid.framing.ContentBody;
+
+import java.net.InetSocketAddress;
+
+public class Client extends IoHandlerAdapter
+{
+ //private static final int[] DEFAULT_SIZES = new int[]{1024, 512, 256, 128, 56};
+ //private static final int[] DEFAULT_SIZES = new int[]{256, 256, 256, 256, 256, 512, 512, 512, 512, 512};
+ private static final int[] DEFAULT_SIZES = new int[]{256, 512, 256, 512, 256, 512, 256, 512, 256, 512};
+ //private static final int[] DEFAULT_SIZES = new int[]{1024, 1024, 1024, 1024, 1024};
+
+ private final IoSession _session;
+ private final long _start;
+ private final int _size;
+ private final int _count;
+ private int _received;
+ private boolean _closed;
+
+ Client(String host, int port, int size, int count) throws Exception
+ {
+ _count = count;
+ _size = size;
+ AMQDataBlock block = BasicDeliverTest.getDataBlock(size);
+
+ InetSocketAddress address = new InetSocketAddress(host, port);
+ ConnectFuture future = new SocketConnector().connect(address, this);
+ future.join();
+ _session = future.getSession();
+
+ _start = System.currentTimeMillis();
+ for(int i = 0; i < count; i++)
+ {
+ _session.write(block);
+ }
+ }
+
+ void close()
+ {
+ long time = System.currentTimeMillis() - _start;
+ System.out.println("Received " + _received + " messages of " + _size
+ + " bytes in " + time + "ms.");
+ _session.close();
+ synchronized(this)
+ {
+ _closed = true;
+ notify();
+ }
+ }
+
+ void waitForClose() throws InterruptedException
+ {
+ synchronized(this)
+ {
+ while(!_closed)
+ {
+ wait();
+ }
+ }
+ }
+
+ public void sessionCreated(IoSession session) throws Exception
+ {
+ session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new AMQCodecFactory(false)));
+ }
+
+ public void messageReceived(IoSession session, Object object) throws Exception
+ {
+ if(isContent(object) && ++_received == _count) close();
+ }
+
+ public void exceptionCaught(IoSession session, Throwable throwable) throws Exception
+ {
+ throwable.printStackTrace();
+ close();
+ }
+
+ private static boolean isDeliver(Object o)
+ {
+ return o instanceof AMQFrame && ((AMQFrame) o).bodyFrame instanceof BasicDeliverBody;
+ }
+
+ private static boolean isContent(Object o)
+ {
+ return o instanceof AMQFrame && ((AMQFrame) o).bodyFrame instanceof ContentBody;
+ }
+
+ public static void main(String[] argv) throws Exception
+ {
+ String host = argv.length > 0 ? argv[0] : "localhost";
+ int port = argv.length > 1 ? Integer.parseInt(argv[1]) : 8888;
+ int count = argv.length > 2 ? Integer.parseInt(argv[2]) : 10000;
+ int[] sizes = argv.length > 3 ? new int[]{Integer.parseInt(argv[3])} : DEFAULT_SIZES;
+
+ System.out.println("Connecting to " + host + ":" + port);
+
+ for(int i = 0; i < sizes.length; i++)
+ {
+ new Client(host, port, sizes[i], count).waitForClose();
+ Thread.sleep(1000);
+ }
+ }
+
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/Client.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/Server.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/Server.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/Server.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/Server.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,100 @@
+/*
+ *
+ * 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.codec;
+
+import org.apache.mina.common.IoHandlerAdapter;
+import org.apache.mina.common.IoSession;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.util.SessionUtil;
+import org.apache.mina.filter.codec.ProtocolCodecFilter;
+import org.apache.qpid.framing.AMQFrame;
+import org.apache.qpid.framing.CompositeAMQDataBlock;
+
+import java.net.InetSocketAddress;
+
+public class Server extends IoHandlerAdapter
+{
+ Server(int port) throws Exception
+ {
+ new SocketAcceptor().bind(new InetSocketAddress(port), this);
+ System.out.println("Listening on " + port);
+ }
+
+ public void sessionCreated(IoSession session) throws Exception
+ {
+ SessionUtil.initialize(session);
+ session.getFilterChain().addLast("protocolFilter", new ProtocolCodecFilter(new AMQCodecFactory(false)));
+ }
+
+ public void messageReceived(IoSession session, Object object) throws Exception
+ {
+ getAccumulator(session).received(session, (AMQFrame) object);
+ }
+
+ public void sessionOpened(IoSession session) throws Exception
+ {
+ System.out.println("sessionOpened()");
+ }
+
+ public void sessionClosed(IoSession session) throws Exception
+ {
+ System.out.println("sessionClosed()");
+ }
+
+ public void exceptionCaught(IoSession session, Throwable t) throws Exception
+ {
+ System.out.println("exceptionCaught()");
+ t.printStackTrace();
+ session.close();
+ }
+
+ private Accumulator getAccumulator(IoSession session)
+ {
+ Accumulator a = (Accumulator) session.getAttribute(ACCUMULATOR);
+ if(a == null)
+ {
+ a = new Accumulator();
+ session.setAttribute(ACCUMULATOR, a);
+ }
+ return a;
+ }
+
+ private static final String ACCUMULATOR = Accumulator.class.getName();
+
+ private static class Accumulator
+ {
+ private final AMQFrame[] frames = new AMQFrame[3];
+ private int i;
+
+ void received(IoSession session, AMQFrame frame)
+ {
+ frames[i++] = frame;
+ if(i >= frames.length)
+ {
+ i = 0;
+ session.write(new CompositeAMQDataBlock(frames));
+ }
+ }
+ }
+
+ public static void main(String[] argv) throws Exception
+ {
+ int port = argv.length > 0 ? Integer.parseInt(argv[0]) : 8888;
+ new Server(port);
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/codec/Server.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java Tue Sep 19 15:06:50 2006
@@ -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.config;
+
+import org.apache.qpid.client.AMQConnectionFactory;
+import org.apache.qpid.config.ConnectionFactoryInitialiser;
+import org.apache.qpid.config.ConnectorConfig;
+
+import javax.jms.ConnectionFactory;
+
+class AMQConnectionFactoryInitialiser implements ConnectionFactoryInitialiser
+{
+ public ConnectionFactory getFactory(ConnectorConfig config)
+ {
+ return new AMQConnectionFactory(config.getHost(), config.getPort(), "/test_path");
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/AMQConnectionFactoryInitialiser.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/AbstractConfig.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/AbstractConfig.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/AbstractConfig.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/AbstractConfig.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,66 @@
+/*
+ *
+ * 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.config;
+
+public abstract class AbstractConfig
+{
+ public boolean setOptions(String[] argv)
+ {
+ try
+ {
+ for(int i = 0; i < argv.length - 1; i += 2)
+ {
+ String key = argv[i];
+ String value = argv[i+1];
+ setOption(key, value);
+ }
+ return true;
+ }
+ catch(Exception e)
+ {
+ System.out.println(e.getMessage());
+ }
+ return false;
+ }
+
+ protected int parseInt(String msg, String i)
+ {
+ try
+ {
+ return Integer.parseInt(i);
+ }
+ catch(NumberFormatException e)
+ {
+ throw new RuntimeException(msg + ": " + i);
+ }
+ }
+
+ protected long parseLong(String msg, String i)
+ {
+ try
+ {
+ return Long.parseLong(i);
+ }
+ catch(NumberFormatException e)
+ {
+ throw new RuntimeException(msg + ": " + i);
+ }
+ }
+
+ public abstract void setOption(String key, String value);
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/AbstractConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/ConnectionFactoryInitialiser.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/ConnectionFactoryInitialiser.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/ConnectionFactoryInitialiser.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/ConnectionFactoryInitialiser.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,26 @@
+/*
+ *
+ * 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.config;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+
+public interface ConnectionFactoryInitialiser
+{
+ public ConnectionFactory getFactory(ConnectorConfig config) throws JMSException;
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/ConnectionFactoryInitialiser.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/Connector.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/Connector.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/Connector.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/Connector.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,37 @@
+/*
+ *
+ * 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.config;
+
+import javax.jms.Connection;
+import javax.jms.ConnectionFactory;
+
+public class Connector
+{
+ public Connection createConnection(ConnectorConfig config) throws Exception
+ {
+ return getConnectionFactory(config).createConnection();
+ }
+
+ ConnectionFactory getConnectionFactory(ConnectorConfig config) throws Exception
+ {
+ String factory = config.getFactory();
+ if(factory == null) factory = AMQConnectionFactoryInitialiser.class.getName();
+ System.out.println("Using " + factory);
+ return ((ConnectionFactoryInitialiser) Class.forName(factory).newInstance()).getFactory(config);
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/Connector.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/ConnectorConfig.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/ConnectorConfig.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/ConnectorConfig.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/ConnectorConfig.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,25 @@
+/*
+ *
+ * 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.config;
+
+public interface ConnectorConfig
+{
+ public String getHost();
+ public int getPort();
+ public String getFactory();
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/ConnectorConfig.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/JBossConnectionFactoryInitialiser.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/JBossConnectionFactoryInitialiser.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/JBossConnectionFactoryInitialiser.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/JBossConnectionFactoryInitialiser.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,108 @@
+/*
+ *
+ * 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.config;
+
+import org.apache.qpid.config.ConnectionFactoryInitialiser;
+import org.apache.qpid.config.ConnectorConfig;
+
+import javax.jms.ConnectionFactory;
+import javax.jms.JMSException;
+import javax.management.MBeanServerConnection;
+import javax.management.ObjectName;
+import javax.management.MBeanException;
+import javax.naming.InitialContext;
+import javax.naming.NamingException;
+import javax.naming.NameNotFoundException;
+import java.util.Hashtable;
+
+public class JBossConnectionFactoryInitialiser implements ConnectionFactoryInitialiser
+{
+ public ConnectionFactory getFactory(ConnectorConfig config) throws JMSException
+ {
+ ConnectionFactory cf = null;
+ InitialContext ic = null;
+ Hashtable ht = new Hashtable();
+ ht.put(InitialContext.INITIAL_CONTEXT_FACTORY, "org.jnp.interfaces.NamingContextFactory");
+ String jbossHost = System.getProperty("jboss.host", "eqd-lxamq01");
+ String jbossPort = System.getProperty("jboss.port", "1099");
+ ht.put(InitialContext.PROVIDER_URL, "jnp://" + jbossHost + ":" + jbossPort);
+ ht.put(InitialContext.URL_PKG_PREFIXES, "org.jboss.naming:org.jnp.interfaces");
+
+ try
+ {
+ ic = new InitialContext(ht);
+ if (!doesDestinationExist("topictest.messages", ic))
+ {
+ deployTopic("topictest.messages", ic);
+ }
+ if (!doesDestinationExist("topictest.control", ic))
+ {
+ deployTopic("topictest.control", ic);
+ }
+
+ cf = (ConnectionFactory) ic.lookup("/ConnectionFactory");
+ return cf;
+ }
+ catch (NamingException e)
+ {
+ throw new JMSException("Unable to lookup object: " + e);
+ }
+ catch (Exception e)
+ {
+ throw new JMSException("Error creating topic: " + e);
+ }
+ }
+
+ private boolean doesDestinationExist(String name, InitialContext ic) throws Exception
+ {
+ try
+ {
+ ic.lookup("/" + name);
+ }
+ catch (NameNotFoundException e)
+ {
+ return false;
+ }
+ return true;
+ }
+
+ private void deployTopic(String name, InitialContext ic) throws Exception
+ {
+ MBeanServerConnection mBeanServer = lookupMBeanServerProxy(ic);
+
+ ObjectName serverObjectName = new ObjectName("jboss.messaging:service=ServerPeer");
+
+ String jndiName = "/" + name;
+ try
+ {
+ mBeanServer.invoke(serverObjectName, "createTopic",
+ new Object[]{name, jndiName},
+ new String[]{"java.lang.String", "java.lang.String"});
+ }
+ catch (MBeanException e)
+ {
+ System.err.println("Error: " + e);
+ System.err.println("Cause: " + e.getCause());
+ }
+ }
+
+ private MBeanServerConnection lookupMBeanServerProxy(InitialContext ic) throws NamingException
+ {
+ return (MBeanServerConnection) ic.lookup("jmx/invoker/RMIAdaptor");
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/config/JBossConnectionFactoryInitialiser.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connection/ConnectionTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connection/ConnectionTest.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connection/ConnectionTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connection/ConnectionTest.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,101 @@
+/*
+ *
+ * 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);
+ }
+
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connection/ConnectionTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connection/TestManyConnections.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connection/TestManyConnections.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connection/TestManyConnections.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connection/TestManyConnections.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,100 @@
+/*
+ *
+ * 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.qpid.client.testutil.VmOrRemoteTestCase;
+import org.apache.log4j.Logger;
+import org.junit.Test;
+
+public class TestManyConnections extends VmOrRemoteTestCase
+{
+ 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, "tcp://foo", "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);
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connection/TestManyConnections.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connectionurl/ConnectionURLTest.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connectionurl/ConnectionURLTest.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connectionurl/ConnectionURLTest.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connectionurl/ConnectionURLTest.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,449 @@
+/*
+ *
+ * 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);
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connectionurl/ConnectionURLTest.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connectionurl/UnitTests.java
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connectionurl/UnitTests.java?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connectionurl/UnitTests.java (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connectionurl/UnitTests.java Tue Sep 19 15:06:50 2006
@@ -0,0 +1,33 @@
+/*
+ *
+ * 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);
+ }
+}
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/connectionurl/UnitTests.java
------------------------------------------------------------------------------
svn:eol-style = native
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/bin/jmscts.sh
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/bin/jmscts.sh?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/bin/jmscts.sh (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/bin/jmscts.sh Tue Sep 19 15:06:50 2006
@@ -0,0 +1,159 @@
+#!/bin/sh
+#
+# 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.
+#
+
+# -----------------------------------------------------------------------------
+# Start/Stop Script for the JMS compliance test suite
+#
+# Required Environment Variables
+#
+# JAVA_HOME Points to the Java Development Kit installation.
+#
+# Optional Environment Variables
+#
+# JMSCTS_HOME Points to the JMS CTS installation directory.
+#
+# JAVA_OPTS Java runtime options used when the command is executed.
+#
+#
+# $Id: jmscts.sh,v 1.6 2003/09/27 09:50:49 tanderson Exp $
+# ---------------------------------------------------------------------------
+
+# OS specific support. $var _must_ be set to either true or false.
+cygwin=false
+case "`uname`" in
+CYGWIN*) cygwin=true;;
+esac
+
+# For Cygwin, ensure paths are in UNIX format before anything is touched
+if $cygwin; then
+ [ -n "$JAVA_HOME" ] && JAVA_HOME=`cygpath --unix "$JAVA_HOME"`
+fi
+
+if [ -z "$JAVA_HOME" ]; then
+ echo "The JAVA_HOME environment variable is not set."
+ echo "This is required to run jmscts"
+ exit 1
+fi
+if [ ! -r "$JAVA_HOME"/bin/java ]; then
+ echo "The JAVA_HOME environment variable is not set correctly."
+ echo "This is required to run jmscts"
+ exit 1
+fi
+_RUNJAVA="$JAVA_HOME"/bin/java
+
+
+# Guess JMSCTS_HOME if it is not set
+if [ -z "$JMSCTS_HOME" ]; then
+# resolve links - $0 may be a softlink
+ PRG="$0"
+ while [ -h "$PRG" ]; do
+ ls=`ls -ld "$PRG"`
+ link=`expr "$ls" : '.*-> \(.*\)$'`
+ if expr "$link" : '.*/.*' > /dev/null; then
+ PRG="$link"
+ else
+ PRG=`dirname "$PRG"`/"$link"
+ fi
+ done
+
+ PRGDIR=`dirname "$PRG"`
+ JMSCTS_HOME=`cd "$PRGDIR/.." ; pwd`
+elif [ ! -r "$JMSCTS_HOME"/bin/jmscts.sh ]; then
+ echo "The JMSCTS_HOME environment variable is not set correctly."
+ echo "This is required to run jmscts"
+ exit 1
+fi
+
+# Set CLASSPATH to empty by default. User jars can be added via the setenv.sh
+# script
+CLASSPATH=
+
+if [ -r "$JMSCTS_HOME"/bin/setenv.sh ]; then
+ . "$JMSCTS_HOME"/bin/setenv.sh
+fi
+
+CLASSPATH="$CLASSPATH":"$JMSCTS_HOME"/lib/jmscts-0.5-b2.jar
+
+# For Cygwin, switch paths to Windows format before running java
+if $cygwin; then
+ JAVA_HOME=`cygpath --path --windows "$JAVA_HOME"`
+ JMSCTS_HOME=`cygpath --path --windows "$JMSCTS_HOME"`
+ CLASSPATH=`cygpath --path --windows "$CLASSPATH"`
+fi
+
+POLICY_FILE="$JMSCTS_HOME"/config/jmscts.policy
+
+# Configure TrAX
+JAVAX_OPTS=-Djavax.xml.transform.TransformerFactory=org.apache.xalan.processor.TransformerFactoryImpl
+
+
+# Execute the requested command
+
+echo "Using JMSCTS_HOME: $JMSCTS_HOME"
+echo "Using JAVA_HOME: $JAVA_HOME"
+echo "Using CLASSPATH: $CLASSPATH"
+
+if [ "$1" = "run" ]; then
+
+ shift
+ exec "$_RUNJAVA" $JAVA_OPTS $JAVAX_OPTS -Djmscts.home="$JMSCTS_HOME" \
+ -classpath "$CLASSPATH" \
+ -Djava.security.manager -Djava.security.policy="$POLICY_FILE" \
+ org.exolab.jmscts.test.ComplianceTestSuite "$@"
+
+elif [ "$1" = "stress" ]; then
+
+ shift
+ exec "$_RUNJAVA" $JAVA_OPTS $JAVAX_OPTS -Djmscts.home="$JMSCTS_HOME" \
+ -classpath "$CLASSPATH" \
+ -Djava.security.manager -Djava.security.policy="$POLICY_FILE" \
+ org.exolab.jmscts.stress.StressTestSuite "$@"
+
+elif [ "$1" = "stop" ] ; then
+
+ shift
+ "$_RUNJAVA" $JAVA_OPTS $JAVAX_OPTS -Djmscts.home="$JMSCTS_HOME" \
+ -classpath "$CLASSPATH" \
+ -Djava.security.manager -Djava.security.policy="$POLICY_FILE" \
+ org.exolab.jmscts.core.Admin -stop
+
+elif [ "$1" = "abort" ] ; then
+
+ shift
+ exec "$_RUNJAVA" $JAVA_OPTS $JAVAX_OPTS -Djmscts.home="$JMSCTS_HOME" \
+ -classpath "$CLASSPATH" \
+ -Djava.security.manager -Djava.security.policy="$POLICY_FILE" \
+ org.exolab.jmscts.core.Admin -abort
+
+elif [ "$1" = "snapshot" ] ; then
+
+ shift
+ exec "$_RUNJAVA" $JAVA_OPTS $JAVAX_OPTS -Djmscts.home="$JMSCTS_HOME" \
+ -classpath "$CLASSPATH" \
+ -Djava.security.manager -Djava.security.policy="$POLICY_FILE" \
+ org.exolab.jmscts.core.Admin -snapshot "$@"
+
+else
+ echo "usage: jmscts.sh (commands)"
+ echo "commands:"
+ echo " run Run compliance tests"
+ echo " stress Run stress tests"
+ echo " stop Stop the JMS CTS"
+ echo " abort Abort the JMS CTS"
+ echo " snapshot Take a snapshot"
+ exit 1
+fi
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/bin/jmscts.sh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/bin/jmscts.sh
------------------------------------------------------------------------------
svn:executable = *
Added: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/bin/setenv.sh
URL: http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/bin/setenv.sh?view=auto&rev=447994
==============================================================================
--- incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/bin/setenv.sh (added)
+++ incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/bin/setenv.sh Tue Sep 19 15:06:50 2006
@@ -0,0 +1,38 @@
+#
+# 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.
+#
+
+# ---------------------------------------------------------------------------
+# Sample environment script for JMS CTS
+#
+# This is invoked by jmscts.sh to configure:
+# . the CLASSPATH, for JMS provider jars
+# . JVM options
+#
+# The following configures the JMS CTS for OpenJMS 0.7.6
+# ---------------------------------------------------------------------------
+
+# Configure the CLASSPATH
+#
+DISTDIR="$IBASE/amqp/dist"
+LIBDIR="$IBASE/amqp/lib"
+
+CLASSPATH="$LIBDIR/jakarta-commons/commons-collections-3.1.jar:$LIBDIR/util-concurrent/backport-util-concurrent.jar:$LIBDIR/mina/mina-0.7.3.jar:$LIBDIR/jms/jms.jar:$LIBDIR/logging-log4j/log4j-1.2.9.jar:$DISTDIR/amqp-common.jar:$DISTDIR/amqp-jms.jar"
+
+# Configure JVM options
+#
+JAVA_OPTS=-Xmx512m -Xms512m
+JAVA_OPTS="$JAVA_OPTS \
+ -Damqj.logging.level=WARN"
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/bin/setenv.sh
------------------------------------------------------------------------------
svn:eol-style = native
Propchange: incubator/qpid/trunk/qpid/java/client/test/src/org/apache/qpid/cts/bin/setenv.sh
------------------------------------------------------------------------------
svn:executable = *