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 static org.hamcrest.MatcherAssert.assertThat;
30
31 import java.io.ByteArrayOutputStream;
32 import java.io.PrintStream;
33 import java.nio.charset.StandardCharsets;
34
35 import org.apache.hc.core5.http.HttpVersion;
36 import org.hamcrest.CoreMatchers;
37 import org.junit.jupiter.api.Test;
38
39 public class ResultFormatterTest {
40
41 @Test
42 public void testBasics() throws Exception {
43 final Results results = new Results(
44 "TestServer/1.1",
45 HttpVersion.HTTP_1_1,
46 "localhost",
47 8080,
48 "/index.html",
49 2924,
50 5,
51 3399,
52 20000,
53 0,
54 20000,
55 62640000,
56 0,
57 50000000);
58 final ByteArrayOutputStream buf = new ByteArrayOutputStream();
59 ResultFormatter.print(new PrintStream(buf, true, StandardCharsets.US_ASCII.name()), results);
60 assertThat(new String(buf.toByteArray(), StandardCharsets.US_ASCII).replace("\r\n", "\n"),
61 CoreMatchers.equalTo(
62 "Server Software:\t\tTestServer/1.1\n" +
63 "Protocol version:\t\tHTTP/1.1\n" +
64 "Server Hostname:\t\tlocalhost\n" +
65 "Server Port:\t\t\t8080\n" +
66 "Document Path:\t\t\t/index.html\n" +
67 "Document Length:\t\t2924 bytes\n" +
68 "\n" +
69 "Concurrency Level:\t\t5\n" +
70 "Time taken for tests:\t3.399000 seconds\n" +
71 "Complete requests:\t\t20000\n" +
72 "Failed requests:\t\t0\n" +
73 "Kept alive:\t\t\t\t20000\n" +
74 "Total transferred:\t\t62640000 bytes\n" +
75 "Content transferred:\t50000000 bytes\n" +
76 "Requests per second:\t5,884.08 [#/sec] (mean)\n" +
77 "Time per request:\t\t0.850 [ms] (mean)\n" +
78 "Time per request:\t\t0.170 [ms] (mean, across all concurrent requests)\n" +
79 "Transfer rate:\t\t\t17,997.02 [Kbytes/sec] received\n"
80 ));
81 }
82
83 }