Home / Class/ ByteBufChecksumTest Class — netty Architecture

ByteBufChecksumTest Class — netty Architecture

Architecture documentation for the ByteBufChecksumTest class in ByteBufChecksumTest.java from the netty codebase.

Entity Profile

Dependency Diagram

graph TD
  03780e5e_15f9_cd44_a0a4_a5867c41c73a["ByteBufChecksumTest"]
  9447776f_b6b3_c5ba_177f_b3947d974ddd["ByteBufChecksumTest.java"]
  03780e5e_15f9_cd44_a0a4_a5867c41c73a -->|defined in| 9447776f_b6b3_c5ba_177f_b3947d974ddd
  92b87d53_d136_65a9_75f5_01801cb89244["setUp()"]
  03780e5e_15f9_cd44_a0a4_a5867c41c73a -->|method| 92b87d53_d136_65a9_75f5_01801cb89244
  e2eddb52_9c0d_8dde_ddd8_f2879d52ba8f["testHeapByteBufUpdate()"]
  03780e5e_15f9_cd44_a0a4_a5867c41c73a -->|method| e2eddb52_9c0d_8dde_ddd8_f2879d52ba8f
  7e110919_88ca_6c56_80e0_c3a02565e883["testDirectByteBufUpdate()"]
  03780e5e_15f9_cd44_a0a4_a5867c41c73a -->|method| 7e110919_88ca_6c56_80e0_c3a02565e883
  2a0863fd_970f_c06b_d5c7_c29e80b65317["testUpdate()"]
  03780e5e_15f9_cd44_a0a4_a5867c41c73a -->|method| 2a0863fd_970f_c06b_d5c7_c29e80b65317
  b3af53f1_62b3_118f_43fc_4c21d6b0353b["Checksum()"]
  03780e5e_15f9_cd44_a0a4_a5867c41c73a -->|method| b3af53f1_62b3_118f_43fc_4c21d6b0353b

Relationship Graph

Source Code

codec-compression/src/test/java/io/netty/handler/codec/compression/ByteBufChecksumTest.java lines 32–90

public class ByteBufChecksumTest {

    private static final byte[] BYTE_ARRAY = new byte[1024];

    @BeforeAll
    public static void setUp() {
        new Random().nextBytes(BYTE_ARRAY);
    }

    @Test
    public void testHeapByteBufUpdate() {
        testUpdate(Unpooled.wrappedBuffer(BYTE_ARRAY));
    }

    @Test
    public void testDirectByteBufUpdate() {
        ByteBuf buf = Unpooled.directBuffer(BYTE_ARRAY.length);
        buf.writeBytes(BYTE_ARRAY);
        testUpdate(buf);
    }

    private static void testUpdate(ByteBuf buf) {
        try {
            // all variations of xxHash32: slow and naive, optimised, wrapped optimised;
            // the last two should be literally identical, but it's best to guard against
            // an accidental regression in ByteBufChecksum#wrapChecksum(Checksum)
            testUpdate(xxHash32(DEFAULT_SEED), ByteBufChecksum.wrapChecksum(xxHash32(DEFAULT_SEED)), buf);
            testUpdate(xxHash32(DEFAULT_SEED), new Lz4XXHash32(DEFAULT_SEED), buf);
            testUpdate(xxHash32(DEFAULT_SEED), ByteBufChecksum.wrapChecksum(new Lz4XXHash32(DEFAULT_SEED)), buf);

            // CRC32 and Adler32, special-cased to use ReflectiveByteBufChecksum
            testUpdate(new CRC32(), ByteBufChecksum.wrapChecksum(new CRC32()), buf);
            testUpdate(new Adler32(), ByteBufChecksum.wrapChecksum(new Adler32()), buf);
        } finally {
            buf.release();
        }
    }

    private static void testUpdate(Checksum checksum, ByteBufChecksum wrapped, ByteBuf buf) {
        testUpdate(checksum, wrapped, buf, 0, BYTE_ARRAY.length);
        testUpdate(checksum, wrapped, buf, 0, BYTE_ARRAY.length - 1);
        testUpdate(checksum, wrapped, buf, 1, BYTE_ARRAY.length - 1);
        testUpdate(checksum, wrapped, buf, 1, BYTE_ARRAY.length - 2);
    }

    private static void testUpdate(Checksum checksum, ByteBufChecksum wrapped, ByteBuf buf, int off, int len) {
        checksum.reset();
        wrapped.reset();

        checksum.update(BYTE_ARRAY, off, len);
        wrapped.update(buf, off, len);

        assertEquals(checksum.getValue(), wrapped.getValue());
    }

    private static Checksum xxHash32(int seed) {
        return XXHashFactory.fastestInstance().newStreamingHash32(seed).asChecksum();
    }
}

Frequently Asked Questions

What is the ByteBufChecksumTest class?
ByteBufChecksumTest is a class in the netty codebase, defined in codec-compression/src/test/java/io/netty/handler/codec/compression/ByteBufChecksumTest.java.
Where is ByteBufChecksumTest defined?
ByteBufChecksumTest is defined in codec-compression/src/test/java/io/netty/handler/codec/compression/ByteBufChecksumTest.java at line 32.

Analyze Your Own Codebase

Get architecture documentation, dependency graphs, and domain analysis for your codebase in minutes.

Try Supermodel Free