PooledByteBuf.capacity(...) not enforces maxCapacity()
Motivation: PooledByteBuf.capacity(...) miss to enforce maxCapacity() and so its possible to increase the capacity of the buffer even if it will be bigger then maxCapacity(). Modifications: - Correctly enforce maxCapacity() - Add unit tests for capacity(...) calls. Result: Correctly enforce maxCapacity().
This commit is contained in:
parent
0fbad09535
commit
06c629a226
@ -1155,6 +1155,13 @@ public abstract class AbstractByteBuf extends ByteBuf {
|
|||||||
checkReadableBytes0(minimumReadableBytes);
|
checkReadableBytes0(minimumReadableBytes);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
protected final void checkNewCapacity(int newCapacity) {
|
||||||
|
ensureAccessible();
|
||||||
|
if (newCapacity < 0 || newCapacity > maxCapacity()) {
|
||||||
|
throw new IllegalArgumentException("newCapacity: " + newCapacity + " (expected: 0-" + maxCapacity() + ')');
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
private void checkReadableBytes0(int minimumReadableBytes) {
|
private void checkReadableBytes0(int minimumReadableBytes) {
|
||||||
ensureAccessible();
|
ensureAccessible();
|
||||||
if (readerIndex > writerIndex - minimumReadableBytes) {
|
if (readerIndex > writerIndex - minimumReadableBytes) {
|
||||||
|
@ -641,10 +641,7 @@ public class CompositeByteBuf extends AbstractReferenceCountedByteBuf implements
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public CompositeByteBuf capacity(int newCapacity) {
|
public CompositeByteBuf capacity(int newCapacity) {
|
||||||
ensureAccessible();
|
checkNewCapacity(newCapacity);
|
||||||
if (newCapacity < 0 || newCapacity > maxCapacity()) {
|
|
||||||
throw new IllegalArgumentException("newCapacity: " + newCapacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
int oldCapacity = capacity();
|
int oldCapacity = capacity();
|
||||||
if (newCapacity > oldCapacity) {
|
if (newCapacity > oldCapacity) {
|
||||||
|
@ -84,7 +84,7 @@ abstract class PooledByteBuf<T> extends AbstractReferenceCountedByteBuf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public final ByteBuf capacity(int newCapacity) {
|
public final ByteBuf capacity(int newCapacity) {
|
||||||
ensureAccessible();
|
checkNewCapacity(newCapacity);
|
||||||
|
|
||||||
// If the request capacity does not require reallocation, just update the length of the memory.
|
// If the request capacity does not require reallocation, just update the length of the memory.
|
||||||
if (chunk.unpooled) {
|
if (chunk.unpooled) {
|
||||||
|
@ -139,10 +139,7 @@ public class UnpooledDirectByteBuf extends AbstractReferenceCountedByteBuf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf capacity(int newCapacity) {
|
public ByteBuf capacity(int newCapacity) {
|
||||||
ensureAccessible();
|
checkNewCapacity(newCapacity);
|
||||||
if (newCapacity < 0 || newCapacity > maxCapacity()) {
|
|
||||||
throw new IllegalArgumentException("newCapacity: " + newCapacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
int readerIndex = readerIndex();
|
int readerIndex = readerIndex();
|
||||||
int writerIndex = writerIndex();
|
int writerIndex = writerIndex();
|
||||||
|
@ -104,10 +104,7 @@ public class UnpooledHeapByteBuf extends AbstractReferenceCountedByteBuf {
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf capacity(int newCapacity) {
|
public ByteBuf capacity(int newCapacity) {
|
||||||
ensureAccessible();
|
checkNewCapacity(newCapacity);
|
||||||
if (newCapacity < 0 || newCapacity > maxCapacity()) {
|
|
||||||
throw new IllegalArgumentException("newCapacity: " + newCapacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
int oldCapacity = array.length;
|
int oldCapacity = array.length;
|
||||||
if (newCapacity > oldCapacity) {
|
if (newCapacity > oldCapacity) {
|
||||||
|
@ -146,10 +146,7 @@ public class UnpooledUnsafeDirectByteBuf extends AbstractReferenceCountedByteBuf
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf capacity(int newCapacity) {
|
public ByteBuf capacity(int newCapacity) {
|
||||||
ensureAccessible();
|
checkNewCapacity(newCapacity);
|
||||||
if (newCapacity < 0 || newCapacity > maxCapacity()) {
|
|
||||||
throw new IllegalArgumentException("newCapacity: " + newCapacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
int readerIndex = readerIndex();
|
int readerIndex = readerIndex();
|
||||||
int writerIndex = writerIndex();
|
int writerIndex = writerIndex();
|
||||||
|
@ -37,10 +37,7 @@ final class UnpooledUnsafeNoCleanerDirectByteBuf extends UnpooledUnsafeDirectByt
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public ByteBuf capacity(int newCapacity) {
|
public ByteBuf capacity(int newCapacity) {
|
||||||
ensureAccessible();
|
checkNewCapacity(newCapacity);
|
||||||
if (newCapacity < 0 || newCapacity > maxCapacity()) {
|
|
||||||
throw new IllegalArgumentException("newCapacity: " + newCapacity);
|
|
||||||
}
|
|
||||||
|
|
||||||
int readerIndex = readerIndex();
|
int readerIndex = readerIndex();
|
||||||
int writerIndex = writerIndex();
|
int writerIndex = writerIndex();
|
||||||
|
@ -74,7 +74,11 @@ public abstract class AbstractByteBufTest {
|
|||||||
private Random random;
|
private Random random;
|
||||||
private ByteBuf buffer;
|
private ByteBuf buffer;
|
||||||
|
|
||||||
protected abstract ByteBuf newBuffer(int capacity);
|
protected final ByteBuf newBuffer(int capacity) {
|
||||||
|
return newBuffer(capacity, Integer.MAX_VALUE);
|
||||||
|
}
|
||||||
|
|
||||||
|
protected abstract ByteBuf newBuffer(int capacity, int maxCapacity);
|
||||||
|
|
||||||
protected boolean discardReadBytesDoesNotMoveWritableBytes() {
|
protected boolean discardReadBytesDoesNotMoveWritableBytes() {
|
||||||
return true;
|
return true;
|
||||||
@ -2892,4 +2896,56 @@ public abstract class AbstractByteBufTest {
|
|||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testCapacityEnforceMaxCapacity() {
|
||||||
|
ByteBuf buffer = newBuffer(3, 13);
|
||||||
|
assertEquals(13, buffer.maxCapacity());
|
||||||
|
assertEquals(3, buffer.capacity());
|
||||||
|
try {
|
||||||
|
buffer.capacity(14);
|
||||||
|
} finally {
|
||||||
|
buffer.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test(expected = IllegalArgumentException.class)
|
||||||
|
public void testCapacityNegative() {
|
||||||
|
ByteBuf buffer = newBuffer(3, 13);
|
||||||
|
assertEquals(13, buffer.maxCapacity());
|
||||||
|
assertEquals(3, buffer.capacity());
|
||||||
|
try {
|
||||||
|
buffer.capacity(-1);
|
||||||
|
} finally {
|
||||||
|
buffer.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCapacityDecrease() {
|
||||||
|
ByteBuf buffer = newBuffer(3, 13);
|
||||||
|
assertEquals(13, buffer.maxCapacity());
|
||||||
|
assertEquals(3, buffer.capacity());
|
||||||
|
try {
|
||||||
|
buffer.capacity(2);
|
||||||
|
assertEquals(2, buffer.capacity());
|
||||||
|
assertEquals(13, buffer.maxCapacity());
|
||||||
|
} finally {
|
||||||
|
buffer.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testCapacityIncrease() {
|
||||||
|
ByteBuf buffer = newBuffer(3, 13);
|
||||||
|
assertEquals(13, buffer.maxCapacity());
|
||||||
|
assertEquals(3, buffer.capacity());
|
||||||
|
try {
|
||||||
|
buffer.capacity(4);
|
||||||
|
assertEquals(4, buffer.capacity());
|
||||||
|
assertEquals(13, buffer.maxCapacity());
|
||||||
|
} finally {
|
||||||
|
buffer.release();
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -16,6 +16,7 @@
|
|||||||
package io.netty.buffer;
|
package io.netty.buffer;
|
||||||
|
|
||||||
import io.netty.util.ReferenceCountUtil;
|
import io.netty.util.ReferenceCountUtil;
|
||||||
|
import org.junit.Assume;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.nio.ByteBuffer;
|
import java.nio.ByteBuffer;
|
||||||
@ -60,7 +61,9 @@ public abstract class AbstractCompositeByteBufTest extends AbstractByteBufTest {
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
|
Assume.assumeTrue(maxCapacity == Integer.MAX_VALUE);
|
||||||
|
|
||||||
List<ByteBuf> buffers = new ArrayList<ByteBuf>();
|
List<ByteBuf> buffers = new ArrayList<ByteBuf>();
|
||||||
for (int i = 0; i < length + 45; i += 45) {
|
for (int i = 0; i < length + 45; i += 45) {
|
||||||
buffers.add(EMPTY_BUFFER);
|
buffers.add(EMPTY_BUFFER);
|
||||||
|
@ -19,11 +19,11 @@ import static org.junit.Assert.*;
|
|||||||
|
|
||||||
public abstract class AbstractPooledByteBufTest extends AbstractByteBufTest {
|
public abstract class AbstractPooledByteBufTest extends AbstractByteBufTest {
|
||||||
|
|
||||||
protected abstract ByteBuf alloc(int length);
|
protected abstract ByteBuf alloc(int length, int maxCapacity);
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
ByteBuf buffer = alloc(length);
|
ByteBuf buffer = alloc(length, maxCapacity);
|
||||||
|
|
||||||
// Testing if the writerIndex and readerIndex are correct when allocate and also after we reset the mark.
|
// Testing if the writerIndex and readerIndex are correct when allocate and also after we reset the mark.
|
||||||
assertEquals(0, buffer.writerIndex());
|
assertEquals(0, buffer.writerIndex());
|
||||||
|
@ -25,14 +25,14 @@ import java.nio.ByteOrder;
|
|||||||
public class BigEndianDirectByteBufTest extends AbstractByteBufTest {
|
public class BigEndianDirectByteBufTest extends AbstractByteBufTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
ByteBuf buffer = newDirectBuffer(length);
|
ByteBuf buffer = newDirectBuffer(length, maxCapacity);
|
||||||
assertSame(ByteOrder.BIG_ENDIAN, buffer.order());
|
assertSame(ByteOrder.BIG_ENDIAN, buffer.order());
|
||||||
assertEquals(0, buffer.writerIndex());
|
assertEquals(0, buffer.writerIndex());
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ByteBuf newDirectBuffer(int length) {
|
protected ByteBuf newDirectBuffer(int length, int maxCapacity) {
|
||||||
return new UnpooledDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, Integer.MAX_VALUE);
|
return new UnpooledDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, maxCapacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ import static org.junit.Assert.*;
|
|||||||
public class BigEndianHeapByteBufTest extends AbstractByteBufTest {
|
public class BigEndianHeapByteBufTest extends AbstractByteBufTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
ByteBuf buffer = Unpooled.buffer(length);
|
ByteBuf buffer = Unpooled.buffer(length, maxCapacity);
|
||||||
assertEquals(0, buffer.writerIndex());
|
assertEquals(0, buffer.writerIndex());
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class BigEndianUnsafeDirectByteBufTest extends BigEndianDirectByteBufTest
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
return new UnpooledUnsafeDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, Integer.MAX_VALUE);
|
return new UnpooledUnsafeDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, maxCapacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -31,7 +31,7 @@ public class BigEndianUnsafeNoCleanerDirectByteBufTest extends BigEndianDirectBy
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
return new UnpooledUnsafeNoCleanerDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, Integer.MAX_VALUE);
|
return new UnpooledUnsafeNoCleanerDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, maxCapacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ import static org.junit.Assert.assertEquals;
|
|||||||
public class DuplicateByteBufTest extends AbstractByteBufTest {
|
public class DuplicateByteBufTest extends AbstractByteBufTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
ByteBuf wrapped = Unpooled.buffer(length);
|
ByteBuf wrapped = Unpooled.buffer(length, maxCapacity);
|
||||||
ByteBuf buffer = new DuplicatedByteBuf(wrapped);
|
ByteBuf buffer = new DuplicatedByteBuf(wrapped);
|
||||||
assertEquals(wrapped.writerIndex(), buffer.writerIndex());
|
assertEquals(wrapped.writerIndex(), buffer.writerIndex());
|
||||||
assertEquals(wrapped.readerIndex(), buffer.readerIndex());
|
assertEquals(wrapped.readerIndex(), buffer.readerIndex());
|
||||||
|
@ -25,14 +25,14 @@ import java.nio.ByteOrder;
|
|||||||
public class LittleEndianDirectByteBufTest extends AbstractByteBufTest {
|
public class LittleEndianDirectByteBufTest extends AbstractByteBufTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
ByteBuf buffer = newDirectBuffer(length).order(ByteOrder.LITTLE_ENDIAN);
|
ByteBuf buffer = newDirectBuffer(length, maxCapacity).order(ByteOrder.LITTLE_ENDIAN);
|
||||||
assertSame(ByteOrder.LITTLE_ENDIAN, buffer.order());
|
assertSame(ByteOrder.LITTLE_ENDIAN, buffer.order());
|
||||||
assertEquals(0, buffer.writerIndex());
|
assertEquals(0, buffer.writerIndex());
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
|
||||||
protected ByteBuf newDirectBuffer(int length) {
|
protected ByteBuf newDirectBuffer(int length, int maxCapacity) {
|
||||||
return new UnpooledDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, Integer.MAX_VALUE);
|
return new UnpooledDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, maxCapacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ import java.nio.ByteOrder;
|
|||||||
public class LittleEndianHeapByteBufTest extends AbstractByteBufTest {
|
public class LittleEndianHeapByteBufTest extends AbstractByteBufTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
ByteBuf buffer = Unpooled.buffer(length).order(ByteOrder.LITTLE_ENDIAN);
|
ByteBuf buffer = Unpooled.buffer(length, maxCapacity).order(ByteOrder.LITTLE_ENDIAN);
|
||||||
assertEquals(0, buffer.writerIndex());
|
assertEquals(0, buffer.writerIndex());
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -29,7 +29,7 @@ public class LittleEndianUnsafeDirectByteBufTest extends LittleEndianDirectByteB
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
return new UnpooledUnsafeDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, Integer.MAX_VALUE);
|
return new UnpooledUnsafeDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, maxCapacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -30,7 +30,7 @@ public class LittleEndianUnsafeNoCleanerDirectByteBufTest extends LittleEndianDi
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
return new UnpooledUnsafeNoCleanerDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, Integer.MAX_VALUE);
|
return new UnpooledUnsafeNoCleanerDirectByteBuf(UnpooledByteBufAllocator.DEFAULT, length, maxCapacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ import static org.junit.Assert.*;
|
|||||||
public class PooledBigEndianDirectByteBufTest extends AbstractPooledByteBufTest {
|
public class PooledBigEndianDirectByteBufTest extends AbstractPooledByteBufTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf alloc(int length) {
|
protected ByteBuf alloc(int length, int maxCapacity) {
|
||||||
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.directBuffer(length);
|
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.directBuffer(length, maxCapacity);
|
||||||
assertSame(ByteOrder.BIG_ENDIAN, buffer.order());
|
assertSame(ByteOrder.BIG_ENDIAN, buffer.order());
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -21,7 +21,7 @@ package io.netty.buffer;
|
|||||||
public class PooledBigEndianHeapByteBufTest extends AbstractPooledByteBufTest {
|
public class PooledBigEndianHeapByteBufTest extends AbstractPooledByteBufTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf alloc(int length) {
|
protected ByteBuf alloc(int length, int maxCapacity) {
|
||||||
return PooledByteBufAllocator.DEFAULT.heapBuffer(length);
|
return PooledByteBufAllocator.DEFAULT.heapBuffer(length, maxCapacity);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,9 @@ import static org.junit.Assert.*;
|
|||||||
public class PooledLittleEndianDirectByteBufTest extends AbstractPooledByteBufTest {
|
public class PooledLittleEndianDirectByteBufTest extends AbstractPooledByteBufTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf alloc(int length) {
|
protected ByteBuf alloc(int length, int maxCapacity) {
|
||||||
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.directBuffer(length).order(ByteOrder.LITTLE_ENDIAN);
|
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.directBuffer(length, maxCapacity)
|
||||||
|
.order(ByteOrder.LITTLE_ENDIAN);
|
||||||
assertSame(ByteOrder.LITTLE_ENDIAN, buffer.order());
|
assertSame(ByteOrder.LITTLE_ENDIAN, buffer.order());
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -25,8 +25,8 @@ import static org.junit.Assert.*;
|
|||||||
public class PooledLittleEndianHeapByteBufTest extends AbstractPooledByteBufTest {
|
public class PooledLittleEndianHeapByteBufTest extends AbstractPooledByteBufTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf alloc(int length) {
|
protected ByteBuf alloc(int length, int maxCapacity) {
|
||||||
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(length).order(ByteOrder.LITTLE_ENDIAN);
|
ByteBuf buffer = PooledByteBufAllocator.DEFAULT.heapBuffer(length, maxCapacity).order(ByteOrder.LITTLE_ENDIAN);
|
||||||
assertSame(ByteOrder.LITTLE_ENDIAN, buffer.order());
|
assertSame(ByteOrder.LITTLE_ENDIAN, buffer.order());
|
||||||
return buffer;
|
return buffer;
|
||||||
}
|
}
|
||||||
|
@ -31,8 +31,8 @@ public class SimpleLeakAwareByteBufTest extends BigEndianHeapByteBufTest {
|
|||||||
private final Queue<NoopResourceLeakTracker<ByteBuf>> trackers = new ArrayDeque<NoopResourceLeakTracker<ByteBuf>>();
|
private final Queue<NoopResourceLeakTracker<ByteBuf>> trackers = new ArrayDeque<NoopResourceLeakTracker<ByteBuf>>();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final ByteBuf newBuffer(int capacity) {
|
protected final ByteBuf newBuffer(int capacity, int maxCapacity) {
|
||||||
return wrap(super.newBuffer(capacity));
|
return wrap(super.newBuffer(capacity, maxCapacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
private ByteBuf wrap(ByteBuf buffer) {
|
private ByteBuf wrap(ByteBuf buffer) {
|
||||||
|
@ -15,7 +15,7 @@
|
|||||||
*/
|
*/
|
||||||
package io.netty.buffer;
|
package io.netty.buffer;
|
||||||
|
|
||||||
import org.junit.Ignore;
|
import org.junit.Assume;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
import java.io.IOException;
|
import java.io.IOException;
|
||||||
@ -34,7 +34,8 @@ public class SlicedByteBufTest extends AbstractByteBufTest {
|
|||||||
private final Random random = new Random();
|
private final Random random = new Random();
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
|
Assume.assumeTrue(maxCapacity == Integer.MAX_VALUE);
|
||||||
ByteBuf buffer = Unpooled.wrappedBuffer(
|
ByteBuf buffer = Unpooled.wrappedBuffer(
|
||||||
new byte[length * 2], random.nextInt(length - 1) + 1, length);
|
new byte[length * 2], random.nextInt(length - 1) + 1, length);
|
||||||
assertEquals(length, buffer.writerIndex());
|
assertEquals(length, buffer.writerIndex());
|
||||||
|
@ -18,8 +18,8 @@ package io.netty.buffer;
|
|||||||
public class WrappedCompositeByteBufTest extends BigEndianCompositeByteBufTest {
|
public class WrappedCompositeByteBufTest extends BigEndianCompositeByteBufTest {
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected final ByteBuf newBuffer(int length) {
|
protected final ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
return wrap((CompositeByteBuf) super.newBuffer(length));
|
return wrap((CompositeByteBuf) super.newBuffer(length, maxCapacity));
|
||||||
}
|
}
|
||||||
|
|
||||||
protected WrappedCompositeByteBuf wrap(CompositeByteBuf buffer) {
|
protected WrappedCompositeByteBuf wrap(CompositeByteBuf buffer) {
|
||||||
|
@ -32,7 +32,9 @@ public class WrappedUnpooledUnsafeByteBufTest extends BigEndianUnsafeDirectByteB
|
|||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
protected ByteBuf newBuffer(int length) {
|
protected ByteBuf newBuffer(int length, int maxCapacity) {
|
||||||
|
Assume.assumeTrue(maxCapacity == Integer.MAX_VALUE);
|
||||||
|
|
||||||
return new WrappedUnpooledUnsafeDirectByteBuf(UnpooledByteBufAllocator.DEFAULT,
|
return new WrappedUnpooledUnsafeDirectByteBuf(UnpooledByteBufAllocator.DEFAULT,
|
||||||
PlatformDependent.allocateMemory(length), length, true);
|
PlatformDependent.allocateMemory(length), length, true);
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user