1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package net.sf.ehcache.constructs.web.filter;
18
19 import com.meterware.httpunit.WebConversation;
20 import com.meterware.httpunit.WebResponse;
21 import net.sf.ehcache.StopWatch;
22 import net.sf.ehcache.constructs.web.AbstractWebTest;
23 import org.apache.commons.httpclient.HttpClient;
24 import org.apache.commons.httpclient.HttpMethod;
25 import org.apache.commons.httpclient.methods.GetMethod;
26 import org.apache.commons.logging.Log;
27 import org.apache.commons.logging.LogFactory;
28
29 import java.io.IOException;
30
31
32
33
34
35 public class SpeedTest extends AbstractWebTest {
36 private static final Log LOG = LogFactory.getLog(SpeedTest.class.getName());
37
38
39
40
41
42 public void testSpeedHttpClientNotCached() throws IOException {
43 StopWatch stopWatch = new StopWatch();
44 String url = "http://localhost:9080/Login.jsp";
45 HttpClient httpClient = new HttpClient();
46 HttpMethod httpMethod = new GetMethod(url);
47 stopWatch.getElapsedTime();
48 for (int i = 0; i < 200; i++) {
49 httpClient.executeMethod(httpMethod);
50 httpMethod.getResponseBodyAsStream();
51 }
52 long time = stopWatch.getElapsedTime();
53 LOG.info("Time for 200 uncached page requests: " + time);
54 }
55
56
57
58
59
60 public void testSpeedHttpClientCached() throws IOException {
61 StopWatch stopWatch = new StopWatch();
62 String url = "http://localhost:9080/CachedPage.jsp";
63 HttpClient httpClient = new HttpClient();
64 HttpMethod httpMethod = new GetMethod(url);
65 stopWatch.getElapsedTime();
66 for (int i = 0; i < 200; i++) {
67 httpClient.executeMethod(httpMethod);
68 httpMethod.getResponseBodyAsStream();
69 }
70 long time = stopWatch.getElapsedTime();
71 LOG.info("Time for 200 cached page requests: " + time);
72 }
73
74
75
76
77 public void testSpeedNoDom() throws Exception {
78 StopWatch stopWatch = new StopWatch();
79 final WebConversation conversation = createWebConversation(true);
80
81 String requestUrl = "http://localhost:9080/CachedPage.jsp";
82 stopWatch.getElapsedTime();
83 for (int i = 0; i < 200; i++) {
84 WebResponse response = conversation.getResponse(requestUrl);
85 response.getText().indexOf("timestamp");
86 }
87 long time = stopWatch.getElapsedTime();
88 LOG.info("Time for 200 cached page requests: " + time);
89
90 }
91
92
93
94
95
96
97 public void testSpeedDom() throws Exception {
98 StopWatch stopWatch = new StopWatch();
99 CachingFilterTest cachingFilterTest = new CachingFilterTest();
100 cachingFilterTest.testCachedPageIsCached();
101 stopWatch.getElapsedTime();
102 for (int i = 0; i < 100; i++) {
103 cachingFilterTest.testCachedPageIsCached();
104 }
105 long time = stopWatch.getElapsedTime();
106 LOG.info("Time for 200 cached page requests: " + time);
107
108 }
109
110
111
112
113
114 public void testFlushClover() {
115
116 }
117 }