View Javadoc

1   /**
2    * 
3    */
4   package test.crispy.impl;
5   
6   import java.math.BigDecimal;
7   import java.util.Date;
8   import java.util.Properties;
9   import java.util.Vector;
10  
11  import junit.framework.TestCase;
12  import net.sf.crispy.IServiceManager;
13  import net.sf.crispy.InvocationException;
14  import net.sf.crispy.Property;
15  import net.sf.crispy.impl.RmiExecutor;
16  import net.sf.crispy.impl.ServiceManager;
17  import net.sf.crispy.impl.StaticRmiProxy;
18  import net.sf.crispy.impl.rmi.MiniRmiServer;
19  import net.sf.crispy.impl.rmi.RmiInvocationHandler;
20  import net.sf.crispy.interceptor.StopWatchInterceptor;
21  import net.sf.crispy.strategy.ClassWithOutPackageInvocationStrategy;
22  import test.crispy.concurrent.AsynchronousCallbackForTests;
23  import test.crispy.example.interceptor.WaitInterceptor;
24  import test.crispy.example.model.Adresse;
25  import test.crispy.example.model.Kunde;
26  import test.crispy.example.model.Primitive;
27  import test.crispy.example.modify.CalculatorModifierAfter;
28  import test.crispy.example.modify.CalculatorModifierBefore;
29  import test.crispy.example.service.Calculator;
30  import test.crispy.example.service.CalculatorImpl;
31  import test.crispy.example.service.Echo;
32  import test.crispy.example.service.EchoImpl;
33  import test.crispy.example.service.RemoteCalculator;
34  import test.crispy.example.service.RemoteCalculatorImpl;
35  import test.crispy.example.service.RemoteEcho;
36  import test.crispy.example.service.RemoteEchoImpl;
37  
38  /**
39   * @author Linke
40   *
41   */
42  public class StaticRmiTest extends TestCase {
43  	
44  	
45  	private static MiniRmiServer miniRmiServer = new MiniRmiServer();
46  
47  	public StaticRmiTest() {
48  	}
49  	
50  	protected void setUp() throws Exception {
51  		super.setUp();
52  		if (MiniRmiServer.isStarted() == false) {			
53  			miniRmiServer.addService(RemoteCalculatorImpl.LOOKUP_NAME, RemoteCalculatorImpl.class.getName());
54  			miniRmiServer.addService(RemoteEchoImpl.LOOKUP_NAME, RemoteEchoImpl.class.getName());
55  
56  			miniRmiServer.addService(Echo.class.getName(), EchoImpl.class.getName());
57  			miniRmiServer.addService(Calculator.class.getName(), CalculatorImpl.class.getName());
58  
59  			miniRmiServer.addService("RemoteCalculator", RemoteCalculatorImpl.class.getName());
60  			miniRmiServer.addService("RemoteEcho", RemoteEchoImpl.class.getName());
61  			
62  			miniRmiServer.start();
63  		}
64  	}
65  
66  	protected void tearDown() throws Exception {
67  		super.tearDown();
68  		miniRmiServer.stop();
69  	}
70  	
71  	
72  	private Properties getProperties () {
73  		Properties prop = new Properties();
74  		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
75  		prop.put(RemoteCalculator.class.getName(), RemoteCalculator.LOOKUP_NAME);
76  		return prop;
77  	}
78  	
79      public void testEchoPrimitive() throws Exception {
80      	Properties prop = new Properties();
81  		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
82  		prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
83      	
84          ServiceManager lvServiceManager = new ServiceManager(prop);
85          RemoteEcho lvEcho = (RemoteEcho) lvServiceManager.createService(RemoteEcho.class);
86          Primitive lvPrimitive = Primitive.createPrimitiveExample();
87          
88          Primitive lvPrimitiveAfter = lvEcho.echoPrimitive(lvPrimitive);
89          assertEquals(lvPrimitive, lvPrimitiveAfter);
90          assertNotSame(lvPrimitive, lvPrimitiveAfter);
91  	}
92  
93  	private void makeCalculatorTest (IServiceManager pvManager) throws Exception {
94  		RemoteCalculator lvCalculator = (RemoteCalculator) pvManager.createService(RemoteCalculator.class);
95  		int ret = lvCalculator.add(5, 4);
96  		assertTrue(ret == 9);
97  		ret = lvCalculator.subtract(7, 3);
98  		assertTrue(ret == 4);				
99  	}
100 	
101 	public void testSimpleRemotePing() throws Exception {
102 		Properties prop = new Properties();
103 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
104 		prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
105     	
106 		ServiceManager manager = new ServiceManager(prop);
107 		RemoteEcho lvEcho = (RemoteEcho)  manager.createService(RemoteEcho.class);
108 		String lvPing = lvEcho.ping();
109 		assertEquals(lvPing, Echo.PING_STRING);
110 	}
111 	
112 	
113 	public void testSimpleService() throws Exception {
114 		Properties prop = getProperties ();
115 		makeCalculatorTest( new ServiceManager(prop));
116 	}
117 
118 	public void testDoubleService() throws Exception {
119 		Properties prop = getProperties ();
120 		prop.put(RmiInvocationHandler.class.getName(), RmiExecutor.LOOKUP_NAME);
121 		IServiceManager manager = new ServiceManager(prop);
122 		makeCalculatorTest(manager);
123 		RmiInvocationHandler rmiHandeler = (RmiInvocationHandler) manager.createService(RmiInvocationHandler.class);
124 		Vector params = new Vector();
125 		String lvEchoStr = "Hello Echo";
126 		params.add(lvEchoStr);
127 		String lvReturn = (String) rmiHandeler.invoke(Echo.class.getName(), "echo", params);
128 		assertEquals(lvEchoStr, lvReturn);
129 	}
130 	
131 	public void testRmiTestWithDynamicJdkProxy() throws Exception {
132 		Properties prop = getProperties ();
133 		prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
134 		makeCalculatorTest( new ServiceManager(prop));
135 	}
136 
137 	public void testRmiTestWithDynamicCglibProxy() throws Exception {
138 		Properties prop = getProperties ();
139 		prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_CGLIB_DYNAMIC_PROXY);
140 		try {
141 			makeCalculatorTest( new ServiceManager(prop));
142 //			fail("The DynamicCglibProxy can not work with final classes.");
143 		} catch (InvocationException e) { assertTrue(true);}
144 	}
145 	
146     public void testSimpleRemoteInvocationWithOutDynamicJdkProxy() throws Exception {
147 		Properties prop = getProperties ();
148         prop.put(Property.INTERCEPTOR_CLASS, WaitInterceptor.class.getName());
149         prop.put(Property.INTERCEPTOR_CLASS_2, StopWatchInterceptor.class.getName());		
150 		
151 		ServiceManager lvManager = new ServiceManager(prop);
152 		makeCalculatorTest(lvManager);
153 		StopWatchInterceptor lvStopWatchInterceptor = (StopWatchInterceptor) lvManager.getInterceptorByPos(1);
154 		long lvStopTime = lvStopWatchInterceptor.getStopTimeInvokeMethod();
155 		assertTrue("StopTime is: " + lvStopTime, lvStopTime > 10);
156 		
157 		lvManager.removeInterceptorByPos(0);
158 		lvManager.removeInterceptorByPos(0);
159 		makeCalculatorTest(lvManager);
160 		assertEquals(lvStopTime, lvStopWatchInterceptor.getStopTimeInvokeMethod());
161 
162 		lvStopWatchInterceptor.clearStopTimeInvokeMethod();
163 		makeCalculatorTest(lvManager);
164 		lvStopTime = lvStopWatchInterceptor.getStopTimeInvokeMethod();
165 		assertEquals(lvStopTime, 0);		
166     }
167 	
168 
169     public void testCycleDetectionTest() throws Exception {
170     	Properties prop = getProperties ();
171         prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
172         
173         ServiceManager lvServiceManager = new ServiceManager(prop);
174 		RemoteEcho lvEcho = (RemoteEcho) lvServiceManager.createService(RemoteEcho.class);
175 		
176 		Kunde k = new Kunde("Mario");
177 		k.setGehalt(new BigDecimal(12.34));
178 		Adresse a = new Adresse();
179 		a.setOrt("Magdebrug");
180 		a.setPlz("39104");
181 		k.getAdressen().add(a);
182 		a.setKunde(k);
183 		
184 		String lvRenameName = "Nadine";
185 		Kunde kAfter = lvEcho.renameKunde(k, lvRenameName);
186 		assertEquals(kAfter.getName(), lvRenameName);
187 		
188 		Kunde kTemp = ((Adresse) kAfter.getAdressen().get(0)).getKunde();
189 		assertEquals(kAfter, kTemp);
190 	}
191 	
192     public void testProxyInterceptor() throws Exception {
193         Properties prop = getProperties ();
194         prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
195 		prop.put(Property.INTERCEPTOR_CLASS, WaitInterceptor.class.getName());
196 		prop.put(Property.INTERCEPTOR_CLASS_2, StopWatchInterceptor.class.getName());
197 
198 		
199 		IServiceManager manager = new ServiceManager(prop);
200 		makeCalculatorTest(manager);
201 		WaitInterceptor lvWaitInterceptor = (WaitInterceptor) manager.getInterceptorByPos(0);
202 		assertNotNull(lvWaitInterceptor);
203 		StopWatchInterceptor stopWatch = (StopWatchInterceptor) manager.getInterceptorByPos(1);
204 		assertTrue(stopWatch.getStopTimeInvokeMethod() > 10);
205 		assertTrue(stopWatch.getStopTimeNewInstance() > 10);
206     }
207 
208     public void testBeforeModifyService() throws Exception {
209     	Properties prop = getProperties ();
210     	prop.put(Property.MODIFIER_CLASS, CalculatorModifierBefore.class.getName());
211     	prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
212     	
213 		IServiceManager manager = new ServiceManager(prop);
214 		RemoteCalculator lvCalculator = (RemoteCalculator) manager.createService(RemoteCalculator.class);
215 		int ret = lvCalculator.add(5, 6);
216 		int val = CalculatorModifierBefore.NEW_ADD_VALUE.intValue() + CalculatorModifierBefore.NEW_ADD_VALUE.intValue();
217 		assertTrue(ret == val);
218     }
219     
220     public void testAfterModifyService() throws Exception {
221     	Properties prop = getProperties ();
222     	prop.put(Property.MODIFIER_CLASS, CalculatorModifierAfter.class.getName());
223     	prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
224     	
225 		IServiceManager manager = new ServiceManager(prop);
226 		RemoteCalculator lvCalculator = (RemoteCalculator) manager.createService(RemoteCalculator.class);
227 		int ret = lvCalculator.add(5, 6);
228 		int val = CalculatorModifierAfter.NEW_ADD_VALUE.intValue();
229 		assertTrue(ret == val);
230     }
231 
232     public void testAddLongs() throws Exception {
233     	Properties prop = new Properties();
234 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
235 		prop.put(RemoteCalculator.class.getName(), RemoteCalculator.LOOKUP_NAME);
236 
237     	
238 		ServiceManager manager = new ServiceManager(prop);
239 		RemoteCalculator calc =  (RemoteCalculator) manager.createService(RemoteCalculator.class);
240 		assertEquals(calc.addLong(123l, 124l), 247);
241 	}    
242 
243     public void testOverloading() throws Exception {
244 		Properties prop = new Properties();
245 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
246 		prop.put(RemoteCalculator.class.getName(), RemoteCalculator.LOOKUP_NAME);
247 		
248 		ServiceManager manager = new ServiceManager(prop);
249 		RemoteCalculator lvCalculator = (RemoteCalculator) manager.createService(RemoteCalculator.class);
250 		int lvIntResult = lvCalculator.add(2, 3);
251 		assertEquals(lvIntResult, 5);
252 		long lvLongResult = lvCalculator.add(21, 32);
253 		assertEquals(lvLongResult, 53);
254 		double lvDoubleResult = lvCalculator.add(2.3, 3.2);
255 		assertEquals(lvDoubleResult, 5.5, 0);
256     }
257 
258     public void testOverloadingInteger() throws Exception {
259 		Properties prop = new Properties();
260 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
261 		prop.put(RemoteCalculator.class.getName(), RemoteCalculator.LOOKUP_NAME);
262 		
263 		ServiceManager manager = new ServiceManager(prop);
264 		RemoteCalculator lvCalculator = (RemoteCalculator) manager.createService(RemoteCalculator.class);
265 		Integer i[] = lvCalculator.echoArray(new Integer[] {new Integer(1), new Integer(3), new Integer(5)});
266 		assertTrue(i.length == 3);
267 		assertEquals(i[0], new Integer(1));
268 		assertEquals(i[1], new Integer(3));
269 		assertEquals(i[2], new Integer(5));
270 	}
271     
272     public void testOverloadingLong() throws Exception {
273 		Properties prop = new Properties();
274 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
275 		prop.put(RemoteCalculator.class.getName(), RemoteCalculator.LOOKUP_NAME);
276 		
277 		ServiceManager manager = new ServiceManager(prop);
278 		RemoteCalculator lvCalculator = (RemoteCalculator) manager.createService(RemoteCalculator.class);
279 		Long l[] = lvCalculator.echoArray(new Long[] {new Long(1), new Long(5)});
280 		assertTrue(l.length == 2);
281 		assertEquals(l[0], new Long(1));
282 		assertEquals(l[1], new Long(5));
283 	}
284 
285     public void testOverloadingObject() throws Exception {
286 		Properties prop = new Properties();
287 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
288 		prop.put(RemoteCalculator.class.getName(), RemoteCalculator.LOOKUP_NAME);
289 		
290 		ServiceManager manager = new ServiceManager(prop);
291 		RemoteCalculator lvCalculator = (RemoteCalculator) manager.createService(RemoteCalculator.class);
292 		Object o[] = lvCalculator.echoArray(new Object[] {"a", new Integer(3), new Long(5)});
293 		assertTrue(o.length == 3);
294 		assertEquals(o[0], "a");
295 		assertEquals(o[1], new Integer(3));
296 		assertEquals(o[2], new Long(5)); // is Integer
297 	}
298     
299 
300     public void testSetInvocationStrategy() throws Exception {
301         Properties prop = new Properties();
302 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
303         prop.put(Property.INVOCATION_STRATEGY, ClassWithOutPackageInvocationStrategy.class.getName());
304         prop.put(RemoteCalculator.class.getName(), "RemoteCalculator");
305         prop.put(RemoteEcho.class.getName(), "RemoteEcho");
306 
307         ServiceManager lvManager = new ServiceManager(prop);
308 
309         RemoteCalculator lvCalculator = (RemoteCalculator) lvManager.createService(RemoteCalculator.class);
310 		int lvResult = lvCalculator.add(2, 3);		
311 		assertEquals(lvResult, 5);
312 		
313 		RemoteEcho lvEcho = (RemoteEcho) lvManager.createService(RemoteEcho.class);
314 		String lvEchoString = "Hello Crispy ...";
315 		assertEquals(lvEchoString, lvEcho.echo(lvEchoString));
316         
317 		
318 		miniRmiServer.removeService("RemoteCalculator");
319         try {
320         	lvCalculator = (RemoteCalculator) lvManager.createService(RemoteCalculator.class);
321     		lvResult = lvCalculator.add(2, 3);
322     		fail("FAIL, no RemoteCalculator registered by MiniRmiServer!");
323 		} catch (Exception e) {
324 			assertTrue(true);
325 		}
326 	}
327     
328     public void testCreateService() throws Exception {
329         Properties prop = new Properties();
330 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
331         prop.put(RemoteCalculator.class.getName(), RemoteCalculator.LOOKUP_NAME);
332         
333         ServiceManager lvManager = new ServiceManager(prop);
334         RemoteCalculator lvCalculator1 = (RemoteCalculator) lvManager.createService(RemoteCalculator.class);
335         RemoteCalculator lvCalculator2 = (RemoteCalculator) lvManager.createService(RemoteCalculator.class);
336         
337         assertNotNull(lvCalculator1);
338         assertNotNull(lvCalculator2);
339         assertNotSame(lvCalculator1, lvCalculator2);
340 	}
341 
342     public void testThrowException() throws Exception {
343         Properties prop = new Properties();
344 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
345         prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
346 		
347 		ServiceManager lvManager = new ServiceManager(prop);
348 
349 		RemoteEcho lvEcho = (RemoteEcho) lvManager.createService(RemoteEcho.class);
350 		boolean throwException = false;
351 		try {
352 			lvEcho.throwException("A Test-Excption.");
353 		} catch (Exception e) {
354 			throwException = true;
355 		}
356 		assertTrue("No Exception thrown: " + throwException, throwException);
357 	}
358 
359     public void testNoLookupNameSet() throws Exception {
360 		Properties prop = new Properties();
361 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
362 
363 		ServiceManager lvManager = new ServiceManager(prop);
364 		try {
365 			lvManager.createService(RemoteEcho.class);
366 			fail("Must thrown Exception: No LookUp Name");
367 		} catch (Exception e) {
368 			assertTrue(true);
369 		}
370 	}
371     
372     public void testNotValideLookupNameSet() throws Exception {
373 		Properties prop = new Properties();
374 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
375 		prop.put(RemoteEcho.class.getName(), "NotValideLookUpName");
376 		
377 		ServiceManager lvManager = new ServiceManager(prop);
378 		try {
379 			lvManager.createService(RemoteEcho.class);
380 			fail("Must thrown Exception: No LookUp Name");
381 		} catch (Exception e) {
382 			assertTrue(true);
383 		}
384 	}
385     
386     public void testNullValueParamsWithException() throws Exception {
387         Properties prop = new Properties();
388 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
389         prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
390         
391 		ServiceManager lvManager = new ServiceManager(prop);
392 
393 		RemoteEcho lvEcho = (RemoteEcho) lvManager.createService(RemoteEcho.class);
394 		String s = lvEcho.echo(null);
395 		assertNull(s);
396 	}
397 
398     public void testNullLongValueParams() throws Exception {
399         Properties prop = new Properties();
400         prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
401         prop.put(RemoteCalculator.class.getName(), RemoteCalculator.LOOKUP_NAME);
402         
403 		ServiceManager lvManager = new ServiceManager(prop);
404 
405 		RemoteCalculator lvCalculator = (RemoteCalculator) lvManager.createService(RemoteCalculator.class);
406 		Long lvLong = lvCalculator.addLong((Long) null, (Long) null);
407 		assertNull(lvLong);
408 	}
409 
410     public void testNullComplexValueParams() throws Exception {
411         Properties prop = new Properties();
412 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
413         prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
414 		
415 		ServiceManager lvManager = new ServiceManager(prop);
416 
417 		RemoteEcho lvEcho = (RemoteEcho) lvManager.createService(RemoteEcho.class);
418 		Kunde k = lvEcho.renameKunde(null, null);
419 		assertNull(k);
420 	}
421 
422 	public void testTransferDate() throws Exception {
423 		Properties prop = new Properties();
424 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
425 		prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
426 		
427 		ServiceManager manager = new ServiceManager(prop);
428 		RemoteEcho lvEcho =  (RemoteEcho) manager.createService(RemoteEcho.class);
429 		
430 		Kunde k = new Kunde("JUnit-Test-Name");
431 		Date d = new Date();
432 		k.setDate(d);
433 		Kunde k2 = lvEcho.renameKunde(k, "Rename-Test");
434 		assertNotNull(k2.getDate());
435 		assertEquals(k.getDate(), k2.getDate());
436 	}
437 
438     
439     
440     
441     
442     
443     
444     
445 	public void testAsynchronousInvocation() throws Exception {
446 		Properties prop = new Properties();
447 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
448         prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
449         prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
450 		prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName());
451 		
452 		ServiceManager manager = new ServiceManager(prop);
453 		RemoteEcho echo =  (RemoteEcho) manager.createService(RemoteEcho.class);
454 		String lvPing = echo.ping();
455 		assertNull(lvPing);
456 		
457         assertTrue(manager.isInvocationAsynchronous(RemoteEcho.class));
458         
459         Thread.sleep(300);
460         AsynchronousCallbackForTests lvAsynchronousCallbackForTests = (AsynchronousCallbackForTests) manager.getAsynchronousCallback(RemoteEcho.class);
461         assertNotNull(lvAsynchronousCallbackForTests);
462         
463         assertEquals("ping", lvAsynchronousCallbackForTests.getMethodName());
464         assertEquals(Echo.PING_STRING, lvAsynchronousCallbackForTests.getResult());
465         assertNull(lvAsynchronousCallbackForTests.getThrowable());
466 	}
467 	
468 	public void testAsynchronousInvocationWithMultyThreaded() throws Exception {
469 		Properties prop = new Properties();
470 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
471         prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
472         prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
473 		prop.put(Property.ASYNCHRONOUS_CALLBACK_CLASS, AsynchronousCallbackForTests.class.getName());
474 		prop.put(Property.ASYNCHRONOUS_MAX_SIZE_OF_THREADS, "3");
475 		
476 		ServiceManager manager = new ServiceManager(prop);
477 		RemoteEcho echo =  (RemoteEcho) manager.createService(RemoteEcho.class);
478 		String lvPing = echo.ping();
479 		assertNull(lvPing);
480 		
481         assertTrue(manager.isInvocationAsynchronous(RemoteEcho.class));
482         
483         Thread.sleep(1000);
484         AsynchronousCallbackForTests lvAsynchronousCallbackForTests = (AsynchronousCallbackForTests) manager.getAsynchronousCallback(RemoteEcho.class);
485         assertNotNull(lvAsynchronousCallbackForTests);
486         
487         assertEquals("ping", lvAsynchronousCallbackForTests.getMethodName());
488         assertEquals(Echo.PING_STRING, lvAsynchronousCallbackForTests.getResult());
489         assertNull(lvAsynchronousCallbackForTests.getThrowable());
490 	}
491 
492 	public void testIndivualAsynchronousInvocationWithMultyThreaded() throws Exception {
493 		Properties prop = new Properties();
494 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
495         prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
496         prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
497 
498 		ServiceManager manager = new ServiceManager(prop);
499 		AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
500 		RemoteEcho e = (RemoteEcho) manager.createService(RemoteEcho.class, lvCallback, null, 8);
501 		
502 		String lvEchoStr = null;
503 		String lvPingString = null;
504 		for (int i=0;i<3;i++) {
505 			lvPingString = e.ping();
506 			assertNull(lvPingString);
507 			lvEchoStr = e.echo("Hello");
508 			assertNull(lvEchoStr);
509 		}
510 	}
511 	
512 	public void testIndivualAsynchronousInvocationWithMultyThreadedWith2Services() throws Exception {
513 		Properties prop = new Properties();
514 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
515         prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
516         prop.put(RemoteCalculator.class.getName(), RemoteCalculator.LOOKUP_NAME);
517         prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
518 
519 		ServiceManager manager = new ServiceManager(prop);
520 		AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
521 		RemoteEcho e = (RemoteEcho) manager.createService(RemoteEcho.class, lvCallback, null, 8);
522 		RemoteCalculator c =  (RemoteCalculator) manager.createService(RemoteCalculator.class, lvCallback, null, 8);
523 		
524 		String lvEchoStr = null;
525 		Long lvAddResult = null;
526 		for (int i=0;i<3;i++) {
527 			lvEchoStr = e.echo("Hello");
528 			assertNull(lvEchoStr);
529 			lvAddResult = c.addLong(new Long(123), new Long(456));
530 			assertNull(lvAddResult);
531 		}
532 	}
533 
534 	public void testIndivualAsynchronousInvocationWithMethodFilter() throws Exception {
535 		Properties prop = new Properties();
536 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
537         prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
538         prop.put(RemoteCalculator.class.getName(), RemoteCalculator.LOOKUP_NAME);
539         prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
540 
541 		ServiceManager manager = new ServiceManager(prop);
542 		AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
543 		RemoteEcho e = (RemoteEcho) manager.createService(RemoteEcho.class, lvCallback, new String[] { "ping" }, 4);
544 		
545 		String lvEchoStr = null;
546 		String lvPing = null;
547 		for (int i=0;i<3;i++) {
548 			lvPing = e.ping();
549 			assertNotNull(lvPing);
550 			assertEquals(RemoteEcho.PING_STRING, lvPing);
551 			lvEchoStr = e.echo("Hello");
552 			assertNull(lvEchoStr);
553 		}
554 	}
555 
556 	public void testAddAndRemoveAsynchronousCallback() throws Exception {
557 		Properties prop = new Properties();
558 		prop.put(Property.STATIC_PROXY_CLASS, StaticRmiProxy.class.getName());
559         prop.put(RemoteEcho.class.getName(), RemoteEcho.LOOKUP_NAME);
560         prop.put(RemoteCalculator.class.getName(), RemoteCalculator.LOOKUP_NAME);
561         prop.put(Property.DYNAMIC_PROXY_CLASS, Property.VALUE_FOR_JDK_DYNAMIC_PROXY);
562 
563 
564 		ServiceManager manager = new ServiceManager(prop);
565 		AsynchronousCallbackForTests lvCallback = new AsynchronousCallbackForTests();
566 		RemoteEcho e = (RemoteEcho) manager.createService(RemoteEcho.class, lvCallback, new String[] { "doLongExecution" }, 4);
567 		RemoteCalculator c =  (RemoteCalculator) manager.createService(RemoteCalculator.class, lvCallback, null, 4);
568 				
569 		String lvEchoStr = e.echo("Hello");
570 		assertNull(lvEchoStr);
571 		
572 		Long lvAddResult = c.addLong(new Long(1), new Long(3));
573 		assertNull(lvAddResult);
574 		
575 		assertTrue(manager.isInvocationAsynchronous(RemoteCalculator.class));
576 		manager.removeAsynchronousCallback(RemoteCalculator.class);
577 		assertFalse(manager.isInvocationAsynchronous(RemoteCalculator.class));
578 		
579 		lvEchoStr = e.echo("Hello2");
580 		assertNull(lvEchoStr);
581 		
582 		lvAddResult = c.addLong(new Long(2), new Long(3));
583 		assertNotNull(lvAddResult);
584 		assertEquals(new Long(5), lvAddResult);
585 		
586 		
587 		manager.removeAsynchronousCallback(RemoteEcho.class);
588 		
589 		lvEchoStr = e.echo("Hello3");
590 		assertNotNull(lvEchoStr);
591 		assertEquals("Hello3", lvEchoStr);
592 	}
593 
594 }