KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jgroups > blocks > RpcDispatcherExceptionTest


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 JavaDoc;
10
11 /**
12  * @author Bela Ban
13  * @version $Id: RpcDispatcherExceptionTest.java,v 1.3 2007/01/22 23:21:26 vlada Exp $
14  */

15 public class RpcDispatcherExceptionTest extends ChannelTestBase {
16     RpcDispatcher disp;
17     Channel channel;
18
19     public void setUp() throws Exception JavaDoc {
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 JavaDoc {
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 JavaDoc[]{new Pojo()}, new Class JavaDoc[]{Pojo.class}, GroupRequest.GET_ALL, 5000);
40             fail("this should have thrown an exception");
41         }
42         catch(Throwable JavaDoc t) {
43             System.out.println("received an exception as expected: " + t);
44             assertTrue(t instanceof RuntimeException JavaDoc);
45             Throwable JavaDoc cause=t.getCause();
46             assertTrue(cause instanceof NotSerializableException JavaDoc);
47         }
48     }
49
50     public void testUnserializableValue2() {
51         try {
52             disp.callRemoteMethod(channel.getLocalAddress(), "foo", new Object JavaDoc[]{new Pojo()}, new Class JavaDoc[]{Pojo.class},
53                                   GroupRequest.GET_ALL, 5000);
54             fail("this should have thrown an exception");
55         }
56         catch(Throwable JavaDoc t) {
57             System.out.println("received an exception as expected: " + t);
58             assertTrue(t instanceof NotSerializableException JavaDoc);
59         }
60     }
61
62     static class Pojo { // doesn't implement Serializable !
63
int age; String JavaDoc name;
64     }
65
66
67     public static Test suite() {
68         return new TestSuite(RpcDispatcherExceptionTest.class);
69     }
70
71
72     public static void main(String JavaDoc[] args) {
73         junit.textui.TestRunner.run(RpcDispatcherExceptionTest.suite());
74     }
75 }
76
Popular Tags