KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > test > jbossmq > stress > ExceptionListenerTest


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.stress;
23
24 import junit.framework.TestSuite;
25 import junit.framework.Assert;
26
27 import org.jboss.test.jbossmq.MQBase;
28 /**
29  * Exception listener tests-
30  *
31  *
32  * @author <a HREF="mailto:pra@tim.se">Peter Antman</a>
33  * @version $Revision: 37406 $
34  */

35
36 public class ExceptionListenerTest extends MQBase{
37    
38    public ExceptionListenerTest(String JavaDoc name) {
39       super(name);
40    }
41    /*
42      To catch the old typ of error, we need a consumer that has not consumed
43      anything before the server goes down.
44
45      To govern this we need a publisher method to be used in the tests.
46
47      Big question is: when are we satisfyed with the listeners result???
48     */

49
50
51    public void runListener() throws Exception JavaDoc {
52       // Clean testarea up
53
drainTopic();
54
55       int ic = getIterationCount();
56       long sleep = getRunSleep();
57       IntRangeMessageFilter f1 = new IntRangeMessageFilter(javax.jms.Message JavaDoc.class,
58                                                            "FAILSAFE_NR",
59                                                            0,
60                                                            ic);
61       
62       TopicWorker sub1 = new TopicWorker(FAILSAFE_SUBSCRIBER,
63                                          TRANS_NONE,
64                                          f1);
65       Thread JavaDoc t1 = new Thread JavaDoc(sub1);
66       t1.start();
67       
68       // Now we must wait until JBoss has been restarted before we check
69
// messages
70
sleep(5*sleep);
71       log.info("Awakened from sleep");
72       
73       Assert.assertEquals("Subscriber did not get correct number of messages "+sub1.getMessageHandled(), ic,
74                           sub1.getMessageHandled());
75       
76       sub1.setStoped();
77       t1.interrupt();
78       sub1.close();
79
80    }
81
82    public void runPublish() throws Exception JavaDoc {
83       int ic = getIterationCount();
84       // This does NOT work perfect, since both sends will have base 0
85
IntRangeMessageCreator c1 = new IntRangeMessageCreator("FAILSAFE_NR",
86                                                              0);
87       TopicWorker pub1 = new TopicWorker(PUBLISHER,
88                                          TRANS_NONE,
89                                          c1,
90                                          ic/2);
91       pub1.connect();
92       pub1.publish();
93       
94       Assert.assertEquals("Publisher did not publish correct number of messages "+pub1.getMessageHandled(),
95                           ic/2,
96                           pub1.getMessageHandled());
97       
98       
99       pub1.close();
100    }
101    public static junit.framework.Test suite() throws Exception JavaDoc{
102       
103       TestSuite suite= new TestSuite();
104       suite.addTest(new ExceptionListenerTest("runListener"));
105       
106       //suite.addTest(new DurableSubscriberTest("testBadClient"));
107
return suite;
108    }
109    
110    public static void main(String JavaDoc[] args) {
111       
112    }
113    
114 } // ExceptionListenerTest
115
Popular Tags