1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27 package org.apache.hc.core5.benchmark;
28
29 import java.io.File;
30 import java.net.URI;
31 import java.util.Arrays;
32
33 import org.apache.hc.core5.http.ContentType;
34 import org.apache.hc.core5.util.Args;
35 import org.apache.hc.core5.util.TimeValue;
36 import org.apache.hc.core5.util.Timeout;
37
38 public class BenchmarkConfig {
39
40 private final URI uri;
41 private final int requests;
42 private final int concurrencyLevel;
43 private final TimeValue timeLimit;
44 private final Timeout socketTimeout;
45 private final File payloadFile;
46 private final ContentType contentType;
47 private final int verbosity;
48 private final boolean headInsteadOfGet;
49 private final String[] headers;
50 private final boolean keepAlive;
51 private final String method;
52
53 private final boolean useChunking;
54 private final boolean useExpectContinue;
55 private final boolean useAcceptGZip;
56 private final String payloadText;
57 private final String soapAction;
58 private final boolean forceHttp2;
59 private final boolean disableSSLVerification;
60 private final String trustStorePath;
61 private final String identityStorePath;
62 private final String trustStorePassword;
63 private final String identityStorePassword;
64
65 private BenchmarkConfig(final URI uri,
66 final int requests,
67 final int concurrencyLevel,
68 final TimeValue timeLimit,
69 final Timeout socketTimeout,
70 final File payloadFile,
71 final ContentType contentType,
72 final int verbosity,
73 final boolean headInsteadOfGet,
74 final String[] headers,
75 final boolean keepAlive,
76 final String method,
77 final boolean useChunking,
78 final boolean useExpectContinue,
79 final boolean useAcceptGZip,
80 final String payloadText,
81 final String soapAction,
82 final boolean forceHttp2,
83 final boolean disableSSLVerification,
84 final String trustStorePath,
85 final String identityStorePath,
86 final String trustStorePassword,
87 final String identityStorePassword) {
88 this.uri = uri;
89 this.requests = requests;
90 this.concurrencyLevel = concurrencyLevel;
91 this.timeLimit = timeLimit;
92 this.socketTimeout = socketTimeout;
93 this.payloadFile = payloadFile;
94 this.contentType = contentType;
95 this.verbosity = verbosity;
96 this.headInsteadOfGet = headInsteadOfGet;
97 this.headers = headers;
98 this.keepAlive = keepAlive;
99 this.method = method;
100 this.useChunking = useChunking;
101 this.useExpectContinue = useExpectContinue;
102 this.useAcceptGZip = useAcceptGZip;
103 this.payloadText = payloadText;
104 this.soapAction = soapAction;
105 this.forceHttp2 = forceHttp2;
106 this.disableSSLVerification = disableSSLVerification;
107 this.trustStorePath = trustStorePath;
108 this.identityStorePath = identityStorePath;
109 this.trustStorePassword = trustStorePassword;
110 this.identityStorePassword = identityStorePassword;
111 }
112
113 public URI getUri() {
114 return uri;
115 }
116
117 public int getRequests() {
118 return requests;
119 }
120
121 public int getConcurrencyLevel() {
122 return concurrencyLevel;
123 }
124
125 public boolean isKeepAlive() {
126 return keepAlive;
127 }
128
129 public int getVerbosity() {
130 return verbosity;
131 }
132
133 public boolean isHeadInsteadOfGet() {
134 return headInsteadOfGet;
135 }
136
137 public File getPayloadFile() {
138 return payloadFile;
139 }
140
141 public ContentType getContentType() {
142 return contentType;
143 }
144
145 public String[] getHeaders() {
146 return headers != null ? headers.clone() : null;
147 }
148
149 public Timeout getSocketTimeout() {
150 return socketTimeout;
151 }
152
153 public String getMethod() {
154 return method;
155 }
156
157 public boolean isUseChunking() {
158 return useChunking;
159 }
160
161 public boolean isUseExpectContinue() {
162 return useExpectContinue;
163 }
164
165 public boolean isUseAcceptGZip() {
166 return useAcceptGZip;
167 }
168
169 public String getPayloadText() {
170 return payloadText;
171 }
172
173 public String getSoapAction() {
174 return soapAction;
175 }
176
177 public boolean isForceHttp2() {
178 return forceHttp2;
179 }
180
181 public boolean isDisableSSLVerification() {
182 return disableSSLVerification;
183 }
184
185 public String getTrustStorePath() {
186 return trustStorePath;
187 }
188
189 public String getIdentityStorePath() {
190 return identityStorePath;
191 }
192
193 public String getTrustStorePassword() {
194 return trustStorePassword;
195 }
196
197 public String getIdentityStorePassword() {
198 return identityStorePassword;
199 }
200
201 public TimeValue getTimeLimit() {
202 return timeLimit;
203 }
204
205 @Override
206 public String toString() {
207 return "[" +
208 "uri=" + uri +
209 ", requests=" + requests +
210 ", concurrencyLevel=" + concurrencyLevel +
211 ", timeLimit=" + timeLimit +
212 ", socketTimeout=" + socketTimeout +
213 ", payloadFile=" + payloadFile +
214 ", contentType=" + contentType +
215 ", verbosity=" + verbosity +
216 ", headInsteadOfGet=" + headInsteadOfGet +
217 ", headers=" + Arrays.toString(headers) +
218 ", keepAlive=" + keepAlive +
219 ", method='" + method + '\'' +
220 ", useChunking=" + useChunking +
221 ", useExpectContinue=" + useExpectContinue +
222 ", useAcceptGZip=" + useAcceptGZip +
223 ", payloadText='" + payloadText + '\'' +
224 ", soapAction='" + soapAction + '\'' +
225 ", forceHttp2=" + forceHttp2+
226 ", disableSSLVerification=" + disableSSLVerification +
227 ", trustStorePath='" + trustStorePath + '\'' +
228 ", identityStorePath='" + identityStorePath + '\'' +
229 ", trustStorePassword='" + trustStorePassword + '\'' +
230 ", identityStorePassword='" + identityStorePassword + '\'' +
231 ']';
232 }
233
234 public static BenchmarkConfig.Builder custom() {
235 return new BenchmarkConfig.Builder();
236 }
237
238 public static BenchmarkConfig.Builder copy(final BenchmarkConfig config) {
239 Args.notNull(config, "Socket config");
240 return new Builder()
241 .setUri(config.getUri())
242 .setRequests(config.getRequests())
243 .setConcurrencyLevel(config.getConcurrencyLevel())
244 .setTimeLimit(config.getTimeLimit())
245 .setSocketTimeout(config.getSocketTimeout())
246 .setPayloadFile(config.getPayloadFile())
247 .setContentType(config.getContentType())
248 .setVerbosity(config.getVerbosity())
249 .setHeadInsteadOfGet(config.isHeadInsteadOfGet())
250 .setHeaders(config.getHeaders())
251 .setKeepAlive(config.isKeepAlive())
252 .setMethod(config.getMethod())
253 .setUseChunking(config.isUseChunking())
254 .setUseExpectContinue(config.isUseExpectContinue())
255 .setUseAcceptGZip(config.isUseAcceptGZip())
256 .setPayloadText(config.getPayloadText())
257 .setSoapAction(config.getSoapAction())
258 .setForceHttp2(config.isForceHttp2())
259 .setDisableSSLVerification(config.isDisableSSLVerification())
260 .setTrustStorePath(config.getTrustStorePath())
261 .setIdentityStorePath(config.getIdentityStorePath())
262 .setTrustStorePassword(config.getTrustStorePassword())
263 .setIdentityStorePassword(config.getIdentityStorePassword());
264 }
265
266
267 public static class Builder {
268
269 private URI uri;
270 private int requests;
271 private int concurrencyLevel;
272 private TimeValue timeLimit;
273 private Timeout socketTimeout;
274 private File payloadFile;
275 private ContentType contentType;
276 private int verbosity;
277 private boolean headInsteadOfGet;
278 private String[] headers;
279 private boolean keepAlive;
280 private String method;
281
282 private boolean useChunking;
283 private boolean useExpectContinue;
284 private boolean useAcceptGZip;
285 private String payloadText;
286 private String soapAction;
287 private boolean forceHttp2;
288 private boolean disableSSLVerification;
289 private String trustStorePath;
290 private String identityStorePath;
291 private String trustStorePassword;
292 private String identityStorePassword;
293
294 public Builder() {
295 super();
296 this.requests = 1;
297 this.concurrencyLevel = 1;
298 this.keepAlive = false;
299 this.verbosity = 0;
300 this.headInsteadOfGet = false;
301 this.socketTimeout = Timeout.ofSeconds(60);
302 }
303
304 public Builder setUri(final URI uri) {
305 this.uri = uri;
306 return this;
307 }
308
309 public Builder setRequests(final int requests) {
310 this.requests = requests;
311 return this;
312 }
313
314 public Builder setConcurrencyLevel(final int concurrencyLevel) {
315 this.concurrencyLevel = concurrencyLevel;
316 return this;
317 }
318
319 public Builder setKeepAlive(final boolean keepAlive) {
320 this.keepAlive = keepAlive;
321 return this;
322 }
323
324 public Builder setVerbosity(final int verbosity) {
325 this.verbosity = verbosity;
326 return this;
327 }
328
329 public Builder setHeadInsteadOfGet(final boolean headInsteadOfGet) {
330 this.headInsteadOfGet = headInsteadOfGet;
331 return this;
332 }
333
334 public Builder setContentType(final ContentType contentType) {
335 this.contentType = contentType;
336 return this;
337 }
338
339 public Builder setHeaders(final String[] headers) {
340 this.headers = headers;
341 return this;
342 }
343
344 public Builder setSocketTimeout(final Timeout socketTimeout) {
345 this.socketTimeout = socketTimeout;
346 return this;
347 }
348
349 public Builder setMethod(final String method) {
350 this.method = method;
351 return this;
352 }
353
354 public Builder setUseChunking(final boolean useChunking) {
355 this.useChunking = useChunking;
356 return this;
357 }
358
359 public Builder setUseExpectContinue(final boolean useExpectContinue) {
360 this.useExpectContinue = useExpectContinue;
361 return this;
362 }
363
364 public Builder setUseAcceptGZip(final boolean useAcceptGZip) {
365 this.useAcceptGZip = useAcceptGZip;
366 return this;
367 }
368
369 public Builder setPayloadFile(final File payloadFile) {
370 this.payloadFile = payloadFile;
371 return this;
372 }
373
374 public Builder setPayloadText(final String payloadText) {
375 this.payloadText = payloadText;
376 return this;
377 }
378
379 public Builder setSoapAction(final String soapAction) {
380 this.soapAction = soapAction;
381 return this;
382 }
383
384 public Builder setTimeLimit(final TimeValue timeLimit) {
385 this.timeLimit = timeLimit;
386 return this;
387 }
388
389 public Builder setForceHttp2(final boolean forceHttp2) {
390 this.forceHttp2 = forceHttp2;
391 return this;
392 }
393
394 public Builder setDisableSSLVerification(final boolean disableSSLVerification) {
395 this.disableSSLVerification = disableSSLVerification;
396 return this;
397 }
398
399 public Builder setTrustStorePath(final String trustStorePath) {
400 this.trustStorePath = trustStorePath;
401 return this;
402 }
403
404 public Builder setIdentityStorePath(final String identityStorePath) {
405 this.identityStorePath = identityStorePath;
406 return this;
407 }
408
409 public Builder setTrustStorePassword(final String trustStorePassword) {
410 this.trustStorePassword = trustStorePassword;
411 return this;
412 }
413
414 public Builder setIdentityStorePassword(final String identityStorePassword) {
415 this.identityStorePassword = identityStorePassword;
416 return this;
417 }
418
419 public BenchmarkConfig build() {
420 return new BenchmarkConfig(
421 uri,
422 requests,
423 concurrencyLevel,
424 timeLimit,
425 socketTimeout,
426 payloadFile,
427 contentType,
428 verbosity,
429 headInsteadOfGet,
430 headers,
431 keepAlive,
432 method,
433 useChunking,
434 useExpectContinue,
435 useAcceptGZip,
436 payloadText,
437 soapAction,
438 forceHttp2,
439 disableSSLVerification,
440 trustStorePath,
441 identityStorePath,
442 trustStorePassword,
443 identityStorePassword);
444 }
445
446 }
447
448 }