1 package org.jgroups.blocks; 2 3 import junit.framework.Test; 4 import junit.framework.TestSuite; 5 6 import org.jgroups.Channel; 7 import org.jgroups.ChannelException; 8 import org.jgroups.TimeoutException; 9 import org.jgroups.tests.ChannelTestBase; 10 11 15 public class RpcDispatcherUnicastMethodExceptionTest extends ChannelTestBase { 16 RpcDispatcher disp; 17 Channel channel; 18 19 protected void setUp() throws Exception { 20 super.setUp(); 21 channel=createChannel("A"); 22 disp=new RpcDispatcher(channel, null, null, this); 23 channel.connect("demo"); 24 } 25 26 protected void tearDown() throws Exception { 27 super.tearDown(); 28 disp.stop(); 29 channel.close(); 30 } 31 32 33 public Object foo() { 34 System.out.println("-- foo()"); 35 return "foo(): OK"; 36 } 37 38 public Object bar() throws Exception { 39 System.out.println("-- bar()"); 40 throw new TimeoutException("this is an exception"); 41 } 42 43 public Object foobar() { 44 System.out.println("-- foobar()"); 45 throw new IllegalArgumentException ("bla bla bla from foobar"); 46 } 47 48 public Object foofoobar() { 49 System.out.println("-- foofoobar()"); 50 throw new AssertionError ("bla bla bla from foofoobar"); 51 } 52 53 public void fooWithThrowable() throws Throwable { 54 System.out.println("-- fooWithThrowable()"); 55 throw new Throwable ("this is an exception"); 56 } 57 58 59 60 public void testMethodWithoutException() throws Throwable { 61 Object retval=disp.callRemoteMethod(channel.getLocalAddress(), "foo", null, (Class [])null, GroupRequest.GET_ALL, 5000); 62 System.out.println("retval: " + retval); 63 assertNotNull(retval); 64 } 65 66 67 68 public void testMethodWithException() throws ChannelException { 69 try { 70 Object retval=disp.callRemoteMethod(channel.getLocalAddress(), "bar", null, (Class [])null, GroupRequest.GET_ALL, 5000); 71 System.out.println("retval: " + retval); 72 fail("we should not get here; bar() should throw an exception"); 73 } 74 catch(Throwable e) { 75 System.out.println("caught exception (" + e + ") - as expected"); 76 assertTrue(e instanceof TimeoutException); 77 } 78 } 79 80 public void testMethodWithException2() throws ChannelException { 81 try { 82 Object retval=disp.callRemoteMethod(channel.getLocalAddress(), "foobar", null, (Class [])null, GroupRequest.GET_ALL, 5000); 83 System.out.println("retval: " + retval); 84 fail("we should not get here; foobar() should throw an exception"); 85 } 86 catch(Throwable e) { 87 System.out.println("caught exception (" + e + ") - as expected"); 88 assertTrue(e instanceof IllegalArgumentException ); 89 } 90 } 91 92 public void testMethodWithError() throws ChannelException { 93 try { 94 Object retval=disp.callRemoteMethod(channel.getLocalAddress(), "foofoobar", null, (Class [])null, GroupRequest.GET_ALL, 5000); 95 System.out.println("retval: " + retval); 96 fail("we should not get here; foofoobar() should throw an exception"); 97 } 98 catch(Throwable e) { 99 System.out.println("caught exception (" + e + ") - as expected"); 100 assertTrue(e instanceof AssertionError ); 101 } 102 } 103 104 public void testMethodWithThrowable() throws ChannelException { 105 try { 106 Object retval=disp.callRemoteMethod(channel.getLocalAddress(), "fooWithThrowable", null, (Class [])null, GroupRequest.GET_ALL, 5000); 107 System.out.println("retval: " + retval); 108 fail("we should not get here; foofoobar() should throw an exception"); 109 } 110 catch(Throwable e) { 111 System.out.println("caught exception (" + e + ") - as expected"); 112 assertTrue(e instanceof Throwable ); 113 } 114 } 115 116 117 public static Test suite() { 118 return new TestSuite(RpcDispatcherUnicastMethodExceptionTest.class); 119 } 120 121 122 public static void main(String [] args) { 123 junit.textui.TestRunner.run(RpcDispatcherUnicastMethodExceptionTest.suite()); 124 } 125 } 126 | Popular Tags |