KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > tirsen > nanning > profiler > ProfilerTest


1 package com.tirsen.nanning.profiler;
2
3 import com.tirsen.nanning.config.*;
4 import com.tirsen.nanning.attribute.*;
5 import com.tirsen.nanning.profiler.Profiled;
6 import com.tirsen.nanning.profiler.ProfilerInterceptor;
7 import com.tirsen.nanning.profiler.ProfilerLogger;
8
9 public class ProfilerTest extends AbstractAttributesTest {
10     public void testProfiler() throws Exception JavaDoc {
11         Thread JavaDoc thread = new Thread JavaDoc(new Runnable JavaDoc() {
12             public void run() {
13                 AspectSystem aspectSystem = new AspectSystem();
14                 aspectSystem.addAspect(new FindTargetMixinAspect());
15                 aspectSystem.addAspect(new InterceptorAspect(new AttributePointcut("profile"), new ProfilerInterceptor()));
16                 Profiled profiled = (Profiled) aspectSystem.newInstance(Profiled.class);
17
18                 profiled.someMethod();
19                 profiled.notProfiledMethod();
20
21             }
22         });
23         thread.start();
24         thread.join();
25         String JavaDoc log = ProfilerLogger.getProfilerLogger().lastLog;
26         assertNotNull(log);
27         assertTrue(log.matches("(.*)someMethod: (.*)ms"));
28     }
29
30     public void testMinimumProfilingDuration() throws Exception JavaDoc {
31         Thread JavaDoc thread = new Thread JavaDoc(new Runnable JavaDoc() {
32             public void run() {
33                 AspectSystem aspectSystem = new AspectSystem();
34                 aspectSystem.addAspect(new FindTargetMixinAspect());
35                 aspectSystem.addAspect(new InterceptorAspect(new AttributePointcut("profile"), new ProfilerInterceptor()));
36                 Profiled profiled = (Profiled) aspectSystem.newInstance(Profiled.class);
37                 ProfilerInterceptor.setMinDuration(100L);
38                 profiled.delayTwoHundredMillis();
39                 profiled.someMethod();
40
41             }
42         });
43         thread.start();
44         thread.join();
45         String JavaDoc log = ProfilerLogger.getProfilerLogger().lastLog;
46         assertNotNull(log);
47         assertTrue(log.indexOf("delayTwoHundredMillis") > 0);
48
49     }
50 }
51
Popular Tags