Java Code Examples for org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#duplicate()

The following examples show how to use org.apache.flink.shaded.netty4.io.netty.buffer.ByteBuf#duplicate() . 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 vote down vote up
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 vote down vote up
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 3
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 6 votes vote down vote up
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 4
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
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 5
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
@Test
public void testSliceAfterReleaseRetainedSliceDuplicate() {
    ByteBuf buf = newBuffer(1);
    ByteBuf buf2 = buf.retainedSlice(0, 1);
    ByteBuf buf3 = buf2.duplicate();
    assertSliceFailAfterRelease(buf, buf2, buf3);
}
 
Example 6
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSliceAfterReleaseRetainedSliceDuplicate() {
    ByteBuf buf = newBuffer(1);
    ByteBuf buf2 = buf.retainedSlice(0, 1);
    ByteBuf buf3 = buf2.duplicate();
    assertSliceFailAfterRelease(buf, buf2, buf3);
}
 
Example 7
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 5 votes vote down vote up
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 8
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testSliceAfterReleaseRetainedSliceDuplicate() {
    ByteBuf buf = newBuffer(1);
    ByteBuf buf2 = buf.retainedSlice(0, 1);
    ByteBuf buf3 = buf2.duplicate();
    assertSliceFailAfterRelease(buf, buf2, buf3);
}
 
Example 9
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
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 10
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicateAfterReleaseRetainedSliceDuplicate() {
    ByteBuf buf = newBuffer(1);
    ByteBuf buf2 = buf.retainedSlice(0, 1);
    ByteBuf buf3 = buf2.duplicate();
    assertDuplicateFailAfterRelease(buf, buf2, buf3);
}
 
Example 11
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 5 votes vote down vote up
@Test
public void testDuplicateAfterReleaseRetainedSliceDuplicate() {
    ByteBuf buf = newBuffer(1);
    ByteBuf buf2 = buf.retainedSlice(0, 1);
    ByteBuf buf3 = buf2.duplicate();
    assertDuplicateFailAfterRelease(buf, buf2, buf3);
}
 
Example 12
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
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 13
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
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 14
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@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 15
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testRetainedDuplicateAfterReleaseDuplicate() {
    ByteBuf buf = newBuffer(1);
    ByteBuf buf2 = buf.duplicate();
    assertRetainedDuplicateFailAfterRelease(buf, buf2);
}
 
Example 16
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@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 17
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@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());
}
 
Example 18
Source File: AbstractByteBufTest.java    From flink with Apache License 2.0 4 votes vote down vote up
@Test
public void testRetainedDuplicateAfterReleaseDuplicate() {
    ByteBuf buf = newBuffer(1);
    ByteBuf buf2 = buf.duplicate();
    assertRetainedDuplicateFailAfterRelease(buf, buf2);
}
 
Example 19
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@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 20
Source File: AbstractByteBufTest.java    From Flink-CEPplus with Apache License 2.0 4 votes vote down vote up
@Test
public void testRetainedDuplicateAfterReleaseDuplicate() {
    ByteBuf buf = newBuffer(1);
    ByteBuf buf2 = buf.duplicate();
    assertRetainedDuplicateFailAfterRelease(buf, buf2);
}