Classes in this File | Line Coverage | Branch Coverage | Complexity | ||||
HttpSoak |
|
| 1.0;1 |
1 | /* | |
2 | * Licensed to the Apache Software Foundation (ASF) under one or more | |
3 | * contributor license agreements. See the NOTICE file distributed with | |
4 | * this work for additional information regarding copyright ownership. | |
5 | * The ASF licenses this file to You under the Apache License, Version 2.0 | |
6 | * (the "License"); you may not use this file except in compliance with | |
7 | * the License. You may obtain a copy of the License at | |
8 | * | |
9 | * http://www.apache.org/licenses/LICENSE-2.0 | |
10 | * | |
11 | * Unless required by applicable law or agreed to in writing, software | |
12 | * distributed under the License is distributed on an "AS IS" BASIS, | |
13 | * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | |
14 | * See the License for the specific language governing permissions and | |
15 | * limitations under the License. | |
16 | */ | |
17 | ||
18 | package org.apache.commons.performance.http; | |
19 | ||
20 | import java.util.logging.Logger; | |
21 | ||
22 | import org.apache.commons.performance.ClientThread; | |
23 | import org.apache.commons.performance.LoadGenerator; | |
24 | import org.apache.commons.performance.Statistics; | |
25 | ||
26 | /** | |
27 | * Simple http load / performance tester, providing another LoadGenerator | |
28 | * example. | |
29 | * | |
30 | * Uses Commons Digester to parse and load configuration and spawns | |
31 | * HTTPClientThread instances to generate load and gather statistics. | |
32 | * | |
33 | */ | |
34 | ||
35 | 0 | public class HttpSoak extends LoadGenerator { |
36 | ||
37 | private String url; | |
38 | private String method; | |
39 | private int socketTimeout; | |
40 | private String successKey; | |
41 | ||
42 | /** Nothing to do here yet */ | |
43 | 0 | protected void init() throws Exception {} |
44 | ||
45 | protected ClientThread makeClientThread( | |
46 | long iterations, long minDelay, long maxDelay, double sigma, | |
47 | String delayType, long rampPeriod, long peakPeriod, | |
48 | long troughPeriod, String cycleType, String rampType, | |
49 | Logger logger, Statistics stats) { | |
50 | ||
51 | 0 | return new HttpClientThread(iterations, minDelay, maxDelay, |
52 | sigma, delayType, rampPeriod, peakPeriod, | |
53 | troughPeriod, cycleType, rampType, logger, | |
54 | stats, url, method, socketTimeout, successKey); | |
55 | } | |
56 | ||
57 | /** | |
58 | * Add http client configuration to parameters loaded by super. | |
59 | * Also set config file name. | |
60 | */ | |
61 | protected void configure() throws Exception { | |
62 | ||
63 | 0 | super.configure(); // loads run configuration |
64 | ||
65 | 0 | digester.addCallMethod("configuration/http", |
66 | "configureHttp", 4); | |
67 | 0 | digester.addCallParam("configuration/http/url", 0); |
68 | 0 | digester.addCallParam("configuration/http/method", 1); |
69 | 0 | digester.addCallParam("configuration/http/socket-timeout", 2); |
70 | 0 | digester.addCallParam("configuration/http/success-key", 3); |
71 | ||
72 | 0 | this.configFile = "config-http.xml"; |
73 | 0 | } |
74 | ||
75 | // ------------------------------------------------------------------------ | |
76 | // Configuration methods specific to this LoadGenerator invoked by Digester | |
77 | // when superclass execute calls digester.parse. | |
78 | // ------------------------------------------------------------------------ | |
79 | public void configureHttp(String url, | |
80 | String method, String socketTimeout, String successKey) { | |
81 | 0 | this.url = url; |
82 | 0 | this.method = method; |
83 | 0 | this.socketTimeout = Integer.parseInt(socketTimeout); |
84 | 0 | this.successKey = successKey; |
85 | 0 | } |
86 | } |