Source Code Cross Referenced for JBossMQPerfStressTestCase.java in  » EJB-Server-JBoss-4.2.1 » testsuite » org » jboss » test » jbossmq » perf » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » EJB Server JBoss 4.2.1 » testsuite » org.jboss.test.jbossmq.perf 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * JBoss, Home of Professional Open Source.
003:         * Copyright 2006, Red Hat Middleware LLC, and individual contributors
004:         * as indicated by the @author tags. See the copyright.txt file in the
005:         * distribution for a full listing of individual contributors.
006:         *
007:         * This is free software; you can redistribute it and/or modify it
008:         * under the terms of the GNU Lesser General Public License as
009:         * published by the Free Software Foundation; either version 2.1 of
010:         * the License, or (at your option) any later version.
011:         *
012:         * This software is distributed in the hope that it will be useful,
013:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
014:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
015:         * Lesser General Public License for more details.
016:         *
017:         * You should have received a copy of the GNU Lesser General Public
018:         * License along with this software; if not, write to the Free
019:         * Software Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA, or see the FSF site: http://www.fsf.org.
021:         */
022:        package org.jboss.test.jbossmq.perf;
023:
024:        import javax.jms.BytesMessage;
025:        import javax.jms.DeliveryMode;
026:        import javax.jms.JMSException;
027:        import javax.jms.Message;
028:        import javax.jms.MessageListener;
029:        import javax.jms.QueueConnection;
030:        import javax.jms.QueueConnectionFactory;
031:        import javax.jms.QueueReceiver;
032:        import javax.jms.QueueSender;
033:        import javax.jms.QueueSession;
034:        import javax.jms.Session;
035:        import javax.jms.Topic;
036:        import javax.jms.TopicConnection;
037:        import javax.jms.TopicConnectionFactory;
038:        import javax.jms.TopicPublisher;
039:        import javax.jms.TopicSession;
040:        import javax.jms.TopicSubscriber;
041:        import javax.jms.Queue;
042:        import javax.naming.Context;
043:
044:        import org.apache.log4j.Category;
045:        import org.jboss.test.JBossTestCase;
046:
047:        /**
048:         * JBossMQPerfStressTestCase.java Some simple tests of JBossMQ
049:         *
050:         * @author
051:         * @version
052:         */
053:
054:        public class JBossMQPerfStressTestCase extends JBossTestCase {
055:
056:            // Provider specific
057:            static String TOPIC_FACTORY = "ConnectionFactory";
058:            static String QUEUE_FACTORY = "ConnectionFactory";
059:
060:            static String TEST_QUEUE = "queue/testQueue";
061:            static String TEST_TOPIC = "topic/testTopic";
062:
063:            //   static int PERFORMANCE_TEST_ITERATIONS = 1000;
064:            static byte[] PERFORMANCE_TEST_DATA_PAYLOAD = new byte[10 * 1024];
065:
066:            static int TRANS_NONE = 0;
067:            static int TRANS_INDIVIDUAL = 1;
068:            static int TRANS_TOTAL = 2;
069:            static String[] TRANS_DESC = { "NOT", "individually", "totally" };
070:
071:            //JMSProviderAdapter providerAdapter;
072:            static Context context;
073:            static QueueConnection queueConnection;
074:            static TopicConnection topicConnection;
075:
076:            /**
077:             * Constructor for the JBossMQPerfStressTestCase object
078:             *
079:             * @param name           Description of Parameter
080:             * @exception Exception  Description of Exception
081:             */
082:            public JBossMQPerfStressTestCase(String name) throws Exception {
083:                super (name);
084:            }
085:
086:            /**
087:             * #Description of the Method
088:             *
089:             * @param transacted     Description of Parameter
090:             * @param persistence    Description of Parameter
091:             * @exception Exception  Description of Exception
092:             */
093:            public void runAsynchQueuePerformance(final int transacted,
094:                    final int persistence) throws Exception {
095:                {
096:                    queueConnection.start();
097:                    drainQueue();
098:                    queueConnection.stop();
099:                }
100:                final int iterationCount = getIterationCount();
101:                final Category log = getLog();
102:
103:                Thread sendThread = new Thread() {
104:                    /**
105:                     * Main processing method for the JBossMQPerfStressTestCase object
106:                     */
107:                    public void run() {
108:                        try {
109:                            QueueSession session = queueConnection
110:                                    .createQueueSession(
111:                                            transacted != TRANS_NONE,
112:                                            Session.AUTO_ACKNOWLEDGE);
113:                            Queue queue = (Queue) context.lookup(TEST_QUEUE);
114:
115:                            QueueSender sender = session.createSender(queue);
116:
117:                            BytesMessage message = session.createBytesMessage();
118:                            message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
119:
120:                            long startTime = System.currentTimeMillis();
121:                            for (int i = 0; i < iterationCount; i++) {
122:                                //sender.send(queue, message, persistence, 4, 0);
123:                                sender.send(message, persistence, 4, 0);
124:                                //getLog().debug("  Sent #"+i);
125:                                if (transacted == TRANS_INDIVIDUAL) {
126:                                    session.commit();
127:                                }
128:                            }
129:
130:                            if (transacted == TRANS_TOTAL) {
131:                                session.commit();
132:                            }
133:
134:                            long endTime = System.currentTimeMillis();
135:
136:                            session.close();
137:
138:                            long pTime = endTime - startTime;
139:                            log.debug("  sent all messages in "
140:                                    + ((double) pTime / 1000) + " seconds. ");
141:                        } catch (Exception e) {
142:                            log.error("error", e);
143:                        }
144:                    }
145:                };
146:
147:                final QueueSession session = queueConnection
148:                        .createQueueSession(transacted != TRANS_NONE,
149:                                Session.AUTO_ACKNOWLEDGE);
150:                Queue queue = (Queue) context.lookup(TEST_QUEUE);
151:                QueueReceiver receiver = session.createReceiver(queue);
152:
153:                MessageListener listener = new MessageListener() {
154:                    long startTime = System.currentTimeMillis();
155:                    int i = 0;
156:
157:                    /**
158:                     * #Description of the Method
159:                     *
160:                     * @param message  Description of Parameter
161:                     */
162:                    public void onMessage(Message message) {
163:                        try {
164:                            if (transacted == TRANS_INDIVIDUAL)
165:                                session.commit();
166:                            i++;
167:                        } catch (JMSException e) {
168:                            getLog().error("Unable to commit", e);
169:                            synchronized (this ) {
170:                                this .notify();
171:                            }
172:                        }
173:                        if (i >= iterationCount) {
174:                            long endTime = System.currentTimeMillis();
175:                            long pTime = endTime - startTime;
176:                            log.debug("  received all messages in "
177:                                    + ((double) pTime / 1000) + " seconds. ");
178:
179:                            synchronized (this ) {
180:                                this .notify();
181:                            }
182:                        }
183:                    }
184:                };
185:
186:                getLog()
187:                        .debug(
188:                                "  Asynch Queue: This test will send "
189:                                        + getIterationCount()
190:                                        + " "
191:                                        + (persistence == DeliveryMode.PERSISTENT ? "persistent"
192:                                                : "non-persistent")
193:                                        + " messages. Each with a payload of "
194:                                        + ((double) PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024)
195:                                        + "Kb" + " Session is "
196:                                        + TRANS_DESC[transacted]
197:                                        + " transacted");
198:                long startTime = System.currentTimeMillis();
199:                sendThread.start();
200:                receiver.setMessageListener(listener);
201:                synchronized (listener) {
202:                    queueConnection.start();
203:                    listener.wait();
204:                }
205:
206:                if (transacted == TRANS_TOTAL) {
207:                    session.commit();
208:                }
209:
210:                session.close();
211:                sendThread.join();
212:                long endTime = System.currentTimeMillis();
213:                long pTime = endTime - startTime;
214:                getLog().debug(
215:                        "  All threads finished after: "
216:                                + ((double) pTime / 1000) + " seconds. ");
217:
218:            }
219:
220:            /**
221:             * #Description of the Method
222:             *
223:             * @param transacted     Description of Parameter
224:             * @param persistence    Description of Parameter
225:             * @exception Exception  Description of Exception
226:             */
227:            public void runAsynchTopicPerformance(final int transacted,
228:                    final int persistence) throws Exception {
229:                {
230:                    queueConnection.start();
231:                    drainQueue();
232:                }
233:
234:                final int iterationCount = getIterationCount();
235:                final Category log = getLog();
236:
237:                Thread sendThread = new Thread() {
238:                    /**
239:                     * Main processing method for the JBossMQPerfStressTestCase object
240:                     */
241:                    public void run() {
242:                        try {
243:
244:                            TopicSession session = topicConnection
245:                                    .createTopicSession(
246:                                            transacted != TRANS_NONE,
247:                                            Session.AUTO_ACKNOWLEDGE);
248:                            Topic topic = (Topic) context.lookup(TEST_TOPIC);
249:
250:                            TopicPublisher publisher = session
251:                                    .createPublisher(topic);
252:
253:                            waitForSynchMessage();
254:
255:                            BytesMessage message = session.createBytesMessage();
256:                            message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
257:
258:                            long startTime = System.currentTimeMillis();
259:                            for (int i = 0; i < iterationCount; i++) {
260:                                publisher.publish(message, persistence, 4, 0);
261:                                //publisher.publish(topic, message, persistence, 4, 0);
262:                                //getLog().debug("  Sent #"+i);
263:                                if (transacted == TRANS_INDIVIDUAL) {
264:                                    session.commit();
265:                                }
266:                            }
267:
268:                            if (transacted == TRANS_TOTAL) {
269:                                session.commit();
270:                            }
271:
272:                            long endTime = System.currentTimeMillis();
273:                            session.close();
274:
275:                            long pTime = endTime - startTime;
276:                            log.debug("  sent all messages in "
277:                                    + ((double) pTime / 1000) + " seconds. ");
278:                        } catch (Exception e) {
279:                            log.error("error", e);
280:                        }
281:                    }
282:                };
283:
284:                final TopicSession session = topicConnection
285:                        .createTopicSession(transacted != TRANS_NONE,
286:                                Session.AUTO_ACKNOWLEDGE);
287:                Topic topic = (Topic) context.lookup(TEST_TOPIC);
288:                TopicSubscriber subscriber = session.createSubscriber(topic);
289:
290:                MessageListener listener = new MessageListener() {
291:                    long startTime = System.currentTimeMillis();
292:                    int i = 0;
293:
294:                    /**
295:                     * #Description of the Method
296:                     *
297:                     * @param message  Description of Parameter
298:                     */
299:                    public void onMessage(Message message) {
300:                        try {
301:                            if (transacted == TRANS_INDIVIDUAL)
302:                                session.commit();
303:                            i++;
304:                        } catch (JMSException e) {
305:                            getLog().error("Unable to commit", e);
306:                            synchronized (this ) {
307:                                this .notify();
308:                            }
309:                        }
310:                        if (i >= iterationCount) {
311:                            long endTime = System.currentTimeMillis();
312:                            long pTime = endTime - startTime;
313:                            log.debug("  received all messages in "
314:                                    + ((double) pTime / 1000) + " seconds. ");
315:
316:                            synchronized (this ) {
317:                                this .notify();
318:                            }
319:                        }
320:                    }
321:                };
322:
323:                getLog()
324:                        .debug(
325:                                "  Asynch Topic: This test will send "
326:                                        + getIterationCount()
327:                                        + " "
328:                                        + (persistence == DeliveryMode.PERSISTENT ? "persistent"
329:                                                : "non-persistent")
330:                                        + " messages. Each with a payload of "
331:                                        + ((double) PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024)
332:                                        + "Kb" + " Session is "
333:                                        + TRANS_DESC[transacted]
334:                                        + " transacted");
335:                long startTime = System.currentTimeMillis();
336:                sendThread.start();
337:                subscriber.setMessageListener(listener);
338:                sendSynchMessage();
339:                synchronized (listener) {
340:                    topicConnection.start();
341:                    listener.wait();
342:                }
343:
344:                if (transacted == TRANS_TOTAL) {
345:                    session.commit();
346:                }
347:
348:                session.close();
349:                sendThread.join();
350:                long endTime = System.currentTimeMillis();
351:                long pTime = endTime - startTime;
352:                getLog().debug(
353:                        "  All threads finished after: "
354:                                + ((double) pTime / 1000) + " seconds. ");
355:
356:            }
357:
358:            /**
359:             * #Description of the Method
360:             *
361:             * @param transacted     Description of Parameter
362:             * @param persistence    Description of Parameter
363:             * @exception Exception  Description of Exception
364:             */
365:            public void runSynchQueuePerformance(final int transacted,
366:                    final int persistence) throws Exception {
367:                {
368:                    queueConnection.start();
369:                    drainQueue();
370:                }
371:                final int iterationCount = getIterationCount();
372:                final Category log = getLog();
373:
374:                Thread sendThread = new Thread() {
375:                    /**
376:                     * Main processing method for the JBossMQPerfStressTestCase object
377:                     */
378:                    public void run() {
379:                        try {
380:                            QueueSession session = queueConnection
381:                                    .createQueueSession(
382:                                            transacted != TRANS_NONE,
383:                                            Session.AUTO_ACKNOWLEDGE);
384:                            Queue queue = (Queue) context.lookup(TEST_QUEUE);
385:
386:                            QueueSender sender = session.createSender(queue);
387:
388:                            BytesMessage message = session.createBytesMessage();
389:                            message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
390:
391:                            long startTime = System.currentTimeMillis();
392:                            for (int i = 0; i < iterationCount; i++) {
393:                                sender.send(message, persistence, 4, 0);
394:                                //sender.send(queue, message, persistence, 4, 0);
395:                                //getLog().debug("  Sent #"+i);
396:                                if (transacted == TRANS_INDIVIDUAL) {
397:                                    session.commit();
398:                                }
399:                            }
400:
401:                            if (transacted == TRANS_TOTAL) {
402:                                session.commit();
403:                            }
404:
405:                            session.close();
406:
407:                            long endTime = System.currentTimeMillis();
408:
409:                            long pTime = endTime - startTime;
410:                            log.debug("  sent all messages in "
411:                                    + ((double) pTime / 1000) + " seconds. ");
412:                        } catch (Exception e) {
413:                            log.error("error", e);
414:                        }
415:                    }
416:                };
417:
418:                Thread recvThread = new Thread() {
419:                    /**
420:                     * Main processing method for the JBossMQPerfStressTestCase object
421:                     */
422:                    public void run() {
423:                        try {
424:
425:                            QueueSession session = queueConnection
426:                                    .createQueueSession(
427:                                            transacted != TRANS_NONE,
428:                                            Session.AUTO_ACKNOWLEDGE);
429:                            Queue queue = (Queue) context.lookup(TEST_QUEUE);
430:
431:                            QueueReceiver receiver = session
432:                                    .createReceiver(queue);
433:                            long startTime = System.currentTimeMillis();
434:                            for (int i = 0; i < iterationCount; i++) {
435:                                receiver.receive();
436:                                //getLog().debug("  Received #"+i);
437:                                if (transacted == TRANS_INDIVIDUAL) {
438:                                    session.commit();
439:                                }
440:                            }
441:
442:                            if (transacted == TRANS_TOTAL) {
443:                                session.commit();
444:                            }
445:
446:                            long endTime = System.currentTimeMillis();
447:
448:                            session.close();
449:
450:                            long pTime = endTime - startTime;
451:                            log.debug("  received all messages in "
452:                                    + ((double) pTime / 1000) + " seconds. ");
453:
454:                        } catch (Exception e) {
455:                            log.error("error", e);
456:                        }
457:                    }
458:                };
459:
460:                getLog()
461:                        .debug(
462:                                "  Synch Queue: This test will send "
463:                                        + getIterationCount()
464:                                        + " "
465:                                        + (persistence == DeliveryMode.PERSISTENT ? "persistent"
466:                                                : "non-persistent")
467:                                        + " messages. Each with a payload of "
468:                                        + ((double) PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024)
469:                                        + "Kb" + " Session is "
470:                                        + TRANS_DESC[transacted]
471:                                        + " transacted");
472:                long startTime = System.currentTimeMillis();
473:                sendThread.start();
474:                recvThread.start();
475:                sendThread.join();
476:                recvThread.join();
477:                long endTime = System.currentTimeMillis();
478:                long pTime = endTime - startTime;
479:                getLog().debug(
480:                        "  All threads finished after: "
481:                                + ((double) pTime / 1000) + " seconds. ");
482:
483:            }
484:
485:            /**
486:             * #Description of the Method
487:             *
488:             * @param transacted     Description of Parameter
489:             * @param persistence    Description of Parameter
490:             * @exception Exception  Description of Exception
491:             */
492:            public void runSynchTopicPerformance(final int transacted,
493:                    final int persistence) throws Exception {
494:                {
495:                    queueConnection.start();
496:                    topicConnection.start();
497:                    drainQueue();
498:                }
499:                final int iterationCount = getIterationCount();
500:                final Category log = getLog();
501:
502:                Thread sendThread = new Thread() {
503:                    /**
504:                     * Main processing method for the JBossMQPerfStressTestCase object
505:                     */
506:                    public void run() {
507:                        try {
508:
509:                            TopicSession session = topicConnection
510:                                    .createTopicSession(
511:                                            transacted != TRANS_NONE,
512:                                            Session.AUTO_ACKNOWLEDGE);
513:                            Topic topic = (Topic) context.lookup(TEST_TOPIC);
514:
515:                            TopicPublisher publisher = session
516:                                    .createPublisher(topic);
517:
518:                            waitForSynchMessage();
519:
520:                            BytesMessage message = session.createBytesMessage();
521:                            message.writeBytes(PERFORMANCE_TEST_DATA_PAYLOAD);
522:
523:                            long startTime = System.currentTimeMillis();
524:                            for (int i = 0; i < iterationCount; i++) {
525:                                publisher.publish(message, persistence, 4, 0);
526:                                //publisher.publish(topic, message, persistence, 4, 0);
527:                                //getLog().debug("  Sent #"+i);
528:                                if (transacted == TRANS_INDIVIDUAL) {
529:                                    session.commit();
530:                                }
531:                            }
532:
533:                            if (transacted == TRANS_TOTAL) {
534:                                session.commit();
535:                            }
536:
537:                            long endTime = System.currentTimeMillis();
538:
539:                            session.close();
540:
541:                            long pTime = endTime - startTime;
542:                            log.debug("  sent all messages in "
543:                                    + ((double) pTime / 1000) + " seconds. ");
544:                        } catch (Exception e) {
545:                            log.error("error", e);
546:                        }
547:                    }
548:                };
549:
550:                Thread recvThread = new Thread() {
551:                    /**
552:                     * Main processing method for the JBossMQPerfStressTestCase object
553:                     */
554:                    public void run() {
555:                        try {
556:
557:                            TopicSession session = topicConnection
558:                                    .createTopicSession(
559:                                            transacted != TRANS_NONE,
560:                                            Session.AUTO_ACKNOWLEDGE);
561:                            Topic topic = (Topic) context.lookup(TEST_TOPIC);
562:                            TopicSubscriber subscriber = session
563:                                    .createSubscriber(topic);
564:
565:                            sendSynchMessage();
566:
567:                            long startTime = System.currentTimeMillis();
568:                            for (int i = 0; i < iterationCount; i++) {
569:                                subscriber.receive();
570:                                //getLog().debug("  Received #"+i);
571:                                if (transacted == TRANS_INDIVIDUAL) {
572:                                    session.commit();
573:                                }
574:                            }
575:
576:                            if (transacted == TRANS_TOTAL) {
577:                                session.commit();
578:                            }
579:
580:                            long endTime = System.currentTimeMillis();
581:
582:                            session.close();
583:
584:                            long pTime = endTime - startTime;
585:                            log.debug("  received all messages in "
586:                                    + ((double) pTime / 1000) + " seconds. ");
587:
588:                        } catch (Exception e) {
589:                            log.error("error", e);
590:                        }
591:                    }
592:                };
593:
594:                getLog()
595:                        .debug(
596:                                "  Synch Topic: This test will send "
597:                                        + getIterationCount()
598:                                        + " "
599:                                        + (persistence == DeliveryMode.PERSISTENT ? "persistent"
600:                                                : "non-persistent")
601:                                        + " messages. Each with a payload of "
602:                                        + ((double) PERFORMANCE_TEST_DATA_PAYLOAD.length / 1024)
603:                                        + "Kb" + " Session is "
604:                                        + TRANS_DESC[transacted]
605:                                        + " transacted");
606:                long startTime = System.currentTimeMillis();
607:                sendThread.start();
608:                recvThread.start();
609:                sendThread.join();
610:                recvThread.join();
611:                long endTime = System.currentTimeMillis();
612:                long pTime = endTime - startTime;
613:                getLog().debug(
614:                        "  All threads finished after: "
615:                                + ((double) pTime / 1000) + " seconds. ");
616:
617:            }
618:
619:            /**
620:             * A unit test for JUnit
621:             *
622:             * @exception Exception  Description of Exception
623:             */
624:            public void testAsynchQueuePerformance() throws Exception {
625:
626:                getLog().debug("Starting AsynchQueuePerformance test");
627:
628:                runAsynchQueuePerformance(TRANS_NONE,
629:                        DeliveryMode.NON_PERSISTENT);
630:                runAsynchQueuePerformance(TRANS_NONE, DeliveryMode.PERSISTENT);
631:                runAsynchQueuePerformance(TRANS_INDIVIDUAL,
632:                        DeliveryMode.NON_PERSISTENT);
633:                runAsynchQueuePerformance(TRANS_INDIVIDUAL,
634:                        DeliveryMode.PERSISTENT);
635:                runAsynchQueuePerformance(TRANS_TOTAL,
636:                        DeliveryMode.NON_PERSISTENT);
637:                runAsynchQueuePerformance(TRANS_TOTAL, DeliveryMode.PERSISTENT);
638:
639:                getLog().debug("AsynchQueuePerformance passed");
640:            }
641:
642:            /**
643:             * A unit test for JUnit
644:             *
645:             * @exception Exception  Description of Exception
646:             */
647:            public void testAsynchTopicPerformance() throws Exception {
648:
649:                getLog().debug("Starting AsynchTopicPerformance test");
650:
651:                runAsynchTopicPerformance(TRANS_NONE,
652:                        DeliveryMode.NON_PERSISTENT);
653:                runAsynchTopicPerformance(TRANS_NONE, DeliveryMode.PERSISTENT);
654:                runAsynchTopicPerformance(TRANS_INDIVIDUAL,
655:                        DeliveryMode.NON_PERSISTENT);
656:                runAsynchTopicPerformance(TRANS_INDIVIDUAL,
657:                        DeliveryMode.PERSISTENT);
658:                runAsynchTopicPerformance(TRANS_TOTAL,
659:                        DeliveryMode.NON_PERSISTENT);
660:                runAsynchTopicPerformance(TRANS_TOTAL, DeliveryMode.PERSISTENT);
661:
662:                getLog().debug("AsynchTopicPerformance passed");
663:            }
664:
665:            /**
666:             * A unit test for JUnit
667:             *
668:             * @exception Exception  Description of Exception
669:             */
670:            public void testSynchQueuePerformance() throws Exception {
671:
672:                getLog().debug("Starting SynchQueuePerformance test");
673:
674:                runSynchQueuePerformance(TRANS_NONE,
675:                        DeliveryMode.NON_PERSISTENT);
676:                runSynchQueuePerformance(TRANS_NONE, DeliveryMode.PERSISTENT);
677:                runSynchQueuePerformance(TRANS_INDIVIDUAL,
678:                        DeliveryMode.NON_PERSISTENT);
679:                runSynchQueuePerformance(TRANS_INDIVIDUAL,
680:                        DeliveryMode.PERSISTENT);
681:                runSynchQueuePerformance(TRANS_TOTAL,
682:                        DeliveryMode.NON_PERSISTENT);
683:                runSynchQueuePerformance(TRANS_TOTAL, DeliveryMode.PERSISTENT);
684:
685:                getLog().debug("SynchQueuePerformance passed");
686:            }
687:
688:            /**
689:             * A unit test for JUnit
690:             *
691:             * @exception Exception  Description of Exception
692:             */
693:            public void testSynchTopicPerformance() throws Exception {
694:
695:                getLog().debug("Starting SynchTopicPerformance test");
696:
697:                runSynchTopicPerformance(TRANS_NONE,
698:                        DeliveryMode.NON_PERSISTENT);
699:                runSynchTopicPerformance(TRANS_NONE, DeliveryMode.PERSISTENT);
700:                runSynchTopicPerformance(TRANS_INDIVIDUAL,
701:                        DeliveryMode.NON_PERSISTENT);
702:                runSynchTopicPerformance(TRANS_INDIVIDUAL,
703:                        DeliveryMode.PERSISTENT);
704:                runSynchTopicPerformance(TRANS_TOTAL,
705:                        DeliveryMode.NON_PERSISTENT);
706:                runSynchTopicPerformance(TRANS_TOTAL, DeliveryMode.PERSISTENT);
707:
708:                getLog().debug("SynchTopicPerformance passed");
709:            }
710:
711:            /**
712:             * The JUnit setup method
713:             *
714:             * @exception Exception  Description of Exception
715:             */
716:            protected void setUp() throws Exception {
717:                if (context == null) {
718:
719:                    context = getInitialContext();
720:
721:                    QueueConnectionFactory queueFactory = (QueueConnectionFactory) context
722:                            .lookup(QUEUE_FACTORY);
723:                    queueConnection = queueFactory.createQueueConnection();
724:
725:                    TopicConnectionFactory topicFactory = (TopicConnectionFactory) context
726:                            .lookup(TOPIC_FACTORY);
727:                    topicConnection = topicFactory.createTopicConnection();
728:
729:                    getLog().debug("Connection to JBossMQ established.");
730:                }
731:
732:            }
733:
734:            // Emptys out all the messages in a queue
735:            private void drainQueue() throws Exception {
736:
737:                QueueSession session = queueConnection.createQueueSession(
738:                        false, Session.AUTO_ACKNOWLEDGE);
739:                Queue queue = (Queue) context.lookup(TEST_QUEUE);
740:
741:                QueueReceiver receiver = session.createReceiver(queue);
742:                Message message = receiver.receive(50);
743:                int c = 0;
744:                while (message != null) {
745:                    message = receiver.receive(50);
746:                    c++;
747:                }
748:
749:                if (c != 0) {
750:                    getLog().debug(
751:                            "  Drained " + c + " messages from the queue");
752:                }
753:
754:                session.close();
755:
756:            }
757:
758:            private void waitForSynchMessage() throws Exception {
759:                QueueSession session = queueConnection.createQueueSession(
760:                        false, Session.AUTO_ACKNOWLEDGE);
761:                Queue queue = (Queue) context.lookup(TEST_QUEUE);
762:
763:                QueueReceiver receiver = session.createReceiver(queue);
764:                receiver.receive();
765:                session.close();
766:            }
767:
768:            private void sendSynchMessage() throws Exception {
769:                QueueSession session = queueConnection.createQueueSession(
770:                        false, Session.AUTO_ACKNOWLEDGE);
771:                Queue queue = (Queue) context.lookup(TEST_QUEUE);
772:
773:                QueueSender sender = session.createSender(queue);
774:
775:                Message message = session.createMessage();
776:                sender.send(message);
777:
778:                session.close();
779:            }
780:
781:            /**
782:             * The main entry-point for the JBossMQPerfStressTestCase class
783:             *
784:             * @param args  The command line arguments
785:             */
786:            public static void main(String[] args) {
787:
788:                String newArgs[] = { "org.jboss.test.jbossmq.perf.JBossMQPerfStressTestCase" };
789:                junit.swingui.TestRunner.main(newArgs);
790:
791:            }
792:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.