Java Code Examples for org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#capacity()
The following examples show how to use
org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#capacity() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
private void testDuplicateCapacityChange(boolean retainedDuplicate) { ByteBuf buf = newBuffer(8); ByteBuf dup = retainedDuplicate ? buf.retainedDuplicate() : buf.duplicate(); try { dup.capacity(10); assertEquals(buf.capacity(), dup.capacity()); dup.capacity(5); assertEquals(buf.capacity(), dup.capacity()); } finally { if (retainedDuplicate) { dup.release(); } buf.release(); } }
Example 2
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
private void testSliceCapacityChange(boolean retainedSlice) { ByteBuf buf = newBuffer(8); ByteBuf slice = retainedSlice ? buf.retainedSlice(buf.readerIndex() + 1, 3) : buf.slice(buf.readerIndex() + 1, 3); try { slice.capacity(10); } finally { if (retainedSlice) { slice.release(); } buf.release(); } }
Example 3
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
private void testDuplicateCapacityChange(boolean retainedDuplicate) { ByteBuf buf = newBuffer(8); ByteBuf dup = retainedDuplicate ? buf.retainedDuplicate() : buf.duplicate(); try { dup.capacity(10); assertEquals(buf.capacity(), dup.capacity()); dup.capacity(5); assertEquals(buf.capacity(), dup.capacity()); } finally { if (retainedDuplicate) { dup.release(); } buf.release(); } }
Example 4
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@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(); } }
Example 5
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testCopy() { for (int i = 0; i < buffer.capacity(); i ++) { byte value = (byte) random.nextInt(); buffer.setByte(i, value); } final int readerIndex = CAPACITY / 3; final int writerIndex = CAPACITY * 2 / 3; buffer.setIndex(readerIndex, writerIndex); // Make sure all properties are copied. ByteBuf copy = buffer.copy(); assertEquals(0, copy.readerIndex()); assertEquals(buffer.readableBytes(), copy.writerIndex()); assertEquals(buffer.readableBytes(), copy.capacity()); assertSame(buffer.order(), copy.order()); for (int i = 0; i < copy.capacity(); i ++) { assertEquals(buffer.getByte(i + readerIndex), copy.getByte(i)); } // Make sure the buffer content is independent from each other. buffer.setByte(readerIndex, (byte) (buffer.getByte(readerIndex) + 1)); assertTrue(buffer.getByte(readerIndex) != copy.getByte(0)); copy.setByte(1, (byte) (copy.getByte(1) + 1)); assertTrue(buffer.getByte(readerIndex + 1) != copy.getByte(1)); copy.release(); }
Example 6
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@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(); } }
Example 7
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@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(); } }
Example 8
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@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(); } }
Example 9
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@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(); } }
Example 10
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
private void testSliceCapacityChange(boolean retainedSlice) { ByteBuf buf = newBuffer(8); ByteBuf slice = retainedSlice ? buf.retainedSlice(buf.readerIndex() + 1, 3) : buf.slice(buf.readerIndex() + 1, 3); try { slice.capacity(10); } finally { if (retainedSlice) { slice.release(); } buf.release(); } }
Example 11
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testCopy() { for (int i = 0; i < buffer.capacity(); i ++) { byte value = (byte) random.nextInt(); buffer.setByte(i, value); } final int readerIndex = CAPACITY / 3; final int writerIndex = CAPACITY * 2 / 3; buffer.setIndex(readerIndex, writerIndex); // Make sure all properties are copied. ByteBuf copy = buffer.copy(); assertEquals(0, copy.readerIndex()); assertEquals(buffer.readableBytes(), copy.writerIndex()); assertEquals(buffer.readableBytes(), copy.capacity()); assertSame(buffer.order(), copy.order()); for (int i = 0; i < copy.capacity(); i ++) { assertEquals(buffer.getByte(i + readerIndex), copy.getByte(i)); } // Make sure the buffer content is independent from each other. buffer.setByte(readerIndex, (byte) (buffer.getByte(readerIndex) + 1)); assertTrue(buffer.getByte(readerIndex) != copy.getByte(0)); copy.setByte(1, (byte) (copy.getByte(1) + 1)); assertTrue(buffer.getByte(readerIndex + 1) != copy.getByte(1)); copy.release(); }
Example 12
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
private void testWriteCharSequenceExpand(Charset charset) { ByteBuf buf = newBuffer(1); try { int writerIndex = buf.capacity() - 1; buf.writerIndex(writerIndex); int written = buf.writeCharSequence("AB", charset); assertEquals(writerIndex, buf.writerIndex() - written); } finally { buf.release(); } }
Example 13
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@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(); } }
Example 14
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@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(); } }
Example 15
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@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(); } }
Example 16
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@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(); } }
Example 17
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@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(); } }
Example 18
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void testSliceCapacityChange(boolean retainedSlice) { ByteBuf buf = newBuffer(8); ByteBuf slice = retainedSlice ? buf.retainedSlice(buf.readerIndex() + 1, 3) : buf.slice(buf.readerIndex() + 1, 3); try { slice.capacity(10); } finally { if (retainedSlice) { slice.release(); } buf.release(); } }
Example 19
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void testDuplicateCapacityChange(boolean retainedDuplicate) { ByteBuf buf = newBuffer(8); ByteBuf dup = retainedDuplicate ? buf.retainedDuplicate() : buf.duplicate(); try { dup.capacity(10); assertEquals(buf.capacity(), dup.capacity()); dup.capacity(5); assertEquals(buf.capacity(), dup.capacity()); } finally { if (retainedDuplicate) { dup.release(); } buf.release(); } }
Example 20
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void testWriteCharSequenceExpand(Charset charset) { ByteBuf buf = newBuffer(1); try { int writerIndex = buf.capacity() - 1; buf.writerIndex(writerIndex); int written = buf.writeCharSequence("AB", charset); assertEquals(writerIndex, buf.writerIndex() - written); } finally { buf.release(); } }