diff options
author | Bhupendra Bhusman Bhardwaj <bhupendrab@apache.org> | 2007-01-10 17:41:11 +0000 |
---|---|---|
committer | Bhupendra Bhusman Bhardwaj <bhupendrab@apache.org> | 2007-01-10 17:41:11 +0000 |
commit | 1b13d0fee1a092baeb10ba5c2c90a25ee3e7ffb6 (patch) | |
tree | 80dd5780a86c03c4914a3688e9dbbc0750930b2e | |
parent | 62245d32975f4baf5d49919d4e9ee1b2c406e75d (diff) | |
download | qpid-python-1b13d0fee1a092baeb10ba5c2c90a25ee3e7ffb6.tar.gz |
amended ping tests to allow variation of message sizes
git-svn-id: https://svn.apache.org/repos/asf/incubator/qpid/trunk/qpid@494904 13f79535-47bb-0310-9956-ffa450edef68
3 files changed, 125 insertions, 13 deletions
diff --git a/java/perftests/src/main/java/org/apache/qpid/client/message/TestMessageFactory.java b/java/perftests/src/main/java/org/apache/qpid/client/message/TestMessageFactory.java new file mode 100644 index 0000000000..dc2bf39a9b --- /dev/null +++ b/java/perftests/src/main/java/org/apache/qpid/client/message/TestMessageFactory.java @@ -0,0 +1,83 @@ +/* + * + * 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.mina.common.ByteBuffer; +import org.apache.mina.common.SimpleByteBufferAllocator; + +import javax.jms.JMSException; +import javax.jms.Session; +import javax.jms.ObjectMessage; +import javax.jms.StreamMessage; +import javax.jms.BytesMessage; +import javax.jms.TextMessage; + +public class TestMessageFactory +{ + private static final String MESSAGE_DATA_BYTES = "-message payload-message paylaod-message payload-message paylaod"; + + public static TextMessage newTextMessage(Session session, int size) throws JMSException + { + return session.createTextMessage(createMessagePayload(size)); + } + + public static JMSTextMessage newJMSTextMessage(int size, String encoding) throws JMSException + { + ByteBuffer byteBuffer = (new SimpleByteBufferAllocator()).allocate(size, true); + JMSTextMessage message = new JMSTextMessage(byteBuffer, encoding); + message.clearBody(); + message.setText(createMessagePayload(size)); + return message; + } + + public static BytesMessage newBytesMessage(Session session, int size) throws JMSException + { + BytesMessage message = session.createBytesMessage(); + message.writeUTF(createMessagePayload(size)); + return message; + } + + public static StreamMessage newStreamMessage(Session session, int size) throws JMSException + { + StreamMessage message = session.createStreamMessage(); + message.writeString(createMessagePayload(size)); + return message; + } + + public static ObjectMessage newObjectMessage(Session session, int size) throws JMSException + { + return session.createObjectMessage(createMessagePayload(size)); + } + + public static String createMessagePayload(int size) + { + StringBuffer buf = new StringBuffer(size); + int count = 0; + while (count < size) + { + buf.append(MESSAGE_DATA_BYTES); + count += MESSAGE_DATA_BYTES.length(); + } + if (count < size) + { + buf.append(MESSAGE_DATA_BYTES, 0, size - count); + } + + return buf.toString(); + } +} diff --git a/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java b/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java index cb9154d97b..bb9e17615e 100644 --- a/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java +++ b/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java @@ -27,6 +27,7 @@ import org.apache.qpid.url.URLSyntaxException; import org.apache.qpid.client.AMQNoConsumersException; import org.apache.qpid.client.BasicMessageProducer; import org.apache.qpid.client.AMQQueue; +import org.apache.qpid.client.message.TestMessageFactory; import org.apache.qpid.jms.MessageProducer; import org.apache.qpid.jms.Session; @@ -48,7 +49,7 @@ public class TestPingProducer implements ExceptionListener private AMQConnection _connection; - + private static int _messageSize = 0; private boolean _publish; private long SLEEP_TIME = 250L; @@ -105,8 +106,16 @@ public class TestPingProducer implements ExceptionListener TextMessage msg = session.createTextMessage( "Presented to in conjunction with Mahnah Mahnah and the Snowths: " + ++messageNumber); */ - ObjectMessage msg = session.createObjectMessage(); - + ObjectMessage msg = null; + if (_messageSize != 0) + { + msg = TestMessageFactory.newObjectMessage(session, _messageSize); + } + else + { + msg = session.createObjectMessage(); + } + msg.setStringProperty("timestampString", Long.toString(System.currentTimeMillis())); msg.setLongProperty("timestamp", System.currentTimeMillis()); @@ -184,14 +193,25 @@ public class TestPingProducer implements ExceptionListener { if (args.length < 2) { - System.err.println("Usage: TestPingPublisher <brokerDetails> <virtual path> [transacted]"); + System.err.println("Usage: TestPingPublisher <brokerDetails> <virtual path> [transacted] [message size in bytes]"); System.exit(0); } try { InetAddress address = InetAddress.getLocalHost(); String clientID = address.getHostName() + System.currentTimeMillis(); - new TestPingProducer(args.length == 3, args[0], clientID, args[1]); + boolean transacted = false; + if (args.length == 3 ) + { + transacted = Boolean.parseBoolean(args[2]); + } + else if (args.length > 3 ) + { + transacted = Boolean.parseBoolean(args[2]); + _messageSize = Integer.parseInt(args[3]); + } + + new TestPingProducer(transacted, args[0], clientID, args[1]); } catch (UnknownHostException e) { diff --git a/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java b/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java index 9f66387497..3b2dcc4d36 100644 --- a/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java +++ b/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java @@ -26,6 +26,7 @@ import org.apache.qpid.AMQException; import org.apache.qpid.url.URLSyntaxException; import org.apache.qpid.client.AMQTopic; import org.apache.qpid.client.BasicMessageProducer; +import org.apache.qpid.client.message.TestMessageFactory; import org.apache.qpid.jms.MessageProducer; import org.apache.qpid.jms.Session; @@ -48,7 +49,7 @@ public class TestPingPublisher implements ExceptionListener private AMQConnection _connection; private boolean _publish; - + private static int _messageSize = 0; private long SLEEP_TIME = 0L; // private class CallbackHandler implements MessageListener @@ -94,7 +95,15 @@ public class TestPingPublisher implements ExceptionListener TextMessage msg = session.createTextMessage( "Presented to in conjunction with Mahnah Mahnah and the Snowths: " + ++messageNumber); */ - ObjectMessage msg = session.createObjectMessage(); + ObjectMessage msg = null; + if (_messageSize != 0) + { + msg = TestMessageFactory.newObjectMessage(session, _messageSize); + } + else + { + msg = session.createObjectMessage(); + } Long time = System.nanoTime(); msg.setStringProperty("timestampString", Long.toString(time)); @@ -121,8 +130,6 @@ public class TestPingPublisher implements ExceptionListener //do nothing } } - - } } @@ -135,9 +142,7 @@ public class TestPingPublisher implements ExceptionListener private void createConnection(String brokerDetails, String clientID, String virtualpath) throws AMQException, URLSyntaxException { _publish = true; - _connection = new AMQConnection(brokerDetails, "guest", "guest", - clientID, virtualpath); - + _connection = new AMQConnection(brokerDetails, "guest", "guest", clientID, virtualpath); _log.info("Connected with URL:" + _connection.toURL()); } @@ -149,13 +154,17 @@ public class TestPingPublisher implements ExceptionListener { if (args.length < 2) { - System.err.println("Usage: TestPingPublisher <brokerDetails> <virtual path>"); + System.err.println("Usage: TestPingPublisher <brokerDetails> <virtual path> [message size in bytes]"); System.exit(0); } try { InetAddress address = InetAddress.getLocalHost(); String clientID = address.getHostName() + System.currentTimeMillis(); + if (args.length > 2 ) + { + _messageSize = Integer.parseInt(args[2]); + } new TestPingPublisher(args[0], clientID, args[1]); } catch (UnknownHostException e) |