Author: bhupendrab
Date: Wed Jan 10 09:41:11 2007
New Revision: 494904

URL: http://svn.apache.org/viewvc?view=rev&rev=494904
Log:
amended ping tests to allow variation of message sizes

Added:
    
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/client/
    
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/client/message/
    
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/client/message/TestMessageFactory.java
   (with props)
Modified:
    
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java
    
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java

Added: 
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/client/message/TestMessageFactory.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/client/message/TestMessageFactory.java?view=auto&rev=494904
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/client/message/TestMessageFactory.java
 (added)
+++ 
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/client/message/TestMessageFactory.java
 Wed Jan 10 09:41:11 2007
@@ -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();
+    }
+}

Propchange: 
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/client/message/TestMessageFactory.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: 
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java?view=diff&rev=494904&r1=494903&r2=494904
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingProducer.java
 Wed Jan 10 09:41:11 2007
@@ -27,6 +27,7 @@
 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 @@
 
     private AMQConnection _connection;
 
-
+    private static int _messageSize = 0;
     private boolean _publish;
 
     private long SLEEP_TIME = 250L;
@@ -105,8 +106,16 @@
                 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 @@
     {
         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)
         {

Modified: 
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java
URL: 
http://svn.apache.org/viewvc/incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java?view=diff&rev=494904&r1=494903&r2=494904
==============================================================================
--- 
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java
 (original)
+++ 
incubator/qpid/trunk/qpid/java/perftests/src/main/java/org/apache/qpid/pingpong/TestPingPublisher.java
 Wed Jan 10 09:41:11 2007
@@ -26,6 +26,7 @@
 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 @@
     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 @@
                 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 @@
                         //do nothing
                     }
                 }
-
-
             }
 
         }
@@ -135,9 +142,7 @@
     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 @@
     {
         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)


Reply via email to