[hornetq-commits] JBoss hornetq SVN: r8456 - in trunk/tests/src/org/hornetq/tests/stress: client and 1 other directory.

do-not-reply at jboss.org do-not-reply at jboss.org
Sun Nov 29 22:31:28 EST 2009


Author: clebert.suconic at jboss.com
Date: 2009-11-29 22:31:27 -0500 (Sun, 29 Nov 2009)
New Revision: 8456

Added:
   trunk/tests/src/org/hornetq/tests/stress/client/
   trunk/tests/src/org/hornetq/tests/stress/client/SendStressTest.java
Log:
Adding test to replicate issue described on http://www.jboss.org/index.html?module=bb&op=viewtopic&t=164372

Added: trunk/tests/src/org/hornetq/tests/stress/client/SendStressTest.java
===================================================================
--- trunk/tests/src/org/hornetq/tests/stress/client/SendStressTest.java	                        (rev 0)
+++ trunk/tests/src/org/hornetq/tests/stress/client/SendStressTest.java	2009-11-30 03:31:27 UTC (rev 8456)
@@ -0,0 +1,150 @@
+/*
+ * Copyright 2009 Red Hat, Inc.
+ * Red Hat licenses this file to you 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.hornetq.tests.stress.client;
+
+import junit.framework.TestSuite;
+
+import org.hornetq.core.client.ClientConsumer;
+import org.hornetq.core.client.ClientMessage;
+import org.hornetq.core.client.ClientProducer;
+import org.hornetq.core.client.ClientSession;
+import org.hornetq.core.client.ClientSessionFactory;
+import org.hornetq.core.server.HornetQServer;
+import org.hornetq.tests.util.ServiceTestBase;
+
+/**
+ * A SendStressTest
+ *
+ * @author <mailto:clebert.suconic at jboss.org">Clebert Suconic</a>
+ *
+ *
+ */
+public class SendStressTest extends ServiceTestBase
+{
+
+   // Constants -----------------------------------------------------
+
+   // Attributes ----------------------------------------------------
+
+   // Static --------------------------------------------------------
+
+   // Constructors --------------------------------------------------
+
+   // Public --------------------------------------------------------
+
+   // Remove this method to re-enable those tests
+   public static TestSuite suite()
+   {
+      return new TestSuite();
+   }
+
+   public void testStressSendNetty() throws Exception
+   {
+      doTestStressSend(true);
+   }
+
+   public void testStressSendInVM() throws Exception
+   {
+      doTestStressSend(false);
+   }
+
+   public void doTestStressSend(final boolean netty) throws Exception
+   {
+      HornetQServer server = createServer(false, netty);
+
+      ClientSessionFactory sf = createFactory(netty);
+
+      ClientSession session = null;
+
+      final int batchSize = 2000;
+
+      final int numberOfMessages = 100000;
+
+      try
+      {
+         server.start();
+
+         session = sf.createSession(false, false);
+
+         session.createQueue("address", "queue");
+
+         ClientProducer producer = session.createProducer("address");
+
+         ClientMessage message = session.createClientMessage(false);
+
+         message.getBodyBuffer().writeBytes(new byte[1024]);
+
+         for (int i = 0; i < numberOfMessages; i++)
+         {
+            producer.send(message);
+            if (i % batchSize == 0)
+            {
+               System.out.println("Sent " + i);
+               session.commit();
+            }
+         }
+
+         session.commit();
+
+         session.close();
+
+         session = sf.createSession(false, false);
+
+         ClientConsumer consumer = session.createConsumer("queue");
+
+         session.start();
+
+         for (int i = 0; i < numberOfMessages; i++)
+         {
+            ClientMessage msg = consumer.receive(5000);
+            assertNotNull(msg);
+            msg.acknowledge();
+
+            if (i % batchSize == 0)
+            {
+               System.out.println("Consumed " + i);
+               session.commit();
+            }
+         }
+
+         session.commit();
+      }
+      finally
+      {
+         if (session != null)
+         {
+            try
+            {
+               sf.close();
+               session.close();
+            }
+            catch (Exception e)
+            {
+               e.printStackTrace();
+            }
+         }
+         server.stop();
+      }
+
+   }
+
+   // Package protected ---------------------------------------------
+
+   // Protected -----------------------------------------------------
+
+   // Private -------------------------------------------------------
+
+   // Inner classes -------------------------------------------------
+
+}



More information about the hornetq-commits mailing list