Fix ByteBuf Leak in Nio HTTP Tests (#51444) (#51457)

It is the job of the http server transport to release the request in the handler
but the mock fails to do so since we never override `incomingRequest`.
This commit is contained in:
Armin Braun 2020-01-25 16:19:49 +01:00 committed by GitHub
parent fbec19c022
commit 3e3673b518
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 5 additions and 0 deletions

View File

@ -75,6 +75,7 @@ import static org.hamcrest.Matchers.nullValue;
import static org.mockito.Matchers.any;
import static org.mockito.Matchers.eq;
import static org.mockito.Mockito.atLeastOnce;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify;
@ -92,6 +93,10 @@ public class HttpReadWriteHandlerTests extends ESTestCase {
@Before
public void setMocks() {
transport = mock(NioHttpServerTransport.class);
doAnswer(invocation -> {
((HttpRequest) invocation.getArguments()[0]).releaseAndCopy();
return null;
}).when(transport).incomingRequest(any(HttpRequest.class), any(HttpChannel.class));
Settings settings = Settings.builder().put(SETTING_HTTP_MAX_CONTENT_LENGTH.getKey(), new ByteSizeValue(1024)).build();
HttpHandlingSettings httpHandlingSettings = HttpHandlingSettings.fromSettings(settings);
channel = mock(NioHttpChannel.class);