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.tests.ChannelTestBase; 8 9 import java.io.NotSerializableException ; 10 11 15 public class RpcDispatcherExceptionTest extends ChannelTestBase { 16 RpcDispatcher disp; 17 Channel channel; 18 19 public 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 public void tearDown() throws Exception { 27 super.tearDown(); 28 disp.stop(); 29 channel.close(); 30 } 31 32 public void foo(Pojo p) { 33 System.out.println(p.toString()); 34 } 35 36 37 public void testUnserializableValue() { 38 try { 39 disp.callRemoteMethods(null, "foo", new Object []{new Pojo()}, new Class []{Pojo.class}, GroupRequest.GET_ALL, 5000); 40 fail("this should have thrown an exception"); 41 } 42 catch(Throwable t) { 43 System.out.println("received an exception as expected: " + t); 44 assertTrue(t instanceof RuntimeException ); 45 Throwable cause=t.getCause(); 46 assertTrue(cause instanceof NotSerializableException ); 47 } 48 } 49 50 public void testUnserializableValue2() { 51 try { 52 disp.callRemoteMethod(channel.getLocalAddress(), "foo", new Object []{new Pojo()}, new Class []{Pojo.class}, 53 GroupRequest.GET_ALL, 5000); 54 fail("this should have thrown an exception"); 55 } 56 catch(Throwable t) { 57 System.out.println("received an exception as expected: " + t); 58 assertTrue(t instanceof NotSerializableException ); 59 } 60 } 61 62 static class Pojo { int age; String name; 64 } 65 66 67 public static Test suite() { 68 return new TestSuite(RpcDispatcherExceptionTest.class); 69 } 70 71 72 public static void main(String [] args) { 73 junit.textui.TestRunner.run(RpcDispatcherExceptionTest.suite()); 74 } 75 } 76 | Popular Tags |