KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jacorb > test > poa > QueueWaitTest


1 package org.jacorb.test.poa;
2
3 import java.util.Properties JavaDoc;
4
5 import junit.framework.*;
6 import junit.extensions.*;
7
8 import org.jacorb.test.*;
9
10 import org.jacorb.test.common.*;
11 import org.omg.CORBA.*;
12 import org.omg.Messaging.*;
13
14
15 /**
16  * Try to overrun the request queue with queue_wait=on.
17  * Despite a heavy request storm all requests should come through.
18  *
19  * @author <a HREF="mailto:spiegel@gnu.org">Andre Spiegel</a>
20  * @version $Id: QueueWaitTest.java,v 1.2 2004/04/28 12:37:29 brose Exp $
21  */

22 public class QueueWaitTest extends CallbackTestCase
23 {
24     private CallbackServer server;
25
26     public QueueWaitTest(String JavaDoc name, ClientServerSetup setup)
27     {
28         super(name, setup);
29     }
30
31     public void setUp() throws Exception JavaDoc
32     {
33         server = CallbackServerHelper.narrow( setup.getServerObject() );
34     }
35
36     public static Test suite()
37     {
38         TestSuite suite = new TestSuite( "Request Queue Overrun - waiting" );
39
40         Properties JavaDoc props = new Properties JavaDoc();
41         props.setProperty ("jacorb.poa.queue_max", "10");
42         props.setProperty ("jacorb.poa.queue_min", "5");
43         props.setProperty ("jacorb.poa.queue_wait", "on");
44
45         ClientServerSetup setup = new ClientServerSetup
46             ( suite, "org.jacorb.test.orb.CallbackServerImpl",
47               null, props );
48
49         suite.addTest( new QueueWaitTest( "test_warm_up", setup ) );
50         suite.addTest( new QueueWaitTest( "test_overrun", setup ) );
51             
52         return setup;
53     }
54
55     private class ReplyHandler
56         extends CallbackTestCase.ReplyHandler
57         implements AMI_CallbackServerHandlerOperations
58     {
59         public void delayed_ping_excep(ExceptionHolder excep_holder)
60         {
61             wrong_exception( "delayed_ping_excep", excep_holder );
62         }
63
64         public void delayed_ping()
65         {
66             wrong_reply( "delayed_ping" );
67         }
68
69         public void operation_excep(ExceptionHolder excep_holder)
70         {
71             wrong_exception( "operation_excep", excep_holder );
72         }
73
74         public void operation(int ami_return_val, char p1, int p2)
75         {
76             wrong_reply( "operation" );
77         }
78
79         public void pass_in_char_excep(ExceptionHolder excep_holder)
80         {
81             wrong_exception( "pass_in_char_excep", excep_holder );
82         }
83
84         public void pass_in_char()
85         {
86             wrong_reply( "pass_in_char" );
87         }
88
89         public void ping_excep(ExceptionHolder excep_holder)
90         {
91             wrong_exception( "ping_excep", excep_holder );
92         }
93
94         public void ping()
95         {
96             wrong_reply( "ping" );
97         }
98
99         public void return_char_excep(ExceptionHolder excep_holder)
100         {
101             wrong_exception( "return_char_excep", excep_holder );
102         }
103
104         public void return_char(char ami_return_val)
105         {
106             wrong_reply( "return_char" );
107         }
108
109         public void ex_1_excep(ExceptionHolder excep_holder)
110         {
111             wrong_exception( "ex_1_excep", excep_holder );
112         }
113
114         public void ex_1()
115         {
116             wrong_reply( "ex_1" );
117         }
118
119         public void ex_2_excep(ExceptionHolder excep_holder)
120         {
121             wrong_exception( "ex_2_excep", excep_holder );
122         }
123
124         public void ex_2(int ami_return_val, int p)
125         {
126             wrong_reply( "ex_2" );
127         }
128
129         public void ex_3_excep(ExceptionHolder excep_holder)
130         {
131             wrong_exception( "ex_3_excep", excep_holder );
132         }
133
134         public void ex_3()
135         {
136             wrong_reply( "ex_3" );
137         }
138
139     }
140
141     private AMI_CallbackServerHandler ref ( ReplyHandler handler )
142     {
143         AMI_CallbackServerHandlerPOATie tie =
144             new AMI_CallbackServerHandlerPOATie( handler )
145             {
146                 public org.omg.CORBA.portable.OutputStream JavaDoc
147                     _invoke( String JavaDoc method,
148                              org.omg.CORBA.portable.InputStream JavaDoc _input,
149                              org.omg.CORBA.portable.ResponseHandler JavaDoc handler )
150                     throws org.omg.CORBA.SystemException JavaDoc
151                 {
152                     try
153                     {
154                         return super._invoke( method, _input, handler );
155                     }
156                     catch( AssertionFailedError e )
157                     {
158                         return null;
159                     }
160                 }
161             };
162         return tie._this( setup.getClientOrb() );
163     }
164
165     public void test_warm_up()
166     {
167         server.ping();
168     }
169
170     /**
171      * Try to overrun the request queue, expect that all
172      * requests come through without exceptions.
173      */

174     public void test_overrun()
175     {
176         class Holder {
177             public boolean exceptionReceived = false;
178         }
179         final Holder h = new Holder();
180         
181         ReplyHandler handler = new ReplyHandler()
182         {
183             public void delayed_ping_excep (ExceptionHolder excep)
184             {
185                 h.exceptionReceived = true;
186             }
187             
188             public void delayed_ping()
189             {
190                 // ignore
191
}
192         };
193
194         for (int i=0; i < 1000; i++)
195         {
196             ( ( _CallbackServerStub ) server )
197                     .sendc_delayed_ping( ref( handler ), 10 );
198             if (h.exceptionReceived)
199                 fail ("should not have raised an exception");
200         }
201         try
202         {
203             Thread.sleep (1000);
204         }
205         catch (InterruptedException JavaDoc ex)
206         {}
207
208         if (h.exceptionReceived)
209             fail ("should not have raised an exception");
210     }
211     
212
213 }
214
Popular Tags