-
Notifications
You must be signed in to change notification settings - Fork 52
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix segment deserializer bug for case when checksum=0 (#162)
- Loading branch information
1 parent
2cbbfdc
commit 1f981de
Showing
4 changed files
with
63 additions
and
30 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
41 changes: 41 additions & 0 deletions
41
...src/test/java/com/linkedin/kafka/clients/largemessage/DefaultSegmentDeserializerTest.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,41 @@ | ||
/* | ||
* Copyright 2020 LinkedIn Corp. Licensed under the BSD 2-Clause License (the "License"). See License in the project root for license information. | ||
*/ | ||
|
||
package com.linkedin.kafka.clients.largemessage; | ||
|
||
import java.nio.ByteBuffer; | ||
import java.util.Arrays; | ||
import java.util.UUID; | ||
import org.testng.Assert; | ||
import org.testng.annotations.Test; | ||
|
||
|
||
public class DefaultSegmentDeserializerTest { | ||
|
||
@Test | ||
public void testZeroChecksum() { | ||
DefaultSegmentSerializer segmentSerializer = new DefaultSegmentSerializer(); | ||
|
||
//doctor a UUID such that the projected checksum is 0 | ||
long a = (Long.MAX_VALUE / 2) - 1; | ||
long b = (Long.MAX_VALUE / 2) + 3; | ||
int checksum = (int) (a + b); | ||
|
||
Assert.assertEquals(checksum, 0, "projected checksum should be 0. instead was " + checksum); | ||
|
||
UUID msgId = new UUID(a, b); | ||
byte[] payload = new byte[] {0, 1, 2, 3, 4, 5, 6, 7, 8, 9}; | ||
LargeMessageSegment segment = new LargeMessageSegment(msgId, 0, 1, 10, ByteBuffer.wrap(payload)); | ||
|
||
byte[] serialized = segmentSerializer.serialize("topic", segment); | ||
|
||
DefaultSegmentDeserializer segmentDeserializer = new DefaultSegmentDeserializer(); | ||
|
||
LargeMessageSegment deserialized = segmentDeserializer.deserialize("topic", serialized); | ||
|
||
Assert.assertNotNull(deserialized); | ||
Assert.assertEquals(deserialized.messageId, msgId); | ||
Assert.assertTrue(Arrays.equals(payload, deserialized.payloadArray())); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters