1 package hudson.remoting; 2 3 import junit.framework.Test; 4 5 import java.util.concurrent.ExecutionException ; 6 import java.util.concurrent.Future ; 7 8 13 public class SimpleTest extends RmiTestBase { 14 public void test1() throws Exception { 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 { 21 Future<Integer > 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 , RuntimeException > { 27 public Integer call() throws RuntimeException { 28 System.err.println("invoked"); 29 return 5; 30 } 31 } 32 33 34 public void test2() throws Exception { 35 try { 36 channel.call(new Callable2()); 37 fail(); 38 } catch (RuntimeException e) { 39 assertEquals(e.getMessage(),"foo"); 40 } 41 } 42 43 public void test2Async() throws Exception { 44 try { 45 Future<Integer > r = channel.callAsync(new Callable2()); 46 r.get(); 47 fail(); 48 } catch (ExecutionException e) { 49 assertEquals(e.getCause().getMessage(),"foo"); 50 } 51 } 52 53 private static class Callable2 implements Callable<Integer , RuntimeException > { 54 public Integer call() throws RuntimeException { 55 throw new RuntimeException ("foo"); 56 } 57 } 58 59 public static Test suite() throws Exception { 60 return buildSuite(SimpleTest.class); 61 } 62 } 63 | Popular Tags |