|
28 | 28 | import org.elasticsearch.common.ValidationException; |
29 | 29 | import org.elasticsearch.common.settings.Settings; |
30 | 30 | import org.elasticsearch.common.util.concurrent.ThreadContext; |
| 31 | +import org.elasticsearch.http.netty4.internal.HttpValidator; |
31 | 32 | import org.elasticsearch.test.ESTestCase; |
32 | 33 |
|
33 | 34 | import java.util.ArrayDeque; |
|
40 | 41 | public class Netty4HttpHeaderValidatorTests extends ESTestCase { |
41 | 42 | private EmbeddedChannel channel; |
42 | 43 | private BlockingQueue<ValidationRequest> validatorRequestQueue; |
| 44 | + private HttpValidator httpValidator = (httpRequest, channel, listener) -> validatorRequestQueue.add( |
| 45 | + new ValidationRequest(httpRequest, channel, listener) |
| 46 | + ); |
43 | 47 |
|
44 | 48 | @Override |
45 | 49 | public void setUp() throws Exception { |
46 | 50 | super.setUp(); |
47 | 51 | validatorRequestQueue = new LinkedBlockingQueue<>(); |
48 | 52 | channel = new EmbeddedChannel( |
49 | 53 | new Netty4HttpHeaderValidator( |
50 | | - (httpRequest, channel, listener) -> validatorRequestQueue.add(new ValidationRequest(httpRequest, channel, listener)), |
| 54 | + (httpRequest, channel, listener) -> httpValidator.validate(httpRequest, channel, listener), |
51 | 55 | new ThreadContext(Settings.EMPTY) |
52 | 56 | ) |
53 | 57 | ); |
@@ -313,5 +317,13 @@ public void testDropChunksOnValidationFailure() { |
313 | 317 | assertFalse(channel.hasPendingTasks()); |
314 | 318 | } |
315 | 319 |
|
| 320 | + public void testInlineValidationDoesNotFork() { |
| 321 | + httpValidator = (httpRequest, channel, listener) -> listener.onResponse(null); |
| 322 | + final var httpRequest = newHttpRequest(); |
| 323 | + channel.writeInbound(httpRequest); |
| 324 | + assertFalse(channel.hasPendingTasks()); |
| 325 | + assertSame(httpRequest, channel.readInbound()); |
| 326 | + } |
| 327 | + |
316 | 328 | record ValidationRequest(HttpRequest request, Channel channel, ActionListener<Void> listener) {} |
317 | 329 | } |
0 commit comments