@@ -39,24 +39,13 @@ protected void doPost(HttpServletRequest req, HttpServletResponse res) {
39
39
// Note that this should be mostly the same between all load tests.
40
40
// - See load-tests/self
41
41
switch (req .getPathInfo ()) {
42
- case "/" -> handleNoOp ();
42
+ case "/" -> handleNoOp (req , res );
43
+ case "/no-read" -> handleNoRead (req , res );
43
44
case "/hello" -> handleHello (req , res );
44
45
case "/file" -> handleFile (req , res );
45
46
case "/load" -> handleLoad (req , res );
46
47
default -> handleFailure (req , res );
47
48
}
48
-
49
-
50
- try (InputStream is = req .getInputStream ()) {
51
- byte [] body = is .readAllBytes ();
52
- byte [] result = Base64 .getEncoder ().encode (body );
53
- res .setStatus (200 );
54
- res .setContentType ("text/plain" );
55
- res .setContentLength (result .length );
56
- res .getOutputStream ().write (result );
57
- } catch (Exception e ) {
58
- res .setStatus (500 );
59
- }
60
49
}
61
50
62
51
private void handleFailure (HttpServletRequest req , HttpServletResponse res ) {
@@ -73,51 +62,60 @@ private void handleFailure(HttpServletRequest req, HttpServletResponse res) {
73
62
}
74
63
75
64
private void handleFile (HttpServletRequest req , HttpServletResponse res ) {
76
- int size = 1024 * 1024 ;
77
- var requestedSize = req .getParameter ("size" );
78
- if (requestedSize != null ) {
79
- size = Integer .parseInt (requestedSize );
80
- }
65
+ // Note that it is intentionally that we are not reading the InputStream. This will cause the server to have to drain it.
66
+ try (InputStream is = req .getInputStream ()) {
67
+ // Empty the InputStream
68
+ is .readAllBytes ();
81
69
82
- // Ensure we only build one file
83
- byte [] blob = Blobs .get (size );
84
- if (blob == null ) {
85
- synchronized (Blobs ) {
86
- blob = Blobs .get (size );
87
- if (blob == null ) {
88
- System .out .println ("Build file with size : " + size );
89
- String s = "Lorem ipsum dolor sit amet" ;
90
- String body = s .repeat (size / s .length () + (size % s .length ()));
91
- assert body .length () == size ;
92
- Blobs .put (size , body .getBytes (StandardCharsets .UTF_8 ));
70
+ int size = 1024 * 1024 ;
71
+ var requestedSize = req .getParameter ("size" );
72
+ if (requestedSize != null ) {
73
+ size = Integer .parseInt (requestedSize );
74
+ }
75
+
76
+ // Ensure we only build one file
77
+ byte [] blob = Blobs .get (size );
78
+ if (blob == null ) {
79
+ synchronized (Blobs ) {
93
80
blob = Blobs .get (size );
94
- assert blob != null ;
81
+ if (blob == null ) {
82
+ System .out .println ("Build file with size : " + size );
83
+ String s = "Lorem ipsum dolor sit amet" ;
84
+ String body = s .repeat (size / s .length () + (size % s .length ()));
85
+ assert body .length () == size ;
86
+ Blobs .put (size , body .getBytes (StandardCharsets .UTF_8 ));
87
+ blob = Blobs .get (size );
88
+ assert blob != null ;
89
+ }
95
90
}
96
91
}
97
- }
98
92
99
- res .setStatus (200 );
100
- res .setContentType ("application/octet-stream" );
101
- res .setContentLength (blob .length );
93
+ res .setStatus (200 );
94
+ res .setContentType ("application/octet-stream" );
95
+ res .setContentLength (blob .length );
102
96
103
- try (OutputStream os = res .getOutputStream ()) {
104
- os .write (blob );
105
- os . flush ();
97
+ try (OutputStream os = res .getOutputStream ()) {
98
+ os .write (blob );
99
+ }
106
100
} catch (Exception e ) {
107
101
res .setStatus (500 );
108
102
}
109
103
}
110
104
111
105
private void handleHello (HttpServletRequest req , HttpServletResponse res ) {
112
- // Hello world
113
- res .setStatus (200 );
114
- res .setContentType ("text/plain" );
115
- byte [] response = "Hello world" .getBytes (StandardCharsets .UTF_8 );
116
- res .setContentLength (response .length );
106
+ try (InputStream is = req .getInputStream ()) {
107
+ // Empty the InputStream
108
+ is .readAllBytes ();
109
+
110
+ // Hello world
111
+ res .setStatus (200 );
112
+ res .setContentType ("text/plain" );
113
+ byte [] response = "Hello world" .getBytes (StandardCharsets .UTF_8 );
114
+ res .setContentLength (response .length );
117
115
118
- try (OutputStream os = res .getOutputStream ()) {
119
- os .write (response );
120
- os . flush ();
116
+ try (OutputStream os = res .getOutputStream ()) {
117
+ os .write (response );
118
+ }
121
119
} catch (Exception e ) {
122
120
res .setStatus (500 );
123
121
}
@@ -138,6 +136,20 @@ private void handleLoad(HttpServletRequest req, HttpServletResponse res) {
138
136
}
139
137
}
140
138
141
- private void handleNoOp () {
139
+ private void handleNoOp (HttpServletRequest req , HttpServletResponse res ) {
140
+ // Note that it is intentionally that we are not reading the InputStream. This will cause the server to have to drain it.
141
+ try (InputStream is = req .getInputStream ()) {
142
+ // Just read the bytes from the InputStream and return. Do no other worker.
143
+ is .readAllBytes ();
144
+ res .setStatus (200 );
145
+ } catch (Exception e ) {
146
+ res .setStatus (500 );
147
+ }
148
+ }
149
+
150
+ @ SuppressWarnings ("unused" )
151
+ private void handleNoRead (HttpServletRequest req , HttpServletResponse res ) {
152
+ // Note that it is intentionally that we are not reading the InputStream. This will cause the server to have to drain it.
153
+ res .setStatus (200 );
142
154
}
143
155
}
0 commit comments