Fix incorrect calculation of next buffer size in AdaptiveRecvByteBufAllocator (#9555)

Motivation:

Due a bug we did not always correctly calculate the next buffer size in AdaptiveRecvByteBufAllocator.

Modification:

Fix calculation and add unit test

Result:

Correct calculation is always used.
This commit is contained in:
bruce 2019-09-27 15:59:25 +08:00 committed by Norman Maurer
parent 85a663fa52
commit b39ffed042
2 changed files with 21 additions and 1 deletions

View File

@ -122,7 +122,7 @@ public class AdaptiveRecvByteBufAllocator extends DefaultMaxMessagesRecvByteBufA
}
private void record(int actualReadBytes) {
if (actualReadBytes <= SIZE_TABLE[max(0, index - INDEX_DECREMENT - 1)]) {
if (actualReadBytes <= SIZE_TABLE[max(0, index - INDEX_DECREMENT)]) {
if (decreaseNow) {
index = max(index - INDEX_DECREMENT, minIndex);
nextReceiveBufferSize = SIZE_TABLE[index];

View File

@ -54,6 +54,26 @@ public class AdaptiveRecvByteBufAllocatorTest {
allocReadExpected(handle, alloc, 8388608);
}
@Test
public void memoryAllocationIntervalsTest() {
computingNext(512, 512);
computingNext(8192, 1110);
computingNext(8192, 1200);
computingNext(4096, 1300);
computingNext(4096, 1500);
computingNext(2048, 1700);
computingNext(2048, 1550);
computingNext(2048, 2000);
computingNext(2048, 1900);
}
private void computingNext(long expectedSize, int actualReadBytes) {
assertEquals(expectedSize, handle.guess());
handle.reset(config);
handle.lastBytesRead(actualReadBytes);
handle.readComplete();
}
@Test
public void lastPartialReadDoesNotRampDown() {
allocReadExpected(handle, alloc, 512);