User: chirino 
  Date: 01/06/24 18:25:54

  Added:       src/main/org/jboss/test/jbossmq/perf Main.java
  Log:
  Relabled the spydermq stuff to jbossmq.
  
  Revision  Changes    Path
  1.1                  jbosstest/src/main/org/jboss/test/jbossmq/perf/Main.java
  
  Index: Main.java
  ===================================================================
  /*
   * Copyright (c) 2000 Hiram Chirino <[EMAIL PROTECTED]>
   *
   * This library is free software; you can redistribute it and/or
   * modify it under the terms of the GNU Lesser General Public
   * License as published by the Free Software Foundation; either
   * version 2 of the License, or (at your option) any later version
   *
   * This library is distributed in the hope that it will be useful,
   * but WITHOUT ANY WARRANTY; without even the implied warranty of
   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   * Lesser General Public License for more details.
   *
   * You should have received a copy of the GNU Lesser General Public
   * License along with this library; if not, write to the Free Software
   * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
   */
  package org.jboss.test.jbossmq.perf;
  
  import javax.naming.*;
  import javax.jms.*;
  import java.util.*;
  
  /**
   * Main.java
   *
   * Some simple tests of spyderMQ
   *
   * @author
   * @version
   */
  
  public class Main  extends junit.framework.TestCase {
        
        // Provider specific
        static String TOPIC_FACTORY = "TopicConnectionFactory";
        static String QUEUE_FACTORY = "QueueConnectionFactory";
        
        static String TEST_QUEUE = "queue/testQueue";
        static String TEST_TOPIC = "topic/testTopic";
  
        static int PERFORMANCE_TEST_ITERATIONS = 1000;
        static byte[] PERFORMANCE_TEST_DATA_PAYLOAD = new byte[10*1024];
  
        //JMSProviderAdapter providerAdapter;
        static Context context;
        static QueueConnection queueConnection; 
        static TopicConnection topicConnection;
        
        public Main(String name) throws Exception{
                super(name);            
        }
  
  
        
  
        
  
  
  
  
  
  
  
  
  
  
  
  
        
  
        
        // Emptys out all the messages in a queue 
        private void drainQueue() throws Exception {
                
                QueueSession session = queueConnection.createQueueSession(false, 
Session.AUTO_ACKNOWLEDGE);
                Queue queue = (Queue)context.lookup(TEST_QUEUE);
  
                QueueReceiver receiver = session.createReceiver(queue);
                Message message = receiver.receive( 2000 );
                int c=0;
                while( message != null ) {
                        message = receiver.receive( 2000 );
                        c++;
                }
                
                if( c!=0 )
                        System.out.println("  Drained "+c+" messages from the queue");
                
                session.close();
                
        }
        
        private void waitForSynchMessage() throws Exception {
                QueueSession session = queueConnection.createQueueSession(false, 
Session.AUTO_ACKNOWLEDGE);
                Queue queue = (Queue)context.lookup(TEST_QUEUE);
  
                QueueReceiver receiver = session.createReceiver(queue);
                receiver.receive();
                session.close();
        }
        
        private void sendSynchMessage() throws Exception {
                QueueSession session = queueConnection.createQueueSession(false, 
Session.AUTO_ACKNOWLEDGE);
                Queue queue = (Queue)context.lookup(TEST_QUEUE);
  
                QueueSender sender = session.createSender(queue);
  
                Message message = session.createMessage();
                sender.send(message);
                
                session.close();
        }
                
        static public void main ( String []args ) {
  
                String newArgs[] = { "org.jboss.test.spydermq.test.Main" };
                junit.swingui.TestRunner.main(newArgs);
                
                
        }
  
        public void runAsynchQueuePerformance(final boolean transacted, final int 
persistence) throws Exception {
                        
                {
                        queueConnection.start();
                        drainQueue();
                        queueConnection.stop();
                }
                
                Thread sendThread = new Thread() {
                        public void run() {
                                try {
                                        QueueSession session = 
queueConnection.createQueueSession(transacted, Session.AUTO_ACKNOWLEDGE);
                                        Queue queue = 
(Queue)context.lookup(TEST_QUEUE);
  
                                        QueueSender sender = 
session.createSender(queue);
  
                                        BytesMessage message = 
session.createBytesMessage();
                                        
message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
  
                                        long startTime = System.currentTimeMillis();
                                        for( int i=0; i < PERFORMANCE_TEST_ITERATIONS; 
i++) {
                                                sender.send(queue, message, 
persistence, 4, 0);
                                                //System.out.println("  Sent #"+i);
                                        }
  
                                        if( transacted )
                                                session.commit();
                                                
                                        long endTime = System.currentTimeMillis();
                                                
                                        session.close();
  
                                        long pTime = endTime-startTime;
                                        System.out.println("  sent all messages in 
"+((double)pTime/1000)+" seconds. ");
                                } catch ( Exception e ) {
                                        e.printStackTrace();
                                }
                        }
                };
  
                QueueSession session = queueConnection.createQueueSession(transacted, 
Session.AUTO_ACKNOWLEDGE);
                Queue queue = (Queue)context.lookup(TEST_QUEUE);
                QueueReceiver receiver = session.createReceiver(queue);
  
                MessageListener listener = new MessageListener() {
                        long startTime = System.currentTimeMillis();
                        int i = 0;
                        public void onMessage(Message message) {
                                i++;
                                if( i >= PERFORMANCE_TEST_ITERATIONS ) {               
                         
                                        long endTime = System.currentTimeMillis();
                                        long pTime = endTime-startTime;
                                        System.out.println("  received all messages in 
"+((double)pTime/1000)+" seconds. ");
                                        
                                        synchronized ( this ) {
                                                this.notify();
                                        }
                                }                                       
                        }
                };
  
                
                System.out.println("  This test will send 
"+PERFORMANCE_TEST_ITERATIONS+" "
                        
+(persistence==DeliveryMode.PERSISTENT?"persistent":"non-persistent")+" messages. Each 
with a payload of "
                        +((double)PERFORMANCE_TEST_DATA_PAYLOAD.length/1024)+"Kb"
                        +" Session is "+(!transacted?"NOT":"")+" transacted");
                long startTime = System.currentTimeMillis();
                sendThread.start();
                receiver.setMessageListener( listener );
                queueConnection.start();
                synchronized( listener ) {
                        listener.wait();
                }
                if( transacted )
                        session.commit();
                        
                session.close();
                sendThread.join();
                long endTime = System.currentTimeMillis();
                long pTime = endTime-startTime;
                System.out.println("  All threads finished after: 
"+((double)pTime/1000)+" seconds. ");
                
        }
  
        public void runAsynchTopicPerformance(final boolean transacted, final int 
persistence) throws Exception {
  
                {
                        queueConnection.start();
                        drainQueue( );
                }
                
                Thread sendThread = new Thread() {
                        public void run() {
                                try {
                                        
                                        
                                        TopicSession session = 
topicConnection.createTopicSession(transacted, Session.AUTO_ACKNOWLEDGE);
                                        Topic topic = 
(Topic)context.lookup(TEST_TOPIC);
  
                                        TopicPublisher publisher = 
session.createPublisher(topic);
  
                                        waitForSynchMessage();
  
                                        BytesMessage message = 
session.createBytesMessage();
                                        
message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
  
                                        long startTime = System.currentTimeMillis();
                                        for( int i=0; i < PERFORMANCE_TEST_ITERATIONS; 
i++) {
                                                publisher.publish(topic, message, 
persistence, 4, 0);
                                                //System.out.println("  Sent #"+i);
                                        }
                                        if( transacted )
                                                session.commit();
  
                                        long endTime = System.currentTimeMillis();
                                        session.close();
  
                                        long pTime = endTime-startTime;
                                        System.out.println("  sent all messages in 
"+((double)pTime/1000)+" seconds. ");
                                } catch ( Exception e ) {
                                        e.printStackTrace();
                                }
                        }
                };
  
                TopicSession session = topicConnection.createTopicSession(transacted, 
Session.AUTO_ACKNOWLEDGE);
                Topic topic = (Topic)context.lookup(TEST_TOPIC);
                TopicSubscriber subscriber = session.createSubscriber(topic);
  
                MessageListener listener = new MessageListener() {
                        long startTime = System.currentTimeMillis();
                        int i = 0;
                        public void onMessage(Message message) {
                                i++;
                                if( i >= PERFORMANCE_TEST_ITERATIONS ) {               
                         
                                        long endTime = System.currentTimeMillis();
                                        long pTime = endTime-startTime;
                                        System.out.println("  received all messages in 
"+((double)pTime/1000)+" seconds. ");
                                        
                                        synchronized ( this ) {
                                                this.notify();
                                        }
                                }                                       
                        }
                };
                
                System.out.println("  This test will send 
"+PERFORMANCE_TEST_ITERATIONS+" "
                        
+(persistence==DeliveryMode.PERSISTENT?"persistent":"non-persistent")+" messages. Each 
with a payload of "
                        +((double)PERFORMANCE_TEST_DATA_PAYLOAD.length/1024)+"Kb"
                        +" Session is "+(!transacted?"NOT":"")+" transacted");
                long startTime = System.currentTimeMillis();
                sendThread.start();
                subscriber.setMessageListener( listener );
                topicConnection.start();
                sendSynchMessage();
                synchronized( listener ) {
                        listener.wait();
                }
                
                if( transacted )
                        session.commit();
                        
                session.close();
                sendThread.join();
                long endTime = System.currentTimeMillis();
                long pTime = endTime-startTime;
                System.out.println("  All threads finished after: 
"+((double)pTime/1000)+" seconds. ");
                
        }
  
        public void runSynchQueuePerformance(final boolean transacted, final int 
persistence) throws Exception {
                
                {
                        queueConnection.start();
                        drainQueue( );
                }
                
                Thread sendThread = new Thread() {
                        public void run() {
                                try {
                                        QueueSession session = 
queueConnection.createQueueSession(transacted, Session.AUTO_ACKNOWLEDGE);
                                        Queue queue = 
(Queue)context.lookup(TEST_QUEUE);
  
                                        QueueSender sender = 
session.createSender(queue);
  
                                        BytesMessage message = 
session.createBytesMessage();
                                        
message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
  
                                        long startTime = System.currentTimeMillis();
                                        for( int i=0; i < PERFORMANCE_TEST_ITERATIONS; 
i++) {
                                                sender.send(queue, message, 
persistence, 4, 0);
                                                //System.out.println("  Sent #"+i);
                                        }
  
                                        if( transacted )
                                                session.commit();
                                        
                                        session.close();
  
                                        long endTime = System.currentTimeMillis();
  
                                        long pTime = endTime-startTime;
                                        System.out.println("  sent all messages in 
"+((double)pTime/1000)+" seconds. ");
                                } catch ( Exception e ) {
                                        e.printStackTrace();
                                }
                        }
                };
  
                Thread recvThread = new Thread() {
                        public void run() {
                                try {
  
                                        QueueSession session = 
queueConnection.createQueueSession(transacted, Session.AUTO_ACKNOWLEDGE);
                                        Queue queue = 
(Queue)context.lookup(TEST_QUEUE);
  
                                        QueueReceiver receiver = 
session.createReceiver(queue);
                                        long startTime = System.currentTimeMillis();
                                        for( int i=0; i < PERFORMANCE_TEST_ITERATIONS; 
i++) {
                                                receiver.receive();
                                                //System.out.println("  Received #"+i);
                                        }
  
                                        if( transacted )
                                                session.commit();
                                        
                                        long endTime = System.currentTimeMillis();
  
                                        session.close();
  
                                        long pTime = endTime-startTime;
                                        System.out.println("  received all messages in 
"+((double)pTime/1000)+" seconds. ");
                                        
                                } catch ( Exception e ) {
                                        e.printStackTrace();
                                }
                        }
                };
                
                System.out.println("  This test will send 
"+PERFORMANCE_TEST_ITERATIONS+" "
                        
+(persistence==DeliveryMode.PERSISTENT?"persistent":"non-persistent")+" messages. Each 
with a payload of "
                        +((double)PERFORMANCE_TEST_DATA_PAYLOAD.length/1024)+"Kb"
                        +" Session is "+(!transacted?"NOT":"")+" transacted");
                long startTime = System.currentTimeMillis();
                sendThread.start();
                recvThread.start();
                sendThread.join();
                recvThread.join();
                long endTime = System.currentTimeMillis();
                long pTime = endTime-startTime;
                System.out.println("  All threads finished after: 
"+((double)pTime/1000)+" seconds. ");
                
        }
  
        public void runSynchTopicPerformance(final boolean transacted, final int 
persistence) throws Exception {
  
                
                {
                        queueConnection.start();
                        topicConnection.start();
                        drainQueue( );
                }
                
                Thread sendThread = new Thread() {
                        public void run() {
                                try {
                                        
                                        
                                        TopicSession session = 
topicConnection.createTopicSession(transacted, Session.AUTO_ACKNOWLEDGE);
                                        Topic topic = 
(Topic)context.lookup(TEST_TOPIC);
  
                                        TopicPublisher publisher = 
session.createPublisher(topic);
  
                                        waitForSynchMessage();
  
                                        BytesMessage message = 
session.createBytesMessage();
                                        
message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
  
                                        long startTime = System.currentTimeMillis();
                                        for( int i=0; i < PERFORMANCE_TEST_ITERATIONS; 
i++) {
                                                publisher.publish(topic, message, 
persistence, 4, 0);
                                                //System.out.println("  Sent #"+i);
                                        }
  
                                        if( transacted )
                                                session.commit();
                                                
                                        long endTime = System.currentTimeMillis();
  
                                        session.close();
  
                                        long pTime = endTime-startTime;
                                        System.out.println("  sent all messages in 
"+((double)pTime/1000)+" seconds. ");
                                } catch ( Exception e ) {
                                        e.printStackTrace();
                                }
                        }
                };
  
                Thread recvThread = new Thread() {
                        public void run() {
                                try {
  
                                        TopicSession session = 
topicConnection.createTopicSession(transacted, Session.AUTO_ACKNOWLEDGE);
                                        Topic topic = 
(Topic)context.lookup(TEST_TOPIC);
                                        TopicSubscriber subscriber = 
session.createSubscriber(topic);
  
                                        sendSynchMessage();
  
                                        long startTime = System.currentTimeMillis();
                                        for( int i=0; i < PERFORMANCE_TEST_ITERATIONS; 
i++) {
                                                subscriber.receive();
                                                //System.out.println("  Received #"+i);
                                        }
  
                                        if( transacted )
                                                session.commit();
                                                
                                        long endTime = System.currentTimeMillis();
  
                                        session.close();
  
                                        long pTime = endTime-startTime;
                                        System.out.println("  received all messages in 
"+((double)pTime/1000)+" seconds. ");
                                        
                                } catch ( Exception e ) {
                                        e.printStackTrace();
                                }
                        }
                };
                
                System.out.println("  This test will send 
"+PERFORMANCE_TEST_ITERATIONS+" "
                        
+(persistence==DeliveryMode.PERSISTENT?"persistent":"non-persistent")+" messages. Each 
with a payload of "
                        +((double)PERFORMANCE_TEST_DATA_PAYLOAD.length/1024)+"Kb"
                        +" Session is "+(!transacted?"NOT":"")+" transacted");
                long startTime = System.currentTimeMillis();
                sendThread.start();
                recvThread.start();
                sendThread.join();
                recvThread.join();
                long endTime = System.currentTimeMillis();
                long pTime = endTime-startTime;
                System.out.println("  All threads finished after: 
"+((double)pTime/1000)+" seconds. ");
                
        }
  
        protected void setUp() throws Exception {
  
                if( context == null ) {
                        
                        context = new InitialContext();
                        
                        QueueConnectionFactory queueFactory = (QueueConnectionFactory) 
context.lookup(QUEUE_FACTORY);
                        queueConnection = queueFactory.createQueueConnection();
  
                        TopicConnectionFactory topicFactory = 
(TopicConnectionFactory)context.lookup(TOPIC_FACTORY);
                        topicConnection = topicFactory.createTopicConnection();
  
                        System.out.println("Connection to spyderMQ established.");
                }
                        
        }
  
        public void testAsynchQueuePerformance() throws Exception {
                
                System.out.println("Starting AsynchQueuePerformance test");
  
                runAsynchQueuePerformance(true, DeliveryMode.NON_PERSISTENT);
                runAsynchQueuePerformance(true, DeliveryMode.PERSISTENT);
                runAsynchQueuePerformance(false, DeliveryMode.NON_PERSISTENT);
                runAsynchQueuePerformance(false, DeliveryMode.PERSISTENT);
                
                System.out.println("AsynchQueuePerformance passed");
        }
  
        public void testAsynchTopicPerformance() throws Exception {
  
                System.out.println("Starting AsynchTopicPerformance test");
  
                runAsynchTopicPerformance(true, DeliveryMode.NON_PERSISTENT);
                runAsynchTopicPerformance(true, DeliveryMode.PERSISTENT);
                runAsynchTopicPerformance(false, DeliveryMode.NON_PERSISTENT);
                runAsynchTopicPerformance(false, DeliveryMode.PERSISTENT);
  
                System.out.println("AsynchTopicPerformance passed");
        }
  
        public void testSynchQueuePerformance() throws Exception {
                
                System.out.println("Starting SynchQueuePerformance test");
                
                runSynchQueuePerformance(true, DeliveryMode.NON_PERSISTENT);
                runSynchQueuePerformance(true, DeliveryMode.PERSISTENT);
                runSynchQueuePerformance(false, DeliveryMode.NON_PERSISTENT);
                runSynchQueuePerformance(false, DeliveryMode.PERSISTENT);
  
                System.out.println("SynchQueuePerformance passed");
        }
  
        public void testSynchTopicPerformance() throws Exception {
  
                System.out.println("Starting SynchTopicPerformance test");
                
                runSynchTopicPerformance(true, DeliveryMode.NON_PERSISTENT);
                runSynchTopicPerformance(true, DeliveryMode.PERSISTENT);
                runSynchTopicPerformance(false, DeliveryMode.NON_PERSISTENT);
                runSynchTopicPerformance(false, DeliveryMode.PERSISTENT);
  
                System.out.println("SynchTopicPerformance passed");
        }
  }
  
  
  

_______________________________________________
Jboss-development mailing list
[EMAIL PROTECTED]
http://lists.sourceforge.net/lists/listinfo/jboss-development

Reply via email to