KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > remoting > SimpleTest


1 package hudson.remoting;
2
3 import junit.framework.Test;
4
5 import java.util.concurrent.ExecutionException JavaDoc;
6 import java.util.concurrent.Future JavaDoc;
7
8 /**
9  * Testing the basic features.
10  *
11  * @author Kohsuke Kawaguchi
12  */

13 public class SimpleTest extends RmiTestBase {
14     public void test1() throws Exception JavaDoc {
15         int r = channel.call(new Callable1());
16         System.out.println("result=" + r);
17         assertEquals(5,r);
18     }
19
20     public void test1Async() throws Exception JavaDoc {
21         Future<Integer JavaDoc> r = channel.callAsync(new Callable1());
22         System.out.println("result="+r.get());
23         assertEquals(5,(int)r.get());
24     }
25
26     private static class Callable1 implements Callable<Integer JavaDoc, RuntimeException JavaDoc> {
27         public Integer JavaDoc call() throws RuntimeException JavaDoc {
28             System.err.println("invoked");
29             return 5;
30         }
31     }
32
33
34     public void test2() throws Exception JavaDoc {
35         try {
36             channel.call(new Callable2());
37             fail();
38         } catch (RuntimeException JavaDoc e) {
39             assertEquals(e.getMessage(),"foo");
40         }
41     }
42
43     public void test2Async() throws Exception JavaDoc {
44         try {
45             Future<Integer JavaDoc> r = channel.callAsync(new Callable2());
46             r.get();
47             fail();
48         } catch (ExecutionException JavaDoc e) {
49             assertEquals(e.getCause().getMessage(),"foo");
50         }
51     }
52
53     private static class Callable2 implements Callable<Integer JavaDoc, RuntimeException JavaDoc> {
54         public Integer JavaDoc call() throws RuntimeException JavaDoc {
55             throw new RuntimeException JavaDoc("foo");
56         }
57     }
58
59     public static Test suite() throws Exception JavaDoc {
60         return buildSuite(SimpleTest.class);
61     }
62 }
63
Popular Tags