KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > cts > test > MDBUnitTestCase


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.cts.test;
23
24
25 import javax.jms.Queue JavaDoc;
26 import javax.jms.QueueConnection JavaDoc;
27 import javax.jms.QueueConnectionFactory JavaDoc;
28 import javax.jms.QueueSession JavaDoc;
29 import javax.naming.InitialContext JavaDoc;
30
31 import EDU.oswego.cs.dl.util.concurrent.CountDown;
32 import junit.framework.Test;
33 import org.jboss.test.JBossTestCase;
34
35 /** Basic conformance tests for MDBs
36  *
37  * @author Scott.Stark@jboss.org
38  * @version $Revision: 37406 $
39  */

40 public class MDBUnitTestCase
41    extends JBossTestCase
42 {
43    static final int MAX_SIZE = 20;
44    static String JavaDoc QUEUE_FACTORY = "ConnectionFactory";
45
46    public MDBUnitTestCase (String JavaDoc name)
47    {
48       super(name);
49    }
50
51    public void testPooling() throws Exception JavaDoc
52    {
53       CountDown done = new CountDown(MAX_SIZE);
54       InitialContext JavaDoc ctx = new InitialContext JavaDoc();
55       QueueConnectionFactory JavaDoc factory = (QueueConnectionFactory JavaDoc) ctx.lookup(QUEUE_FACTORY);
56       QueueConnection JavaDoc queConn = factory.createQueueConnection();
57       QueueSession JavaDoc session = queConn.createQueueSession(false, QueueSession.AUTO_ACKNOWLEDGE);
58       Queue JavaDoc queueA = (Queue JavaDoc) ctx.lookup("queue/A");
59       Queue JavaDoc queueB = (Queue JavaDoc) ctx.lookup("queue/B");
60       queConn.start();
61       MDBInvoker[] threads = new MDBInvoker[MAX_SIZE];
62       for(int n = 0; n < MAX_SIZE; n ++)
63       {
64          MDBInvoker t = new MDBInvoker(session, queueA, queueB, n, done, getLog());
65          threads[n] = t;
66          t.start();
67       }
68       assertTrue("Acquired done", done.attempt(1500 * MAX_SIZE));
69       session.close();
70       queConn.close();
71
72       for(int n = 0; n < MAX_SIZE; n ++)
73       {
74          MDBInvoker t = threads[n];
75          if( t.runEx != null )
76          {
77             t.runEx.printStackTrace();
78             fail("Inovker.runEx != null, msg="+t.runEx.getMessage());
79          }
80       }
81    }
82
83    public static Test suite() throws Exception JavaDoc
84    {
85       return getDeploySetup(MDBUnitTestCase.class, "cts.jar");
86    }
87
88 }
89
Popular Tags