1
2
3
4
5 package org.neo.swarm.core.aop.silc.comp;
6 import java.io.ByteArrayInputStream;
7 import java.io.ByteArrayOutputStream;
8 import java.io.ObjectInputStream;
9 import java.io.ObjectOutputStream;
10 import java.io.Serializable;
11
12 import junit.framework.TestCase;
13
14 import org.neo.swarm.util.serialize.XMLSerializer;
15
16 /***
17 * Check that we can serialize invocations....
18 *
19 * @author navery
20 */
21 public class AspectInvocationTest extends TestCase {
22 public void testSerializationPerformance() throws Exception {
23 int numTimes = 10000;
24 long startTime = System.currentTimeMillis();
25 for (int i = 0; i < numTimes; i++) {
26 serialize();
27 }
28
29
30 System.out.println("elapsed time:" + (System.currentTimeMillis() - startTime));
31 }
32
33
34 public void serialize() throws Exception {
35
36 AspectInvocation one = new AspectInvocation(null, "blahhhhhhhhhhh", new StuffObject("blah"), StuffObject.class.getMethod("doStuff",
37 new Class[] { String.class, Perspective.class } ), new Object[] { "argument1", Perspective.DEFAULT}, new MethodInterceptor[0]);
38
39
40 ByteArrayOutputStream bos = new ByteArrayOutputStream();
41 ObjectOutputStream out = new ObjectOutputStream(bos);
42 out.writeObject(one);
43 out.close();
44
45
46 byte[] buf = bos.toByteArray();
47
48 ByteArrayInputStream bis = new ByteArrayInputStream(buf);
49 ObjectInputStream ois = new ObjectInputStream(bis);
50 AspectInvocation two = (AspectInvocation) ois.readObject();
51 assertNotNull(two.getMethod());
52 }
53
54 public void testXmlSerialize() throws Exception {
55
56 AspectInvocation one = new AspectInvocation(null, "blahhhhhhhhhhh", new StuffObject("blah"), StuffObject.class.getMethod("doStuff",
57 new Class[] { String.class, Perspective.class } ), new Object[] { "argument1", Perspective.DEFAULT}, new MethodInterceptor[0]);
58
59 XMLSerializer xstream = new XMLSerializer();
60 byte[] blah = xstream.serialize(one);
61
62
63 AspectInvocation two = (AspectInvocation) xstream.deserialize(blah);
64 assertNotNull(two.getMethod());
65 }
66
67 public interface Stuff {
68 public void doStuff(String param1, Perspective perspective);
69 }
70
71 public class StuffObject implements Stuff, Serializable {
72 public StuffObject(String blah) {
73 };
74 public void doStuff(String param1, Perspective perspective) {
75 }
76 }
77 }