MCPcopy Create free account
hub / github.com/apache/kafka / CrcTest

Class CrcTest

clients/src/test/java/org/apache/kafka/common/utils/CrcTest.java:24–59  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

22import java.nio.ByteBuffer;
23
24public class CrcTest {
25
26 @Test
27 public void testUpdate() {
28 final byte bytes[] = "Any String you want".getBytes();
29 final int len = bytes.length;
30
31 Crc32 crc1 = new Crc32();
32 Crc32 crc2 = new Crc32();
33 Crc32 crc3 = new Crc32();
34
35 crc1.update(bytes, 0, len);
36 for(int i = 0; i < len; i++)
37 crc2.update(bytes[i]);
38 crc3.update(bytes, 0, len/2);
39 crc3.update(bytes, len/2, len-len/2);
40
41 assertEquals("Crc values should be the same", crc1.getValue(), crc2.getValue());
42 assertEquals("Crc values should be the same", crc1.getValue(), crc3.getValue());
43 }
44
45 @Test
46 public void testUpdateInt() {
47 final int value = 1000;
48 final ByteBuffer buffer = ByteBuffer.allocate(4);
49 buffer.putInt(value);
50
51 Crc32 crc1 = new Crc32();
52 Crc32 crc2 = new Crc32();
53
54 crc1.updateInt(value);
55 crc2.update(buffer.array(), buffer.arrayOffset(), 4);
56
57 assertEquals("Crc values should be the same", crc1.getValue(), crc2.getValue());
58 }
59}

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected