KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmessaging > perf > JMSPerfStressTestCase


1 /*
2   * JBoss, Home of Professional Open Source
3   * Copyright 2005, JBoss Inc., and individual contributors as indicated
4   * by the @authors tag. See the copyright.txt in the distribution for a
5   * full listing of individual contributors.
6   *
7   * This is free software; you can redistribute it and/or modify it
8   * under the terms of the GNU Lesser General Public License as
9   * published by the Free Software Foundation; either version 2.1 of
10   * the License, or (at your option) any later version.
11   *
12   * This software is distributed in the hope that it will be useful,
13   * but WITHOUT ANY WARRANTY; without even the implied warranty of
14   * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15   * Lesser General Public License for more details.
16   *
17   * You should have received a copy of the GNU Lesser General Public
18   * License along with this software; if not, write to the Free
19   * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20   * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
21   */

22 package org.jboss.test.jbossmessaging.perf;
23
24 import javax.jms.BytesMessage JavaDoc;
25 import javax.jms.DeliveryMode JavaDoc;
26 import javax.jms.JMSException JavaDoc;
27 import javax.jms.Message JavaDoc;
28 import javax.jms.MessageListener JavaDoc;
29 import javax.jms.QueueConnection JavaDoc;
30 import javax.jms.QueueConnectionFactory JavaDoc;
31 import javax.jms.QueueReceiver JavaDoc;
32 import javax.jms.QueueSender JavaDoc;
33 import javax.jms.QueueSession JavaDoc;
34 import javax.jms.Session JavaDoc;
35 import javax.jms.Topic JavaDoc;
36 import javax.jms.TopicConnection JavaDoc;
37 import javax.jms.TopicConnectionFactory JavaDoc;
38 import javax.jms.TopicPublisher JavaDoc;
39 import javax.jms.TopicSession JavaDoc;
40 import javax.jms.TopicSubscriber JavaDoc;
41 import javax.jms.Queue JavaDoc;
42 import javax.naming.Context JavaDoc;
43
44 import org.jboss.logging.Logger;
45 import org.jboss.test.jbossmessaging.JMSTestCase;
46 /**
47  * JMSPerfStressTestCase.java Some simple tests of JMS provider
48  *
49  * @author <a HREF="mailto:richard.achmatowicz@jboss.com">Richard Achmatowicz</a>
50  * @author
51  * @version
52  */

53
54 public class JMSPerfStressTestCase extends JMSTestCase
55 {
56
57    // Provider specific
58
static String JavaDoc TOPIC_FACTORY = "ConnectionFactory";
59    static String JavaDoc QUEUE_FACTORY = "ConnectionFactory";
60
61    static String JavaDoc TEST_QUEUE = "queue/testQueue";
62    static String JavaDoc TEST_TOPIC = "topic/testTopic";
63
64    // static int PERFORMANCE_TEST_ITERATIONS = 1000;
65
static byte[] PERFORMANCE_TEST_DATA_PAYLOAD = new byte[10 * 1024];
66
67    static int TRANS_NONE = 0;
68    static int TRANS_INDIVIDUAL = 1;
69    static int TRANS_TOTAL = 2;
70    static String JavaDoc[] TRANS_DESC = {"NOT", "individually", "totally"};
71
72    //JMSProviderAdapter providerAdapter;
73
static Context JavaDoc context;
74    static QueueConnection JavaDoc queueConnection;
75    static TopicConnection JavaDoc topicConnection;
76
77    /**
78     * Constructor for the JMSPerfStressTestCase object
79     *
80     * @param name Description of Parameter
81     * @exception Exception Description of Exception
82     */

83    public JMSPerfStressTestCase(String JavaDoc name) throws Exception JavaDoc
84    {
85       super(name);
86    }
87
88
89    /**
90     * #Description of the Method
91     *
92     * @param transacted Description of Parameter
93     * @param persistence Description of Parameter
94     * @exception Exception Description of Exception
95     */

96    public void runAsynchQueuePerformance(final int transacted, final int persistence) throws Exception JavaDoc
97    {
98       {
99          queueConnection.start();
100          drainQueue();
101          queueConnection.stop();
102       }
103       final int iterationCount = getIterationCount();
104       final Logger log = getLog();
105
106       Thread JavaDoc sendThread =
107          new Thread JavaDoc()
108          {
109             /**
110              * Main processing method for the JBossMQPerfStressTestCase object
111              */

112             public void run()
113             {
114                try
115                {
116                   QueueSession JavaDoc session = queueConnection.createQueueSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
117                   Queue JavaDoc queue = (Queue JavaDoc)context.lookup(TEST_QUEUE);
118
119                   QueueSender JavaDoc sender = session.createSender(queue);
120
121                   BytesMessage JavaDoc message = session.createBytesMessage();
122                   message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
123
124                   long startTime = System.currentTimeMillis();
125                   for (int i = 0; i < iterationCount; i++)
126                   {
127                      //sender.send(queue, message, persistence, 4, 0);
128
sender.send(message, persistence, 4, 0);
129                      //getLog().debug(" Sent #"+i);
130
if (transacted == TRANS_INDIVIDUAL)
131                      {
132                         session.commit();
133                      }
134                   }
135
136                   if (transacted == TRANS_TOTAL)
137                   {
138                      session.commit();
139                   }
140
141                   long endTime = System.currentTimeMillis();
142
143                   session.close();
144
145                   long pTime = endTime - startTime;
146                   log.debug(" sent all messages in " + ((double)pTime / 1000) + " seconds. ");
147                }
148                catch (Exception JavaDoc e)
149                {
150                   log.error("error", e);
151                }
152             }
153          };
154
155       final QueueSession JavaDoc session = queueConnection.createQueueSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
156       Queue JavaDoc queue = (Queue JavaDoc)context.lookup(TEST_QUEUE);
157       QueueReceiver JavaDoc receiver = session.createReceiver(queue);
158
159       MessageListener JavaDoc listener =
160          new MessageListener JavaDoc()
161          {
162             long startTime = System.currentTimeMillis();
163             int i = 0;
164
165             /**
166              * #Description of the Method
167              *
168              * @param message Description of Parameter
169              */

170             public void onMessage(Message JavaDoc message)
171             {
172                try
173                {
174                 if( transacted == TRANS_INDIVIDUAL )
175                     session.commit();
176                   i++;
177                }
178                catch (JMSException JavaDoc e)
179                {
180                   getLog().error("Unable to commit", e);
181                   synchronized (this)
182                   {
183                      this.notify();
184                   }
185                }
186                if (i >= iterationCount)
187                {
188                   long endTime = System.currentTimeMillis();
189                   long pTime = endTime - startTime;
190                   log.debug(" received all messages in " + ((double)pTime / 1000) + " seconds. ");
191
192                   synchronized (this)
193                   {
194                      this.notify();
195                   }
196                }
197             }
198          };
199
200       getLog().debug(" Asynch Queue: This test will send " + getIterationCount() + " "
201              + (persistence == DeliveryMode.PERSISTENT ? "persistent" : "non-persistent") + " messages. Each with a payload of "
202              + ((double)PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024) + "Kb"
203              + " Session is " + TRANS_DESC[transacted] + " transacted");
204       long startTime = System.currentTimeMillis();
205       sendThread.start();
206       receiver.setMessageListener(listener);
207       synchronized (listener)
208       {
209          queueConnection.start();
210          listener.wait();
211       }
212
213       if (transacted == TRANS_TOTAL)
214       {
215          session.commit();
216       }
217
218       session.close();
219       sendThread.join();
220       long endTime = System.currentTimeMillis();
221       long pTime = endTime - startTime;
222       getLog().debug(" All threads finished after: " + ((double)pTime / 1000) + " seconds. ");
223
224    }
225
226    /**
227     * #Description of the Method
228     *
229     * @param transacted Description of Parameter
230     * @param persistence Description of Parameter
231     * @exception Exception Description of Exception
232     */

233    public void runAsynchTopicPerformance(final int transacted, final int persistence) throws Exception JavaDoc
234    {
235       {
236          queueConnection.start();
237          drainQueue();
238       }
239
240       final int iterationCount = getIterationCount();
241       final Logger log = getLog();
242
243       Thread JavaDoc sendThread =
244          new Thread JavaDoc()
245          {
246             /**
247              * Main processing method for the JMSPerfStressTestCase object
248              */

249             public void run()
250             {
251                try
252                {
253
254                   TopicSession JavaDoc session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
255                   Topic JavaDoc topic = (Topic JavaDoc)context.lookup(TEST_TOPIC);
256
257                   TopicPublisher JavaDoc publisher = session.createPublisher(topic);
258
259                   waitForSynchMessage();
260
261                   BytesMessage JavaDoc message = session.createBytesMessage();
262                   message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
263
264                   long startTime = System.currentTimeMillis();
265                   for (int i = 0; i < iterationCount; i++)
266                   {
267                      publisher.publish(message, persistence, 4, 0);
268                      //publisher.publish(topic, message, persistence, 4, 0);
269
//getLog().debug(" Sent #"+i);
270
if (transacted == TRANS_INDIVIDUAL)
271                      {
272                         session.commit();
273                      }
274                   }
275
276                   if (transacted == TRANS_TOTAL)
277                   {
278                      session.commit();
279                   }
280
281                   long endTime = System.currentTimeMillis();
282                   session.close();
283
284                   long pTime = endTime - startTime;
285                   log.debug(" sent all messages in " + ((double)pTime / 1000) + " seconds. ");
286                }
287                catch (Exception JavaDoc e)
288                {
289                   log.error("error", e);
290                }
291             }
292          };
293
294       final TopicSession JavaDoc session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
295       Topic JavaDoc topic = (Topic JavaDoc)context.lookup(TEST_TOPIC);
296       TopicSubscriber JavaDoc subscriber = session.createSubscriber(topic);
297
298       MessageListener JavaDoc listener =
299          new MessageListener JavaDoc()
300          {
301             long startTime = System.currentTimeMillis();
302             int i = 0;
303
304             /**
305              * #Description of the Method
306              *
307              * @param message Description of Parameter
308              */

309             public void onMessage(Message JavaDoc message)
310             {
311                try
312                {
313                 if( transacted == TRANS_INDIVIDUAL )
314                     session.commit();
315                   i++;
316                }
317                catch (JMSException JavaDoc e)
318                {
319                   getLog().error("Unable to commit", e);
320                   synchronized (this)
321                   {
322                      this.notify();
323                   }
324                }
325                if (i >= iterationCount)
326                {
327                   long endTime = System.currentTimeMillis();
328                   long pTime = endTime - startTime;
329                   log.debug(" received all messages in " + ((double)pTime / 1000) + " seconds. ");
330
331                   synchronized (this)
332                   {
333                      this.notify();
334                   }
335                }
336             }
337          };
338
339       getLog().debug(" Asynch Topic: This test will send " + getIterationCount() + " "
340              + (persistence == DeliveryMode.PERSISTENT ? "persistent" : "non-persistent") + " messages. Each with a payload of "
341              + ((double)PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024) + "Kb"
342              + " Session is " + TRANS_DESC[transacted] + " transacted");
343       long startTime = System.currentTimeMillis();
344       sendThread.start();
345       subscriber.setMessageListener(listener);
346       sendSynchMessage();
347       synchronized (listener)
348       {
349          topicConnection.start();
350          listener.wait();
351       }
352
353       if (transacted == TRANS_TOTAL)
354       {
355          session.commit();
356       }
357
358       session.close();
359       sendThread.join();
360       long endTime = System.currentTimeMillis();
361       long pTime = endTime - startTime;
362       getLog().debug(" All threads finished after: " + ((double)pTime / 1000) + " seconds. ");
363
364    }
365
366    /**
367     * #Description of the Method
368     *
369     * @param transacted Description of Parameter
370     * @param persistence Description of Parameter
371     * @exception Exception Description of Exception
372     */

373    public void runSynchQueuePerformance(final int transacted, final int persistence) throws Exception JavaDoc
374    {
375       {
376          queueConnection.start();
377          drainQueue();
378       }
379       final int iterationCount = getIterationCount();
380       final Logger log = getLog();
381
382       Thread JavaDoc sendThread =
383          new Thread JavaDoc()
384          {
385             /**
386              * Main processing method for the JMSPerfStressTestCase object
387              */

388             public void run()
389             {
390                try
391                {
392                   QueueSession JavaDoc session = queueConnection.createQueueSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
393                   Queue JavaDoc queue = (Queue JavaDoc)context.lookup(TEST_QUEUE);
394
395                   QueueSender JavaDoc sender = session.createSender(queue);
396
397                   BytesMessage JavaDoc message = session.createBytesMessage();
398                   message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
399
400                   long startTime = System.currentTimeMillis();
401                   for (int i = 0; i < iterationCount; i++)
402                   {
403                      sender.send( message, persistence, 4, 0);
404                      //sender.send(queue, message, persistence, 4, 0);
405
//getLog().debug(" Sent #"+i);
406
if (transacted == TRANS_INDIVIDUAL)
407                      {
408                         session.commit();
409                      }
410                   }
411
412                   if (transacted == TRANS_TOTAL)
413                   {
414                      session.commit();
415                   }
416
417                   session.close();
418
419                   long endTime = System.currentTimeMillis();
420
421                   long pTime = endTime - startTime;
422                   log.debug(" sent all messages in " + ((double)pTime / 1000) + " seconds. ");
423                }
424                catch (Exception JavaDoc e)
425                {
426                   log.error("error", e);
427                }
428             }
429          };
430
431       Thread JavaDoc recvThread =
432          new Thread JavaDoc()
433          {
434             /**
435              * Main processing method for the JMSPerfStressTestCase object
436              */

437             public void run()
438             {
439                try
440                {
441
442                   QueueSession JavaDoc session = queueConnection.createQueueSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
443                   Queue JavaDoc queue = (Queue JavaDoc)context.lookup(TEST_QUEUE);
444
445                   QueueReceiver JavaDoc receiver = session.createReceiver(queue);
446                   long startTime = System.currentTimeMillis();
447                   for (int i = 0; i < iterationCount; i++)
448                   {
449                      receiver.receive();
450                      //getLog().debug(" Received #"+i);
451
if (transacted == TRANS_INDIVIDUAL)
452                      {
453                         session.commit();
454                      }
455                   }
456
457                   if (transacted == TRANS_TOTAL)
458                   {
459                      session.commit();
460                   }
461
462                   long endTime = System.currentTimeMillis();
463
464                   session.close();
465
466                   long pTime = endTime - startTime;
467                   log.debug(" received all messages in " + ((double)pTime / 1000) + " seconds. ");
468
469                }
470                catch (Exception JavaDoc e)
471                {
472                   log.error("error", e);
473                }
474             }
475          };
476
477       getLog().debug(" Synch Queue: This test will send " + getIterationCount() + " "
478              + (persistence == DeliveryMode.PERSISTENT ? "persistent" : "non-persistent") + " messages. Each with a payload of "
479              + ((double)PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024) + "Kb"
480              + " Session is " + TRANS_DESC[transacted] + " transacted");
481       long startTime = System.currentTimeMillis();
482       sendThread.start();
483       recvThread.start();
484       sendThread.join();
485       recvThread.join();
486       long endTime = System.currentTimeMillis();
487       long pTime = endTime - startTime;
488       getLog().debug(" All threads finished after: " + ((double)pTime / 1000) + " seconds. ");
489
490    }
491
492    /**
493     * #Description of the Method
494     *
495     * @param transacted Description of Parameter
496     * @param persistence Description of Parameter
497     * @exception Exception Description of Exception
498     */

499    public void runSynchTopicPerformance(final int transacted, final int persistence) throws Exception JavaDoc
500    {
501       {
502          queueConnection.start();
503          topicConnection.start();
504          drainQueue();
505       }
506       final int iterationCount = getIterationCount();
507       final Logger log = getLog();
508
509       Thread JavaDoc sendThread =
510          new Thread JavaDoc()
511          {
512             /**
513              * Main processing method for the JBossMQPerfStressTestCase object
514              */

515             public void run()
516             {
517                try
518                {
519
520                   TopicSession JavaDoc session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
521                   Topic JavaDoc topic = (Topic JavaDoc)context.lookup(TEST_TOPIC);
522
523                   TopicPublisher JavaDoc publisher = session.createPublisher(topic);
524
525                   waitForSynchMessage();
526
527                   BytesMessage JavaDoc message = session.createBytesMessage();
528                   message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
529
530                   long startTime = System.currentTimeMillis();
531                   for (int i = 0; i < iterationCount; i++)
532                   {
533                      publisher.publish(message, persistence, 4, 0);
534                      //publisher.publish(topic, message, persistence, 4, 0);
535
//getLog().debug(" Sent #"+i);
536
if (transacted == TRANS_INDIVIDUAL)
537                      {
538                         session.commit();
539                      }
540                   }
541
542                   if (transacted == TRANS_TOTAL)
543                   {
544                      session.commit();
545                   }
546
547                   long endTime = System.currentTimeMillis();
548
549                   session.close();
550
551                   long pTime = endTime - startTime;
552                   log.debug(" sent all messages in " + ((double)pTime / 1000) + " seconds. ");
553                }
554                catch (Exception JavaDoc e)
555                {
556                   log.error("error", e);
557                }
558             }
559          };
560
561       Thread JavaDoc recvThread =
562          new Thread JavaDoc()
563          {
564             /**
565              * Main processing method for the JBossMQPerfStressTestCase object
566              */

567             public void run()
568             {
569                try
570                {
571
572                   TopicSession JavaDoc session = topicConnection.createTopicSession(transacted != TRANS_NONE, Session.AUTO_ACKNOWLEDGE);
573                   Topic JavaDoc topic = (Topic JavaDoc)context.lookup(TEST_TOPIC);
574                   TopicSubscriber JavaDoc subscriber = session.createSubscriber(topic);
575
576                   sendSynchMessage();
577
578                   long startTime = System.currentTimeMillis();
579                   for (int i = 0; i < iterationCount; i++)
580                   {
581                      subscriber.receive();
582                      //getLog().debug(" Received #"+i);
583
if (transacted == TRANS_INDIVIDUAL)
584                      {
585                         session.commit();
586                      }
587                   }
588
589                   if (transacted == TRANS_TOTAL)
590                   {
591                      session.commit();
592                   }
593
594                   long endTime = System.currentTimeMillis();
595
596                   session.close();
597
598                   long pTime = endTime - startTime;
599                   log.debug(" received all messages in " + ((double)pTime / 1000) + " seconds. ");
600
601                }
602                catch (Exception JavaDoc e)
603                {
604                   log.error("error", e);
605                }
606             }
607          };
608
609       getLog().debug(" Synch Topic: This test will send " + getIterationCount() + " "
610              + (persistence == DeliveryMode.PERSISTENT ? "persistent" : "non-persistent") + " messages. Each with a payload of "
611              + ((double)PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024) + "Kb"
612              + " Session is " + TRANS_DESC[transacted] + " transacted");
613       long startTime = System.currentTimeMillis();
614       sendThread.start();
615       recvThread.start();
616       sendThread.join();
617       recvThread.join();
618       long endTime = System.currentTimeMillis();
619       long pTime = endTime - startTime;
620       getLog().debug(" All threads finished after: " + ((double)pTime / 1000) + " seconds. ");
621
622    }
623
624    /**
625     * A unit test for JUnit
626     *
627     * @exception Exception Description of Exception
628     */

629    public void testAsynchQueuePerformance() throws Exception JavaDoc
630    {
631
632       getLog().debug("Starting AsynchQueuePerformance test");
633
634       runAsynchQueuePerformance(TRANS_NONE, DeliveryMode.NON_PERSISTENT);
635       runAsynchQueuePerformance(TRANS_NONE, DeliveryMode.PERSISTENT);
636       runAsynchQueuePerformance(TRANS_INDIVIDUAL, DeliveryMode.NON_PERSISTENT);
637       runAsynchQueuePerformance(TRANS_INDIVIDUAL, DeliveryMode.PERSISTENT);
638       runAsynchQueuePerformance(TRANS_TOTAL, DeliveryMode.NON_PERSISTENT);
639       runAsynchQueuePerformance(TRANS_TOTAL, DeliveryMode.PERSISTENT);
640
641       getLog().debug("AsynchQueuePerformance passed");
642    }
643
644    /**
645     * A unit test for JUnit
646     *
647     * @exception Exception Description of Exception
648     */

649    public void testAsynchTopicPerformance() throws Exception JavaDoc
650    {
651
652       getLog().debug("Starting AsynchTopicPerformance test");
653
654       runAsynchTopicPerformance(TRANS_NONE, DeliveryMode.NON_PERSISTENT);
655       runAsynchTopicPerformance(TRANS_NONE, DeliveryMode.PERSISTENT);
656       runAsynchTopicPerformance(TRANS_INDIVIDUAL, DeliveryMode.NON_PERSISTENT);
657       runAsynchTopicPerformance(TRANS_INDIVIDUAL, DeliveryMode.PERSISTENT);
658       runAsynchTopicPerformance(TRANS_TOTAL, DeliveryMode.NON_PERSISTENT);
659       runAsynchTopicPerformance(TRANS_TOTAL, DeliveryMode.PERSISTENT);
660
661       getLog().debug("AsynchTopicPerformance passed");
662    }
663
664    /**
665     * A unit test for JUnit
666     *
667     * @exception Exception Description of Exception
668     */

669    public void testSynchQueuePerformance() throws Exception JavaDoc
670    {
671
672       getLog().debug("Starting SynchQueuePerformance test");
673
674       runSynchQueuePerformance(TRANS_NONE, DeliveryMode.NON_PERSISTENT);
675       runSynchQueuePerformance(TRANS_NONE, DeliveryMode.PERSISTENT);
676       runSynchQueuePerformance(TRANS_INDIVIDUAL, DeliveryMode.NON_PERSISTENT);
677       runSynchQueuePerformance(TRANS_INDIVIDUAL, DeliveryMode.PERSISTENT);
678       runSynchQueuePerformance(TRANS_TOTAL, DeliveryMode.NON_PERSISTENT);
679       runSynchQueuePerformance(TRANS_TOTAL, DeliveryMode.PERSISTENT);
680
681       getLog().debug("SynchQueuePerformance passed");
682    }
683
684    /**
685     * A unit test for JUnit
686     *
687     * @exception Exception Description of Exception
688     */

689    public void testSynchTopicPerformance() throws Exception JavaDoc
690    {
691
692       getLog().debug("Starting SynchTopicPerformance test");
693
694       runSynchTopicPerformance(TRANS_NONE, DeliveryMode.NON_PERSISTENT);
695       runSynchTopicPerformance(TRANS_NONE, DeliveryMode.PERSISTENT);
696       runSynchTopicPerformance(TRANS_INDIVIDUAL, DeliveryMode.NON_PERSISTENT);
697       runSynchTopicPerformance(TRANS_INDIVIDUAL, DeliveryMode.PERSISTENT);
698       runSynchTopicPerformance(TRANS_TOTAL, DeliveryMode.NON_PERSISTENT);
699       runSynchTopicPerformance(TRANS_TOTAL, DeliveryMode.PERSISTENT);
700
701       getLog().debug("SynchTopicPerformance passed");
702    }
703
704    /**
705     * The JUnit setup method
706     *
707     * @exception Exception Description of Exception
708     */

709    protected void setUp() throws Exception JavaDoc
710    {
711        // perform any setUp() required by the base class
712
super.setUp() ;
713
714       if (context == null)
715       {
716       Logger log = getLog() ;
717       if (log == null)
718           System.out.println("JMSPerfStressTestCase: getLog() returned null") ;
719
720      getLog().debug("JMSPerfStresTestCase - setUp") ;
721      
722          context = getInitialContext();
723
724          QueueConnectionFactory JavaDoc queueFactory = (QueueConnectionFactory JavaDoc)context.lookup(QUEUE_FACTORY);
725          queueConnection = queueFactory.createQueueConnection();
726
727          TopicConnectionFactory JavaDoc topicFactory = (TopicConnectionFactory JavaDoc)context.lookup(TOPIC_FACTORY);
728          topicConnection = topicFactory.createTopicConnection();
729
730          getLog().debug("Connection to JMS provider established.");
731       }
732
733    }
734
735
736    // Emptys out all the messages in a queue
737
private void drainQueue() throws Exception JavaDoc
738    {
739
740       QueueSession JavaDoc session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
741       Queue JavaDoc queue = (Queue JavaDoc)context.lookup(TEST_QUEUE);
742
743       QueueReceiver JavaDoc receiver = session.createReceiver(queue);
744       Message JavaDoc message = receiver.receive(50);
745       int c = 0;
746       while (message != null)
747       {
748          message = receiver.receive(50);
749          c++;
750       }
751
752       if (c != 0)
753       {
754          getLog().debug(" Drained " + c + " messages from the queue");
755       }
756
757       session.close();
758
759    }
760
761    private void waitForSynchMessage() throws Exception JavaDoc
762    {
763       QueueSession JavaDoc session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
764       Queue JavaDoc queue = (Queue JavaDoc)context.lookup(TEST_QUEUE);
765
766       QueueReceiver JavaDoc receiver = session.createReceiver(queue);
767       receiver.receive();
768       session.close();
769    }
770
771    private void sendSynchMessage() throws Exception JavaDoc
772    {
773       QueueSession JavaDoc session = queueConnection.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
774       Queue JavaDoc queue = (Queue JavaDoc)context.lookup(TEST_QUEUE);
775
776       QueueSender JavaDoc sender = session.createSender(queue);
777
778       Message JavaDoc message = session.createMessage();
779       sender.send(message);
780
781       session.close();
782    }
783
784    /**
785     * The main entry-point for the JMSPerfStressTestCase class
786     *
787     * @param args The command line arguments
788     */

789    public static void main(String JavaDoc[] args)
790    {
791
792       String JavaDoc newArgs[] = {"org.jboss.test.jbossmessaging.perf.JMSPerfStressTestCase"};
793       junit.swingui.TestRunner.main(newArgs);
794
795    }
796
797    public static junit.framework.Test suite() throws Exception JavaDoc
798    {
799        ClassLoader JavaDoc loader = Thread.currentThread().getContextClassLoader();
800        String JavaDoc resourceName = getJMSResourceRelativePathname("test-destinations-service.xml") ;
801
802        return getDeploySetup(JMSPerfStressTestCase.class,
803                loader.getResource(resourceName).toString());
804    }
805 }
806
Popular Tags