01: package org.jgroups.blocks;
02:
03: import junit.framework.TestCase;
04: import junit.framework.Test;
05: import junit.framework.TestSuite;
06: import org.jgroups.JChannel;
07: import org.jgroups.TimeoutException;
08: import org.jgroups.ChannelException;
09:
10: import java.io.IOException;
11: import java.io.NotSerializableException;
12:
13: /**
14: * @author Bela Ban
15: * @version $Id: RpcDispatcherExceptionTest.java,v 1.2 2006/05/12 09:56:27 belaban Exp $
16: */
17: public class RpcDispatcherExceptionTest extends TestCase {
18: RpcDispatcher disp;
19: JChannel channel;
20:
21: protected void setUp() throws Exception {
22: super .setUp();
23: channel = new JChannel();
24: disp = new RpcDispatcher(channel, null, null, this );
25: channel.connect("demo");
26: }
27:
28: protected void tearDown() throws Exception {
29: super .tearDown();
30: disp.stop();
31: channel.close();
32: }
33:
34: public void foo(Pojo p) {
35: System.out.println(p.toString());
36: }
37:
38: public void testUnserializableValue() {
39: try {
40: disp.callRemoteMethods(null, "foo",
41: new Object[] { new Pojo() },
42: new Class[] { Pojo.class }, GroupRequest.GET_ALL,
43: 5000);
44: fail("this should have thrown an exception");
45: } catch (Throwable t) {
46: System.out.println("received an exception as expected: "
47: + t);
48: assertTrue(t instanceof RuntimeException);
49: Throwable cause = t.getCause();
50: assertTrue(cause instanceof NotSerializableException);
51: }
52: }
53:
54: public void testUnserializableValue2() {
55: try {
56: disp.callRemoteMethod(channel.getLocalAddress(), "foo",
57: new Object[] { new Pojo() },
58: new Class[] { Pojo.class }, GroupRequest.GET_ALL,
59: 5000);
60: fail("this should have thrown an exception");
61: } catch (Throwable t) {
62: System.out.println("received an exception as expected: "
63: + t);
64: assertTrue(t instanceof NotSerializableException);
65: }
66: }
67:
68: static class Pojo { // doesn't implement Serializable !
69: int age;
70: String name;
71: }
72:
73: public static Test suite() {
74: return new TestSuite(RpcDispatcherExceptionTest.class);
75: }
76:
77: public static void main(String[] args) {
78: junit.textui.TestRunner.run(RpcDispatcherExceptionTest.suite());
79: }
80: }
|