Source:
<code>public void sizeLimitationTest() throws Exception { int blobPartSize = 1024; int encodedSize = 1209; long[] maxSizesAllowed = {encodedSize + 1, encodedSize, encodedSize - 1, 0}; for (long maxSizeAllowed : maxSizesAllowed) { InMemoryFile[] files = {new InMemoryFile(RestUtils.MultipartPost.BLOB_PART, ByteBuffer.wrap(TestUtils.getRandomBytes(blobPartSize)))}; HttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/"); HttpPostRequestEncoder encoder = createEncoder(httpRequest, files); NettyMultipartRequest request = new NettyMultipartRequest(encoder.finalizeRequest(), new MockChannel(), NETTY_METRICS, Collections.emptySet(), maxSizeAllowed); assertTrue("Request channel is not open", request.isOpen()); long currentSizeAdded = 0; while (!encoder.isEndOfInput()) { HttpContent httpContent = encoder.readChunk(PooledByteBufAllocator.DEFAULT); int readableBytes = httpContent.content().readableBytes(); if (currentSizeAdded + readableBytes <= maxSizeAllowed) { request.addContent(httpContent); } else { assertTrue("Max size [" + maxSizeAllowed + "] must be lesser than content size: " + encodedSize, maxSizeAllowed < encodedSize); try { request.addContent(httpContent); <START> fail("Should have failed to add content of size [" + encodedSize <END> + "] because it is over the max size allowed: " + maxSizeAllowed); } catch (RestServiceException e) { assertEquals("Unexpected RestServiceErrorCode", RestServiceErrorCode.RequestTooLarge, e.getErrorCode()); break; } } currentSizeAdded += readableBytes; } } }</code><technical_language>do ensure this block is execute for interested ones</technical_language>

Target:
public void sizeLimitationTest() throws Exception { int blobPartSize = 1024; int encodedSize = 1209; long[] maxSizesAllowed = {encodedSize + 1, encodedSize, encodedSize - 1, 0}; for (long maxSizeAllowed : maxSizesAllowed) { InMemoryFile[] files = {new InMemoryFile(RestUtils.MultipartPost.BLOB_PART, ByteBuffer.wrap(TestUtils.getRandomBytes(blobPartSize)))}; HttpRequest httpRequest = new DefaultFullHttpRequest(HttpVersion.HTTP_1_1, HttpMethod.POST, "/"); HttpPostRequestEncoder encoder = createEncoder(httpRequest, files); NettyMultipartRequest request = new NettyMultipartRequest(encoder.finalizeRequest(), new MockChannel(), NETTY_METRICS, Collections.emptySet(), maxSizeAllowed); assertTrue("Request channel is not open", request.isOpen()); long currentSizeAdded = 0; boolean failedToAdd = false; while (!encoder.isEndOfInput()) { HttpContent httpContent = encoder.readChunk(PooledByteBufAllocator.DEFAULT); int readableBytes = httpContent.content().readableBytes(); if (currentSizeAdded + readableBytes <= maxSizeAllowed) { request.addContent(httpContent); } else { assertTrue("Max size [" + maxSizeAllowed + "] must be lesser than content size: " + encodedSize, maxSizeAllowed < encodedSize); try { request.addContent(httpContent); fail("Should have failed to add content of size [" + encodedSize + "] because it is over the max size allowed: " + maxSizeAllowed); } catch (RestServiceException e) { failedToAdd = true; assertEquals("Unexpected RestServiceErrorCode", RestServiceErrorCode.RequestTooLarge, e.getErrorCode()); break; } } currentSizeAdded += readableBytes; } assertEquals("Success state not as expected", maxSizeAllowed < encodedSize, failedToAdd); } }