1 package org.jacorb.test.poa; 2 3 import java.util.Properties ; 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 21 public class QueueNoWaitTest extends CallbackTestCase 22 { 23 private CallbackServer server; 24 25 public QueueNoWaitTest(String name, ClientServerSetup setup) 26 { 27 super(name, setup); 28 } 29 30 public void setUp() throws Exception 31 { 32 server = CallbackServerHelper.narrow( setup.getServerObject() ); 33 } 34 35 public static Test suite() 36 { 37 TestSuite suite = new TestSuite( "Request Queue Overrun - non-waiting" ); 38 39 Properties props = new Properties (); 40 props.setProperty ("jacorb.poa.queue_max", "10"); 41 props.setProperty ("jacorb.poa.queue_min", "1"); 42 props.setProperty ("jacorb.poa.queue_wait", "off"); 43 44 ClientServerSetup setup = 45 new ClientServerSetup( suite, 46 "org.jacorb.test.orb.CallbackServerImpl", 47 null, 48 props ); 49 50 suite.addTest( new QueueNoWaitTest( "test_warm_up", setup ) ); 51 suite.addTest( new QueueNoWaitTest( "test_overrun", setup ) ); 52 53 return setup; 54 } 55 56 private class ReplyHandler 57 extends CallbackTestCase.ReplyHandler 58 implements AMI_CallbackServerHandlerOperations 59 { 60 public void delayed_ping_excep(ExceptionHolder excep_holder) 61 { 62 wrong_exception( "delayed_ping_excep", excep_holder ); 63 } 64 65 public void delayed_ping() 66 { 67 wrong_reply( "delayed_ping" ); 68 } 69 70 public void operation_excep(ExceptionHolder excep_holder) 71 { 72 wrong_exception( "operation_excep", excep_holder ); 73 } 74 75 public void operation(int ami_return_val, char p1, int p2) 76 { 77 wrong_reply( "operation" ); 78 } 79 80 public void pass_in_char_excep(ExceptionHolder excep_holder) 81 { 82 wrong_exception( "pass_in_char_excep", excep_holder ); 83 } 84 85 public void pass_in_char() 86 { 87 wrong_reply( "pass_in_char" ); 88 } 89 90 public void ping_excep(ExceptionHolder excep_holder) 91 { 92 wrong_exception( "ping_excep", excep_holder ); 93 } 94 95 public void ping() 96 { 97 wrong_reply( "ping" ); 98 } 99 100 public void return_char_excep(ExceptionHolder excep_holder) 101 { 102 wrong_exception( "return_char_excep", excep_holder ); 103 } 104 105 public void return_char(char ami_return_val) 106 { 107 wrong_reply( "return_char" ); 108 } 109 110 public void ex_1_excep(ExceptionHolder excep_holder) 111 { 112 wrong_exception( "ex_1_excep", excep_holder ); 113 } 114 115 public void ex_1() 116 { 117 wrong_reply( "ex_1" ); 118 } 119 120 public void ex_2_excep(ExceptionHolder excep_holder) 121 { 122 wrong_exception( "ex_2_excep", excep_holder ); 123 } 124 125 public void ex_2(int ami_return_val, int p) 126 { 127 wrong_reply( "ex_2" ); 128 } 129 130 public void ex_3_excep(ExceptionHolder excep_holder) 131 { 132 wrong_exception( "ex_3_excep", excep_holder ); 133 } 134 135 public void ex_3() 136 { 137 wrong_reply( "ex_3" ); 138 } 139 140 } 141 142 private AMI_CallbackServerHandler ref ( ReplyHandler handler ) 143 { 144 AMI_CallbackServerHandlerPOATie tie = 145 new AMI_CallbackServerHandlerPOATie( handler ) 146 { 147 public org.omg.CORBA.portable.OutputStream 148 _invoke( String method, 149 org.omg.CORBA.portable.InputStream _input, 150 org.omg.CORBA.portable.ResponseHandler handler ) 151 throws org.omg.CORBA.SystemException 152 { 153 try 154 { 155 return super._invoke( method, _input, handler ); 156 } 157 catch( AssertionFailedError e ) 158 { 159 return null; 160 } 161 } 162 }; 163 return tie._this( setup.getClientOrb() ); 164 } 165 166 public void test_warm_up() 167 { 168 server.ping(); 169 } 170 171 174 public void test_overrun() 175 { 176 class Holder { 177 public boolean exceptionReceived = false; 178 } 179 180 final Holder h = new Holder(); 181 182 ReplyHandler handler = new ReplyHandler() 183 { 184 public void delayed_ping_excep (ExceptionHolder excep) 185 { 186 if (getException (excep).getClass().equals 187 (org.omg.CORBA.TRANSIENT .class)) 188 h.exceptionReceived = true; 189 } 190 191 public void delayed_ping() 192 { 193 } 195 }; 196 197 for (int i=0; i < 50; i++) 198 { 199 ( ( _CallbackServerStub ) server ) 200 .sendc_delayed_ping( ref( handler ), 10 ); 201 if (h.exceptionReceived) 202 return; 203 } 204 205 try 206 { 207 Thread.sleep (1000); 208 } 209 catch (InterruptedException ex) 210 {} 211 if (!h.exceptionReceived) 212 fail ("should have raised a TRANSIENT exception"); 213 } 214 215 216 } 217 | Popular Tags |