Skip to content

Include pending tests for bugfix related to Kafka messages with UUID record keys #699

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 5 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,7 @@
import java.util.Collections;
import java.util.HashSet;
import java.util.List;
import java.util.UUID;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
Expand Down Expand Up @@ -162,6 +163,30 @@ public void should_read_json_with_headers_in_record() throws IOException {
Assert.assertEquals(Collections.singletonMap("headerKey", "headerValue"), consumerJsonRecord.getHeaders());
}

@Test
public void should_read_json_with_headers_in_record_with_key_of_object_type() throws IOException {
// given
Object key = UUID.randomUUID();
ConsumerRecord consumerRecord = Mockito.mock(ConsumerRecord.class);
Mockito.when(consumerRecord.key()).thenReturn(key);
Mockito.when(consumerRecord.value()).thenReturn("\"value\"");
Mockito.when(consumerRecord.headers())
.thenReturn(new RecordHeaders().add("headerKey", "headerValue".getBytes()));

// when
List<ConsumerJsonRecord> consumerJsonRecords = new ArrayList<>();
KafkaConsumerHelper.readJson(consumerJsonRecords, Iterators.forArray(consumerRecord),null);

// then
Assert.assertEquals(1, consumerJsonRecords.size());
ConsumerJsonRecord consumerJsonRecord = consumerJsonRecords.get(0);
Assert.assertTrue(consumerJsonRecord.getKey() instanceof JsonNode);
Assert.assertTrue(consumerJsonRecord.getValue() instanceof JsonNode);
Assert.assertEquals("\"" +key+"\"", consumerJsonRecord.getKey().toString());
Assert.assertEquals("\"value\"", consumerJsonRecord.getValue().toString());
Assert.assertEquals(Collections.singletonMap("headerKey", "headerValue"), consumerJsonRecord.getHeaders());
}

@Test
public void test_firstPoll_exits_early_on_assignment() {

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@
import java.io.IOException;
import java.util.LinkedHashMap;
import java.util.Map;
import java.util.UUID;

import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.core.Is.is;
Expand All @@ -22,26 +23,33 @@ public class ConsumerJsonRecordTest {
@Test
public void testSer() throws IOException {
// TODO: Use assert iso sysout
JsonNode key = objectMapper.readTree("\"key1\"");
JsonNode key1 = objectMapper.readTree("\"key1\"");
JsonNode value = objectMapper.readTree("\"val1\"");

ConsumerJsonRecord record = new ConsumerJsonRecord(key, value, null);
ConsumerJsonRecord record = new ConsumerJsonRecord(key1, value, null);
String json = objectMapper.writeValueAsString(record);
System.out.println("1 json >> " + json);


JsonNode key1 = objectMapper.readTree("123");
JsonNode key2 = objectMapper.readTree("123");

record = new ConsumerJsonRecord(key1, value, null);
record = new ConsumerJsonRecord(key2, value, null);
json = objectMapper.writeValueAsString(record);
System.out.println("1 json >> " + json);
System.out.println("2 json >> " + json);


JsonNode key2 = objectMapper.readTree("23.45");
JsonNode key3 = objectMapper.readTree("23.45");

record = new ConsumerJsonRecord(key2, value, null);
record = new ConsumerJsonRecord(key3, value, null);
json = objectMapper.writeValueAsString(record);
System.out.println("2 json >> " + json);

// UUID/Object Key
JsonNode key4 = objectMapper.readTree(objectMapper.writeValueAsString(UUID.randomUUID().toString()));

record = new ConsumerJsonRecord(key4, value, null);
json = objectMapper.writeValueAsString(record);
System.out.println("4 json >> " + json);
}

@Test
Expand Down