UnsafeByteBufUtilTest Class — netty Architecture
Architecture documentation for the UnsafeByteBufUtilTest class in UnsafeByteBufUtilTest.java from the netty codebase.
Entity Profile
Dependency Diagram
graph TD 9a18ae5b_9169_5444_e060_c39f7f301455["UnsafeByteBufUtilTest"] f0f90de9_53bb_93fb_8b09_580e4f32d79a["UnsafeByteBufUtilTest.java"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|defined in| f0f90de9_53bb_93fb_8b09_580e4f32d79a 036fbcd6_6593_c828_e4c6_97af4d12171e["checkHasUnsafe()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| 036fbcd6_6593_c828_e4c6_97af4d12171e dedf2180_79a8_1238_c21f_db09c05bb774["testSetBytesOnReadOnlyByteBuffer()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| dedf2180_79a8_1238_c21f_db09c05bb774 f02794d5_922b_c111_0a81_b8a46286d4cb["testSetBytesOnReadOnlyByteBufferWithPooledAlloc()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| f02794d5_922b_c111_0a81_b8a46286d4cb 1a0e22f5_3c87_41bd_5224_9e2d9388cb8b["testSetBytesWithByteArray()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| 1a0e22f5_3c87_41bd_5224_9e2d9388cb8b 88fb454a_1c15_e22c_db36_64481e6feb12["testSetBytesWithZeroLength()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| 88fb454a_1c15_e22c_db36_64481e6feb12 71447cf4_2674_e1e7_2df6_02328f81be02["testSetBytesWithNullByteArray()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| 71447cf4_2674_e1e7_2df6_02328f81be02 bbd0a117_c8f4_f166_cba8_80777639d17e["testSetBytesOutOfBounds()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| bbd0a117_c8f4_f166_cba8_80777639d17e 13c60c0e_6a28_dc39_bee6_65a25759cce0["testSetBytesOutOfBounds2()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| 13c60c0e_6a28_dc39_bee6_65a25759cce0 a439ba26_9fd4_53d9_e217_6a3d32316a26["testSetBytesOutOfBounds3()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| a439ba26_9fd4_53d9_e217_6a3d32316a26 f5e59a17_59b9_093a_5b0f_3c559bd9fc44["testSetBytesOutOfBounds4()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| f5e59a17_59b9_093a_5b0f_3c559bd9fc44 3f11fde7_9376_fe06_43b2_5325d49440a4["testSetBytesOutOfBounds5()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| 3f11fde7_9376_fe06_43b2_5325d49440a4 eb11d713_8a0b_2a36_746a_046042b9a63d["testSetBytesOutOfBounds6()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| eb11d713_8a0b_2a36_746a_046042b9a63d cf3eacc1_387b_dfe7_bd15_0caf500e4f9b["testSetBytesOutOfBounds7()"] 9a18ae5b_9169_5444_e060_c39f7f301455 -->|method| cf3eacc1_387b_dfe7_bd15_0caf500e4f9b
Relationship Graph
Source Code
buffer/src/test/java/io/netty/buffer/UnsafeByteBufUtilTest.java lines 32–252
public class UnsafeByteBufUtilTest {
@BeforeEach
public void checkHasUnsafe() {
Assumptions.assumeTrue(PlatformDependent.hasUnsafe(), "sun.misc.Unsafe not found, skip tests");
}
@Test
public void testSetBytesOnReadOnlyByteBuffer() throws Exception {
byte[] testData = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int length = testData.length;
ByteBuffer readOnlyBuffer = ByteBuffer.wrap(testData).asReadOnlyBuffer();
UnpooledByteBufAllocator alloc = new UnpooledByteBufAllocator(true);
UnpooledDirectByteBuf targetBuffer = new UnpooledDirectByteBuf(alloc, length, length);
try {
UnsafeByteBufUtil.setBytes(targetBuffer, directBufferAddress(targetBuffer.nioBuffer()), 0, readOnlyBuffer);
byte[] check = new byte[length];
targetBuffer.getBytes(0, check, 0, length);
assertArrayEquals(testData, check, "The byte array's copy does not equal the original");
} finally {
targetBuffer.release();
}
}
@Test
public void testSetBytesOnReadOnlyByteBufferWithPooledAlloc() throws Exception {
byte[] testData = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
int length = testData.length;
ByteBuffer readOnlyBuffer = ByteBuffer.wrap(testData).asReadOnlyBuffer();
int pageSize = 4096;
// create memory pool with one page
ByteBufAllocator alloc = new PooledByteBufAllocator(true, 1, 1, pageSize, 0);
UnpooledDirectByteBuf targetBuffer = new UnpooledDirectByteBuf(alloc, length, length);
ByteBuf b1 = alloc.heapBuffer(16);
ByteBuf b2 = alloc.heapBuffer(16);
try {
// just check that two following buffers share same array but different offset
assertEquals(pageSize, b1.array().length);
assertArrayEquals(b1.array(), b2.array());
assertNotEquals(b1.arrayOffset(), b2.arrayOffset());
UnsafeByteBufUtil.setBytes(targetBuffer, directBufferAddress(targetBuffer.nioBuffer()), 0, readOnlyBuffer);
byte[] check = new byte[length];
targetBuffer.getBytes(0, check, 0, length);
assertArrayEquals(testData, check, "The byte array's copy does not equal the original");
} finally {
targetBuffer.release();
b1.release();
b2.release();
}
}
@Test
public void testSetBytesWithByteArray() {
final byte[] testData = {0, 1, 2, 3, 4, 5, 6, 7, 8, 9};
final int length = testData.length;
final UnpooledByteBufAllocator alloc = new UnpooledByteBufAllocator(true);
final UnpooledDirectByteBuf targetBuffer = new UnpooledDirectByteBuf(alloc, length, length);
try {
UnsafeByteBufUtil.setBytes(targetBuffer,
directBufferAddress(targetBuffer.nioBuffer()), 0, testData, 0, length);
final byte[] check = new byte[length];
targetBuffer.getBytes(0, check, 0, length);
assertArrayEquals(testData, check, "The byte array's copy does not equal the original");
} finally {
targetBuffer.release();
Source
Frequently Asked Questions
What is the UnsafeByteBufUtilTest class?
UnsafeByteBufUtilTest is a class in the netty codebase, defined in buffer/src/test/java/io/netty/buffer/UnsafeByteBufUtilTest.java.
Where is UnsafeByteBufUtilTest defined?
UnsafeByteBufUtilTest is defined in buffer/src/test/java/io/netty/buffer/UnsafeByteBufUtilTest.java at line 32.
Analyze Your Own Codebase
Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.
Try Supermodel Free