Java Code Examples for org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#retainedDuplicate()
The following examples show how to use
org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#retainedDuplicate() .
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 | 6 votes |
private void testDuplicateContents(boolean retainedDuplicate) { ByteBuf buf = newBuffer(8).resetWriterIndex(); buf.writeBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); ByteBuf dup = retainedDuplicate ? buf.retainedDuplicate() : buf.duplicate(); try { assertEquals(0, dup.compareTo(buf)); assertEquals(0, dup.compareTo(dup.duplicate())); ByteBuf b = dup.retainedDuplicate(); assertEquals(0, dup.compareTo(b)); b.release(); assertEquals(0, dup.compareTo(dup.slice(dup.readerIndex(), dup.readableBytes()))); } finally { if (retainedDuplicate) { dup.release(); } buf.release(); } }
Example 2
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 6 votes |
private void testSliceContents(boolean retainedSlice) { ByteBuf buf = newBuffer(8).resetWriterIndex(); ByteBuf expected = newBuffer(3).resetWriterIndex(); buf.writeBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); expected.writeBytes(new byte[] {4, 5, 6}); ByteBuf slice = retainedSlice ? buf.retainedSlice(buf.readerIndex() + 3, 3) : buf.slice(buf.readerIndex() + 3, 3); try { assertEquals(0, slice.compareTo(expected)); assertEquals(0, slice.compareTo(slice.duplicate())); ByteBuf b = slice.retainedDuplicate(); assertEquals(0, slice.compareTo(b)); b.release(); assertEquals(0, slice.compareTo(slice.slice(0, slice.capacity()))); } finally { if (retainedSlice) { slice.release(); } buf.release(); expected.release(); } }
Example 3
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testRetainedSliceAfterReleaseRetainedSliceRetainedDuplicate() { ByteBuf buf = newBuffer(1); ByteBuf buf2 = buf.retainedSlice(0, 1); ByteBuf buf3 = buf2.retainedDuplicate(); assertRetainedSliceFailAfterRelease(buf, buf2, buf3); }
Example 4
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSliceAfterReleaseRetainedDuplicateSlice() { ByteBuf buf = newBuffer(1); ByteBuf buf2 = buf.retainedDuplicate(); ByteBuf buf3 = buf2.slice(0, 1); assertSliceFailAfterRelease(buf, buf2, buf3); }
Example 5
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void testDuplicateReleaseOriginal(boolean retainedDuplicate1, boolean retainedDuplicate2) { ByteBuf buf = newBuffer(8).resetWriterIndex(); ByteBuf expected = newBuffer(8).resetWriterIndex(); buf.writeBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); expected.writeBytes(buf, buf.readerIndex(), buf.readableBytes()); ByteBuf dup1 = retainedDuplicate1 ? buf.retainedDuplicate() : buf.duplicate().retain(); assertEquals(0, dup1.compareTo(expected)); // Simulate a handler that releases the original buffer, and propagates a slice. buf.release(); ByteBuf dup2 = retainedDuplicate2 ? dup1.retainedDuplicate() : dup1.duplicate().retain(); assertEquals(0, dup2.compareTo(expected)); // Cleanup the expected buffers used for testing. assertTrue(expected.release()); // The handler created a slice of the slice and is now done with it. dup2.release(); // The handler is now done with the original slice assertTrue(dup1.release()); // Reference counting may be shared, or may be independently tracked, but at this point all buffers should // be deallocated and have a reference count of 0. assertEquals(0, buf.refCnt()); assertEquals(0, dup1.refCnt()); assertEquals(0, dup2.refCnt()); }
Example 6
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testRetainedSliceAfterReleaseRetainedSliceRetainedDuplicate() { ByteBuf buf = newBuffer(1); ByteBuf buf2 = buf.retainedSlice(0, 1); ByteBuf buf3 = buf2.retainedDuplicate(); assertRetainedSliceFailAfterRelease(buf, buf2, buf3); }
Example 7
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSliceAfterReleaseRetainedDuplicateSlice() { ByteBuf buf = newBuffer(1); ByteBuf buf2 = buf.retainedDuplicate(); ByteBuf buf3 = buf2.slice(0, 1); assertSliceFailAfterRelease(buf, buf2, buf3); }
Example 8
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
private void testRetainedDuplicateUnreleasable(boolean initRetainedDuplicate, boolean finalRetainedDuplicate) { ByteBuf buf = newBuffer(8); ByteBuf buf1 = initRetainedDuplicate ? buf.retainedDuplicate() : buf.duplicate().retain(); ByteBuf buf2 = unreleasableBuffer(buf1); ByteBuf buf3 = finalRetainedDuplicate ? buf2.retainedDuplicate() : buf2.duplicate().retain(); assertFalse(buf3.release()); assertFalse(buf2.release()); buf1.release(); assertTrue(buf.release()); assertEquals(0, buf1.refCnt()); assertEquals(0, buf.refCnt()); }
Example 9
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 5 votes |
@Test public void testSliceAfterReleaseRetainedSliceRetainedDuplicate() { ByteBuf buf = newBuffer(1); ByteBuf buf2 = buf.retainedSlice(0, 1); ByteBuf buf3 = buf2.retainedDuplicate(); assertSliceFailAfterRelease(buf, buf2, buf3); }
Example 10
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 11
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testRetainedSliceAfterReleaseRetainedSliceRetainedDuplicate() { ByteBuf buf = newBuffer(1); ByteBuf buf2 = buf.retainedSlice(0, 1); ByteBuf buf3 = buf2.retainedDuplicate(); assertRetainedSliceFailAfterRelease(buf, buf2, buf3); }
Example 12
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 5 votes |
@Test public void testSliceAfterReleaseRetainedDuplicateSlice() { ByteBuf buf = newBuffer(1); ByteBuf buf2 = buf.retainedDuplicate(); ByteBuf buf3 = buf2.slice(0, 1); assertSliceFailAfterRelease(buf, buf2, buf3); }
Example 13
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testRetainedSliceAndRetainedDuplicateContentIsExpected() { ByteBuf buf = newBuffer(8).resetWriterIndex(); ByteBuf expected1 = newBuffer(6).resetWriterIndex(); ByteBuf expected2 = newBuffer(5).resetWriterIndex(); ByteBuf expected3 = newBuffer(4).resetWriterIndex(); ByteBuf expected4 = newBuffer(3).resetWriterIndex(); buf.writeBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); expected1.writeBytes(new byte[] {2, 3, 4, 5, 6, 7}); expected2.writeBytes(new byte[] {3, 4, 5, 6, 7}); expected3.writeBytes(new byte[] {4, 5, 6, 7}); expected4.writeBytes(new byte[] {5, 6, 7}); ByteBuf slice1 = buf.retainedSlice(buf.readerIndex() + 1, 6); assertEquals(0, slice1.compareTo(expected1)); assertEquals(0, slice1.compareTo(buf.slice(buf.readerIndex() + 1, 6))); // Simulate a handler that releases the original buffer, and propagates a slice. buf.release(); // Advance the reader index on the slice. slice1.readByte(); ByteBuf dup1 = slice1.retainedDuplicate(); assertEquals(0, dup1.compareTo(expected2)); assertEquals(0, dup1.compareTo(slice1.duplicate())); // Advance the reader index on dup1. dup1.readByte(); ByteBuf dup2 = dup1.duplicate(); assertEquals(0, dup2.compareTo(expected3)); // Advance the reader index on dup2. dup2.readByte(); ByteBuf slice2 = dup2.retainedSlice(dup2.readerIndex(), 3); assertEquals(0, slice2.compareTo(expected4)); assertEquals(0, slice2.compareTo(dup2.slice(dup2.readerIndex(), 3))); // Cleanup the expected buffers used for testing. assertTrue(expected1.release()); assertTrue(expected2.release()); assertTrue(expected3.release()); assertTrue(expected4.release()); slice2.release(); dup2.release(); assertEquals(slice2.refCnt(), dup2.refCnt()); assertEquals(dup2.refCnt(), dup1.refCnt()); // The handler is now done with the original slice assertTrue(slice1.release()); // Reference counting may be shared, or may be independently tracked, but at this point all buffers should // be deallocated and have a reference count of 0. assertEquals(0, buf.refCnt()); assertEquals(0, slice1.refCnt()); assertEquals(0, slice2.refCnt()); assertEquals(0, dup1.refCnt()); assertEquals(0, dup2.refCnt()); }
Example 14
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 4 votes |
private void testMultipleLevelRetainedSliceWithNonRetained(boolean doSlice1, boolean doSlice2) { ByteBuf buf = newBuffer(8).resetWriterIndex(); ByteBuf expected1 = newBuffer(6).resetWriterIndex(); ByteBuf expected2 = newBuffer(4).resetWriterIndex(); ByteBuf expected3 = newBuffer(2).resetWriterIndex(); ByteBuf expected4SliceSlice = newBuffer(1).resetWriterIndex(); ByteBuf expected4DupSlice = newBuffer(1).resetWriterIndex(); buf.writeBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); expected1.writeBytes(new byte[] {2, 3, 4, 5, 6, 7}); expected2.writeBytes(new byte[] {3, 4, 5, 6}); expected3.writeBytes(new byte[] {4, 5}); expected4SliceSlice.writeBytes(new byte[] {5}); expected4DupSlice.writeBytes(new byte[] {4}); ByteBuf slice1 = buf.retainedSlice(buf.readerIndex() + 1, 6); assertEquals(0, slice1.compareTo(expected1)); // Simulate a handler that releases the original buffer, and propagates a slice. buf.release(); ByteBuf slice2 = slice1.retainedSlice(slice1.readerIndex() + 1, 4); assertEquals(0, slice2.compareTo(expected2)); assertEquals(0, slice2.compareTo(slice2.duplicate())); assertEquals(0, slice2.compareTo(slice2.slice())); ByteBuf tmpBuf = slice2.retainedDuplicate(); assertEquals(0, slice2.compareTo(tmpBuf)); tmpBuf.release(); tmpBuf = slice2.retainedSlice(); assertEquals(0, slice2.compareTo(tmpBuf)); tmpBuf.release(); ByteBuf slice3 = doSlice1 ? slice2.slice(slice2.readerIndex() + 1, 2) : slice2.duplicate(); if (doSlice1) { assertEquals(0, slice3.compareTo(expected3)); } else { assertEquals(0, slice3.compareTo(expected2)); } ByteBuf slice4 = doSlice2 ? slice3.slice(slice3.readerIndex() + 1, 1) : slice3.duplicate(); if (doSlice1 && doSlice2) { assertEquals(0, slice4.compareTo(expected4SliceSlice)); } else if (doSlice2) { assertEquals(0, slice4.compareTo(expected4DupSlice)); } else { assertEquals(0, slice3.compareTo(slice4)); } // Cleanup the expected buffers used for testing. assertTrue(expected1.release()); assertTrue(expected2.release()); assertTrue(expected3.release()); assertTrue(expected4SliceSlice.release()); assertTrue(expected4DupSlice.release()); // Slice 4, 3, and 2 should effectively "share" a reference count. slice4.release(); assertEquals(slice3.refCnt(), slice2.refCnt()); assertEquals(slice3.refCnt(), slice4.refCnt()); // Slice 1 should also release the original underlying buffer without throwing exceptions assertTrue(slice1.release()); // Reference counting may be shared, or may be independently tracked, but at this point all buffers should // be deallocated and have a reference count of 0. assertEquals(0, buf.refCnt()); assertEquals(0, slice1.refCnt()); assertEquals(0, slice2.refCnt()); assertEquals(0, slice3.refCnt()); }
Example 15
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 4 votes |
private void testMultipleLevelRetainedSliceWithNonRetained(boolean doSlice1, boolean doSlice2) { ByteBuf buf = newBuffer(8).resetWriterIndex(); ByteBuf expected1 = newBuffer(6).resetWriterIndex(); ByteBuf expected2 = newBuffer(4).resetWriterIndex(); ByteBuf expected3 = newBuffer(2).resetWriterIndex(); ByteBuf expected4SliceSlice = newBuffer(1).resetWriterIndex(); ByteBuf expected4DupSlice = newBuffer(1).resetWriterIndex(); buf.writeBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); expected1.writeBytes(new byte[] {2, 3, 4, 5, 6, 7}); expected2.writeBytes(new byte[] {3, 4, 5, 6}); expected3.writeBytes(new byte[] {4, 5}); expected4SliceSlice.writeBytes(new byte[] {5}); expected4DupSlice.writeBytes(new byte[] {4}); ByteBuf slice1 = buf.retainedSlice(buf.readerIndex() + 1, 6); assertEquals(0, slice1.compareTo(expected1)); // Simulate a handler that releases the original buffer, and propagates a slice. buf.release(); ByteBuf slice2 = slice1.retainedSlice(slice1.readerIndex() + 1, 4); assertEquals(0, slice2.compareTo(expected2)); assertEquals(0, slice2.compareTo(slice2.duplicate())); assertEquals(0, slice2.compareTo(slice2.slice())); ByteBuf tmpBuf = slice2.retainedDuplicate(); assertEquals(0, slice2.compareTo(tmpBuf)); tmpBuf.release(); tmpBuf = slice2.retainedSlice(); assertEquals(0, slice2.compareTo(tmpBuf)); tmpBuf.release(); ByteBuf slice3 = doSlice1 ? slice2.slice(slice2.readerIndex() + 1, 2) : slice2.duplicate(); if (doSlice1) { assertEquals(0, slice3.compareTo(expected3)); } else { assertEquals(0, slice3.compareTo(expected2)); } ByteBuf slice4 = doSlice2 ? slice3.slice(slice3.readerIndex() + 1, 1) : slice3.duplicate(); if (doSlice1 && doSlice2) { assertEquals(0, slice4.compareTo(expected4SliceSlice)); } else if (doSlice2) { assertEquals(0, slice4.compareTo(expected4DupSlice)); } else { assertEquals(0, slice3.compareTo(slice4)); } // Cleanup the expected buffers used for testing. assertTrue(expected1.release()); assertTrue(expected2.release()); assertTrue(expected3.release()); assertTrue(expected4SliceSlice.release()); assertTrue(expected4DupSlice.release()); // Slice 4, 3, and 2 should effectively "share" a reference count. slice4.release(); assertEquals(slice3.refCnt(), slice2.refCnt()); assertEquals(slice3.refCnt(), slice4.refCnt()); // Slice 1 should also release the original underlying buffer without throwing exceptions assertTrue(slice1.release()); // Reference counting may be shared, or may be independently tracked, but at this point all buffers should // be deallocated and have a reference count of 0. assertEquals(0, buf.refCnt()); assertEquals(0, slice1.refCnt()); assertEquals(0, slice2.refCnt()); assertEquals(0, slice3.refCnt()); }
Example 16
Source File: AbstractByteBufTest.java From Flink-CEPplus with Apache License 2.0 | 4 votes |
@Test public void testDuplicateAfterReleaseRetainedDuplicate() { ByteBuf buf = newBuffer(1); ByteBuf buf2 = buf.retainedDuplicate(); assertDuplicateFailAfterRelease(buf, buf2); }
Example 17
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testRetainedSliceAfterReleaseRetainedDuplicate() { ByteBuf buf = newBuffer(1); ByteBuf buf2 = buf.retainedDuplicate(); assertRetainedSliceFailAfterRelease(buf, buf2); }
Example 18
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 4 votes |
private void testMultipleRetainedDuplicateReleaseOriginal(boolean retainedDuplicate1, boolean retainedDuplicate2) { ByteBuf buf = newBuffer(8).resetWriterIndex(); ByteBuf expected = newBuffer(8).resetWriterIndex(); buf.writeBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); expected.writeBytes(buf, buf.readerIndex(), buf.readableBytes()); ByteBuf dup1 = retainedDuplicate1 ? buf.retainedDuplicate() : buf.duplicate().retain(); assertEquals(0, dup1.compareTo(expected)); // Simulate a handler that releases the original buffer, and propagates a slice. buf.release(); ByteBuf dup2 = retainedDuplicate2 ? dup1.retainedDuplicate() : dup1.duplicate().retain(); assertEquals(0, dup2.compareTo(expected)); assertEquals(0, dup2.compareTo(dup2.duplicate())); assertEquals(0, dup2.compareTo(dup2.slice())); ByteBuf tmpBuf = dup2.retainedDuplicate(); assertEquals(0, dup2.compareTo(tmpBuf)); tmpBuf.release(); tmpBuf = dup2.retainedSlice(); assertEquals(0, dup2.compareTo(tmpBuf)); tmpBuf.release(); // The handler created a slice of the slice and is now done with it. dup2.release(); ByteBuf dup3 = dup1.retainedDuplicate(); assertEquals(0, dup3.compareTo(expected)); // The handler created another slice of the slice and is now done with it. dup3.release(); // The handler is now done with the original slice assertTrue(dup1.release()); // Cleanup the expected buffers used for testing. assertTrue(expected.release()); // Reference counting may be shared, or may be independently tracked, but at this point all buffers should // be deallocated and have a reference count of 0. assertEquals(0, buf.refCnt()); assertEquals(0, dup1.refCnt()); assertEquals(0, dup2.refCnt()); assertEquals(0, dup3.refCnt()); }
Example 19
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testSliceAfterReleaseRetainedDuplicate() { ByteBuf buf = newBuffer(1); ByteBuf buf2 = buf.retainedDuplicate(); assertSliceFailAfterRelease(buf, buf2); }
Example 20
Source File: AbstractByteBufTest.java From flink with Apache License 2.0 | 4 votes |
@Test public void testRetainedDuplicateAndRetainedSliceContentIsExpected() { ByteBuf buf = newBuffer(8).resetWriterIndex(); ByteBuf expected1 = newBuffer(6).resetWriterIndex(); ByteBuf expected2 = newBuffer(5).resetWriterIndex(); ByteBuf expected3 = newBuffer(4).resetWriterIndex(); buf.writeBytes(new byte[] {1, 2, 3, 4, 5, 6, 7, 8}); expected1.writeBytes(new byte[] {2, 3, 4, 5, 6, 7}); expected2.writeBytes(new byte[] {3, 4, 5, 6, 7}); expected3.writeBytes(new byte[] {5, 6, 7}); ByteBuf dup1 = buf.retainedDuplicate(); assertEquals(0, dup1.compareTo(buf)); assertEquals(0, dup1.compareTo(buf.slice())); // Simulate a handler that releases the original buffer, and propagates a slice. buf.release(); // Advance the reader index on the dup. dup1.readByte(); ByteBuf slice1 = dup1.retainedSlice(dup1.readerIndex(), 6); assertEquals(0, slice1.compareTo(expected1)); assertEquals(0, slice1.compareTo(slice1.duplicate())); // Advance the reader index on slice1. slice1.readByte(); ByteBuf dup2 = slice1.duplicate(); assertEquals(0, dup2.compareTo(slice1)); // Advance the reader index on dup2. dup2.readByte(); ByteBuf slice2 = dup2.retainedSlice(dup2.readerIndex() + 1, 3); assertEquals(0, slice2.compareTo(expected3)); assertEquals(0, slice2.compareTo(dup2.slice(dup2.readerIndex() + 1, 3))); // Cleanup the expected buffers used for testing. assertTrue(expected1.release()); assertTrue(expected2.release()); assertTrue(expected3.release()); slice2.release(); slice1.release(); assertEquals(slice2.refCnt(), dup2.refCnt()); assertEquals(dup2.refCnt(), slice1.refCnt()); // The handler is now done with the original slice assertTrue(dup1.release()); // Reference counting may be shared, or may be independently tracked, but at this point all buffers should // be deallocated and have a reference count of 0. assertEquals(0, buf.refCnt()); assertEquals(0, slice1.refCnt()); assertEquals(0, slice2.refCnt()); assertEquals(0, dup1.refCnt()); assertEquals(0, dup2.refCnt()); }