Java Code Examples for org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#clear()
The following examples show how to use
org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#clear() .
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-CEPplus with Apache License 2.0 | 6 votes |
@Test public void testRandomHeapBufferTransfer1() { byte[] valueContent = new byte[BLOCK_SIZE]; ByteBuf value = wrappedBuffer(valueContent); for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) { random.nextBytes(valueContent); value.setIndex(0, BLOCK_SIZE); buffer.setBytes(i, value); assertEquals(BLOCK_SIZE, value.readerIndex()); assertEquals(BLOCK_SIZE, value.writerIndex()); } random.setSeed(seed); byte[] expectedValueContent = new byte[BLOCK_SIZE]; ByteBuf expectedValue = wrappedBuffer(expectedValueContent); for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) { random.nextBytes(expectedValueContent); value.clear(); buffer.getBytes(i, value); assertEquals(0, value.readerIndex()); assertEquals(BLOCK_SIZE, value.writerIndex()); for (int j = 0; j < BLOCK_SIZE; j ++) { assertEquals(expectedValue.getByte(j), value.getByte(j)); } } }
Example 2
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testRandomHeapBufferTransfer1() { byte[] valueContent = new byte[BLOCK_SIZE]; ByteBuf value = wrappedBuffer(valueContent); for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) { random.nextBytes(valueContent); value.setIndex(0, BLOCK_SIZE); buffer.setBytes(i, value); assertEquals(BLOCK_SIZE, value.readerIndex()); assertEquals(BLOCK_SIZE, value.writerIndex()); } random.setSeed(seed); byte[] expectedValueContent = new byte[BLOCK_SIZE]; ByteBuf expectedValue = wrappedBuffer(expectedValueContent); for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) { random.nextBytes(expectedValueContent); value.clear(); buffer.getBytes(i, value); assertEquals(0, value.readerIndex()); assertEquals(BLOCK_SIZE, value.writerIndex()); for (int j = 0; j < BLOCK_SIZE; j ++) { assertEquals(expectedValue.getByte(j), value.getByte(j)); } } }
Example 3
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 6 votes |
@Test public void testRandomHeapBufferTransfer1() { byte[] valueContent = new byte[BLOCK_SIZE]; ByteBuf value = wrappedBuffer(valueContent); for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) { random.nextBytes(valueContent); value.setIndex(0, BLOCK_SIZE); buffer.setBytes(i, value); assertEquals(BLOCK_SIZE, value.readerIndex()); assertEquals(BLOCK_SIZE, value.writerIndex()); } random.setSeed(seed); byte[] expectedValueContent = new byte[BLOCK_SIZE]; ByteBuf expectedValue = wrappedBuffer(expectedValueContent); for (int i = 0; i < buffer.capacity() - BLOCK_SIZE + 1; i += BLOCK_SIZE) { random.nextBytes(expectedValueContent); value.clear(); buffer.getBytes(i, value); assertEquals(0, value.readerIndex()); assertEquals(BLOCK_SIZE, value.writerIndex()); for (int j = 0; j < BLOCK_SIZE; j ++) { assertEquals(expectedValue.getByte(j), value.getByte(j)); } } }
Example 4
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private ByteBuf releasedBuffer() { ByteBuf buffer = newBuffer(8); // Clear the buffer so we are sure the reader and writer indices are 0. // This is important as we may return a slice from newBuffer(...). buffer.clear(); assertTrue(buffer.release()); return buffer; }
Example 5
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testEmptyNioBuffers() throws Exception { ByteBuf buffer = newBuffer(8); buffer.clear(); assertFalse(buffer.isReadable()); ByteBuffer[] nioBuffers = buffer.nioBuffers(); assertEquals(1, nioBuffers.length); assertFalse(nioBuffers[0].hasRemaining()); buffer.release(); }
Example 6
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
private ByteBuf releasedBuffer() { ByteBuf buffer = newBuffer(8); // Clear the buffer so we are sure the reader and writer indices are 0. // This is important as we may return a slice from newBuffer(...). buffer.clear(); assertTrue(buffer.release()); return buffer; }
Example 7
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testEmptyNioBuffers() throws Exception { ByteBuf buffer = newBuffer(8); buffer.clear(); assertFalse(buffer.isReadable()); ByteBuffer[] nioBuffers = buffer.nioBuffers(); assertEquals(1, nioBuffers.length); assertFalse(nioBuffers[0].hasRemaining()); buffer.release(); }
Example 8
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
private ByteBuf releasedBuffer() { ByteBuf buffer = newBuffer(8); // Clear the buffer so we are sure the reader and writer indices are 0. // This is important as we may return a slice from newBuffer(...). buffer.clear(); assertTrue(buffer.release()); return buffer; }
Example 9
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testEmptyNioBuffers() throws Exception { ByteBuf buffer = newBuffer(8); buffer.clear(); assertFalse(buffer.isReadable()); ByteBuffer[] nioBuffers = buffer.nioBuffers(); assertEquals(1, nioBuffers.length); assertFalse(nioBuffers[0].hasRemaining()); buffer.release(); }