KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > hudson > remoting > ClassRemotingTest


1 package hudson.remoting;
2
3 import junit.framework.Test;
4 import org.objectweb.asm.ClassReader;
5 import org.objectweb.asm.commons.EmptyVisitor;
6
7 /**
8  * Test class image forwarding.
9  *
10  * @author Kohsuke Kawaguchi
11  */

12 public class ClassRemotingTest extends RmiTestBase {
13     public void test1() throws Throwable JavaDoc {
14         // call a class that's only available on DummyClassLoader, so that on the remote channel
15
// it will be fetched from this class loader and not from the system classloader.
16
DummyClassLoader cl = new DummyClassLoader(this.getClass().getClassLoader());
17         Callable c = (Callable) cl.loadClass("hudson.remoting.test.TestCallable").newInstance();
18
19         Object JavaDoc[] r = (Object JavaDoc[]) channel.call(c);
20
21         System.out.println(r[0]);
22
23         assertTrue(r[0].toString().startsWith("hudson.remoting.RemoteClassLoader@"));
24
25         // make sure the bytes are what we are expecting
26
System.out.println("Resource is "+((byte[])r[1]).length+" bytes");
27         ClassReader cr = new ClassReader((byte[])r[1]);
28         cr.accept(new EmptyVisitor(),false);
29
30         // make sure cache is taking effect
31
System.out.println(r[2]);
32         System.out.println(r[3]);
33         assertEquals(r[2],r[3]);
34     }
35
36     public static Test suite() throws Exception JavaDoc {
37         return buildSuite(ClassRemotingTest.class);
38     }
39 }
40
Popular Tags