Return-Path: Delivered-To: apmail-activemq-commits-archive@www.apache.org Received: (qmail 62563 invoked from network); 23 Oct 2009 08:11:42 -0000 Received: from hermes.apache.org (HELO mail.apache.org) (140.211.11.3) by minotaur.apache.org with SMTP; 23 Oct 2009 08:11:42 -0000 Received: (qmail 38860 invoked by uid 500); 23 Oct 2009 08:11:42 -0000 Delivered-To: apmail-activemq-commits-archive@activemq.apache.org Received: (qmail 38812 invoked by uid 500); 23 Oct 2009 08:11:42 -0000 Mailing-List: contact commits-help@activemq.apache.org; run by ezmlm Precedence: bulk List-Help: List-Unsubscribe: List-Post: List-Id: Reply-To: dev@activemq.apache.org Delivered-To: mailing list commits@activemq.apache.org Received: (qmail 38803 invoked by uid 99); 23 Oct 2009 08:11:42 -0000 Received: from nike.apache.org (HELO nike.apache.org) (192.87.106.230) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Oct 2009 08:11:42 +0000 X-ASF-Spam-Status: No, hits=-2000.0 required=10.0 tests=ALL_TRUSTED X-Spam-Check-By: apache.org Received: from [140.211.11.4] (HELO eris.apache.org) (140.211.11.4) by apache.org (qpsmtpd/0.29) with ESMTP; Fri, 23 Oct 2009 08:11:39 +0000 Received: by eris.apache.org (Postfix, from userid 65534) id 3D0F523888CF; Fri, 23 Oct 2009 08:11:18 +0000 (UTC) Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit Subject: svn commit: r828954 - in /activemq/trunk/activemq-core: pom.xml src/test/java/org/apache/activemq/transport/stomp/StompLoadTest.java Date: Fri, 23 Oct 2009 08:11:18 -0000 To: commits@activemq.apache.org From: dejanb@apache.org X-Mailer: svnmailer-1.0.8 Message-Id: <20091023081118.3D0F523888CF@eris.apache.org> X-Virus-Checked: Checked by ClamAV on apache.org Author: dejanb Date: Fri Oct 23 08:11:17 2009 New Revision: 828954 URL: http://svn.apache.org/viewvc?rev=828954&view=rev Log: test for http://issues.apache.org/activemq/browse/AMQ-1873 - stomp toon many open files Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompLoadTest.java Modified: activemq/trunk/activemq-core/pom.xml Modified: activemq/trunk/activemq-core/pom.xml URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/pom.xml?rev=828954&r1=828953&r2=828954&view=diff ============================================================================== --- activemq/trunk/activemq-core/pom.xml (original) +++ activemq/trunk/activemq-core/pom.xml Fri Oct 23 08:11:17 2009 @@ -481,6 +481,8 @@ **/ProxyConnectorTest.* + + **/StompLoadTest.* Added: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompLoadTest.java URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompLoadTest.java?rev=828954&view=auto ============================================================================== --- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompLoadTest.java (added) +++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/transport/stomp/StompLoadTest.java Fri Oct 23 08:11:17 2009 @@ -0,0 +1,109 @@ +package org.apache.activemq.transport.stomp; + +import java.net.Socket; +import java.net.URI; +import java.util.HashMap; + +import junit.framework.TestCase; + +import org.apache.activemq.transport.stomp.StompConnection; +import org.apache.activemq.transport.stomp.StompFrame; +import org.apache.commons.logging.Log; +import org.apache.commons.logging.LogFactory; + +/** + * + * Simulates load on the Stomp connector. All producers/consumers open/close a + * connection on every command Configurable number of producers/consumers, their + * speed and duration of test + * + * Start a broker with the desired configuration to test and then run this test + * + */ +public class StompLoadTest extends TestCase { + + private static final Log LOG = LogFactory.getLog(StompLoadTest.class); + + final int producerSleep = 10; + final int consumerSleep = 10; + final int msgCount = 10000; + final int producerCount = 5; + final int consumerCount = 5; + final int testTime = 10 * 60 * 1000; + final String bindAddress = "stomp://0.0.0.0:61613"; + + public void testLoad() throws Exception { + + for (int i = 0; i < producerCount; i++) { + ProducerThread producerThread = new ProducerThread("producer" + i); + producerThread.start(); + } + + for (int i = 0; i < consumerCount; i++) { + Thread consumerThread = new ConsumerThread("consumer" + i); + consumerThread.start(); + } + + Thread.sleep(testTime); + } + + public StompConnection createConnection() throws Exception { + StompConnection conn = new StompConnection(); + URI connectUri = new URI(bindAddress); + conn.open(new Socket(connectUri.getHost(), connectUri.getPort())); + conn.connect("", ""); + return conn; + } + + class ProducerThread extends Thread { + + String name; + + public ProducerThread(String name) { + this.name = name; + } + + public void run() { + for (int i = 0; i < msgCount; i++) { + try { + StompConnection conn = createConnection(); + String msg = "test message " + i; + LOG.info(name + " sending " + msg); + conn.send("/queue/test", msg); + conn.disconnect(); + Thread.sleep(producerSleep); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + + class ConsumerThread extends Thread { + + String name; + + public ConsumerThread(String name) { + this.name = name; + } + + public void run() { + for (int i = 0; i < msgCount; i++) { + try { + StompConnection conn = createConnection(); + HashMap headers = new HashMap(); + headers.put("activemq.prefetchSize", "1"); + conn.subscribe("/queue/test", "client", headers); + StompFrame frame = conn.receive(1000); + conn.ack(frame); + LOG.info(name + " received " + frame.getBody()); + conn.disconnect(); + Thread.sleep(consumerSleep); + } catch (Exception e) { + e.printStackTrace(); + } + } + } + } + +}