KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmq > test > LargeMessageUnitTestCase


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.jbossmq.test;
23
24 import java.util.Properties JavaDoc;
25
26 import javax.jms.BytesMessage JavaDoc;
27 import javax.jms.ExceptionListener JavaDoc;
28 import javax.jms.JMSException 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.TemporaryQueue JavaDoc;
36 import javax.jms.TextMessage JavaDoc;
37
38 import org.jboss.mq.SpyConnectionFactory;
39 import org.jboss.test.JBossTestCase;
40
41 /**
42  * A that a large message doesn't get in the way of ping/pong
43  *
44  * @author Adrian@jboss.org
45  * @version $Revision: 41445 $
46  */

47 public class LargeMessageUnitTestCase extends JBossTestCase implements ExceptionListener JavaDoc
48 {
49
50    private Exception JavaDoc failed = null;
51
52    public LargeMessageUnitTestCase(String JavaDoc name)
53    {
54       super(name);
55    }
56
57    protected void setUp() throws Exception JavaDoc
58    {
59    }
60
61    public void testUIL2LargeMessage() throws Exception JavaDoc
62    {
63       Properties JavaDoc props = new Properties JavaDoc();
64       props.setProperty(
65          org.jboss.mq.il.uil2.UILServerILFactory.SERVER_IL_FACTORY_KEY,
66          org.jboss.mq.il.uil2.UILServerILFactory.SERVER_IL_FACTORY);
67       props.setProperty(
68          org.jboss.mq.il.uil2.UILServerILFactory.CLIENT_IL_SERVICE_KEY,
69          org.jboss.mq.il.uil2.UILServerILFactory.CLIENT_IL_SERVICE);
70       props.setProperty(org.jboss.mq.il.uil2.UILServerILFactory.PING_PERIOD_KEY, "60000");
71       props.setProperty(org.jboss.mq.il.uil2.UILServerILFactory.UIL_ADDRESS_KEY, getServerHost());
72       props.setProperty(org.jboss.mq.il.uil2.UILServerILFactory.UIL_PORT_KEY, "8093");
73       props.setProperty(org.jboss.mq.il.uil2.UILServerILFactory.UIL_BUFFERSIZE_KEY, "1");
74       props.setProperty(org.jboss.mq.il.uil2.UILServerILFactory.UIL_CHUNKSIZE_KEY, "10000");
75
76       runTest(props);
77    }
78
79    public void runTest(Properties JavaDoc props) throws Exception JavaDoc
80    {
81       QueueConnectionFactory JavaDoc cf = new SpyConnectionFactory(props);
82       QueueConnection JavaDoc c = cf.createQueueConnection();
83       TemporaryQueue JavaDoc queue = null;
84       try
85       {
86          failed = null;
87          c.setExceptionListener(this);
88          c.start();
89          QueueSession JavaDoc session = c.createQueueSession(false, Session.AUTO_ACKNOWLEDGE);
90          queue = session.createTemporaryQueue();
91          QueueSender JavaDoc sender = session.createSender(queue);
92          char[] chars = new char[1000000];
93          for (int i = 0; i < chars.length - 1; ++i)
94             chars[i] = 'a';
95          chars[chars.length - 1] = 0;
96          String JavaDoc string = new String JavaDoc(chars);
97          TextMessage JavaDoc message = session.createTextMessage(string);
98          sender.send(message);
99
100          QueueReceiver JavaDoc receiver = session.createReceiver(queue);
101          assertTrue("No message?", receiver.receiveNoWait() != null);
102
103          BytesMessage JavaDoc bytesMessage = session.createBytesMessage();
104          bytesMessage.writeUTF(string);
105          sender.send(bytesMessage);
106
107          assertTrue("No message?", receiver.receiveNoWait() != null);
108
109          assertTrue("We should not get a ping exception because it should pong every chunk: " + failed, failed == null);
110       }
111       finally
112       {
113          c.close();
114       }
115    }
116
117    public void onException(JMSException JavaDoc e)
118    {
119       failed = e;
120    }
121
122    public static void main(java.lang.String JavaDoc[] args)
123    {
124       junit.textui.TestRunner.run(LargeMessageUnitTestCase.class);
125    }
126 }
127
Popular Tags