-
Notifications
You must be signed in to change notification settings - Fork 15.1k
KAFKA-20173: Propagate headers into serde 7/N #21851
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
UladzislauBlok
wants to merge
7
commits into
apache:trunk
Choose a base branch
from
UladzislauBlok:bloku/kafka-20173-8
base: trunk
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
7 commits
Select commit
Hold shift + click to select a range
705d9c0
KAFKA-20173: Propagate headers into serde 7/N
UladzislauBlok fe32ff3
more deserializers
UladzislauBlok ab439cf
TimestampedKeyAndJoinSide Serde tests
UladzislauBlok dd10f77
Left or right serde tests
UladzislauBlok 7b31b22
small tests simplification
UladzislauBlok 4b934c4
SubscriptionResponseWrapperSerdeTest
UladzislauBlok 2175131
minor fix
UladzislauBlok File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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 hidden or 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
53 changes: 53 additions & 0 deletions
53
.../test/java/org/apache/kafka/streams/state/internals/LeftOrRightValueDeserializerTest.java
This file contains hidden or 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,53 @@ | ||
| /* | ||
| * Licensed to the Apache Software Foundation (ASF) under one or more | ||
| * contributor license agreements. See the NOTICE file distributed with | ||
| * this work for additional information regarding copyright ownership. | ||
| * The ASF licenses this file to You under the Apache License, Version 2.0 | ||
| * (the "License"); you may not use this file except in compliance with | ||
| * the License. You may obtain a copy of the License at | ||
| * | ||
| * http://www.apache.org/licenses/LICENSE-2.0 | ||
| * | ||
| * Unless required by applicable law or agreed to in writing, software | ||
| * distributed under the License is distributed on an "AS IS" BASIS, | ||
| * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
| * See the License for the specific language governing permissions and | ||
| * limitations under the License. | ||
| */ | ||
| package org.apache.kafka.streams.state.internals; | ||
|
|
||
| import org.apache.kafka.common.header.Headers; | ||
| import org.apache.kafka.common.header.internals.RecordHeaders; | ||
| import org.apache.kafka.common.serialization.Deserializer; | ||
| import org.apache.kafka.common.serialization.Serdes; | ||
| import org.apache.kafka.common.serialization.StringDeserializer; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
| import static org.mockito.Mockito.when; | ||
|
|
||
| public class LeftOrRightValueDeserializerTest { | ||
|
|
||
| @Test | ||
| public void shouldPassHeadersToUnderlyingDeserializer() { | ||
| final Deserializer<String> mockDeserializer = mock(StringDeserializer.class); | ||
|
|
||
| final String topic = "dummy"; | ||
| final String value = "some-string"; | ||
| final Headers headers = new RecordHeaders().add("key", "value".getBytes()); | ||
| final LeftOrRightValue<String, Object> data = LeftOrRightValue.makeLeftValue(value); | ||
| final byte[] serializedBytes = new LeftOrRightValueSerializer<>(Serdes.String().serializer(), null).serialize(topic, headers, data); | ||
|
|
||
| when(mockDeserializer.deserialize(topic, headers, value.getBytes())).thenReturn("dummy-value"); | ||
|
|
||
| final LeftOrRightValueDeserializer<String, String> testDeserializer = new LeftOrRightValueDeserializer<>(mockDeserializer, null); | ||
|
|
||
| testDeserializer.deserialize(topic, headers, serializedBytes); | ||
|
|
||
| verify(mockDeserializer).deserialize(topic, headers, value.getBytes()); | ||
| verify(mockDeserializer, never()).deserialize(topic, value.getBytes()); | ||
| } | ||
| } |
This file contains hidden or 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 |
|---|---|---|
|
|
@@ -16,34 +16,38 @@ | |
| */ | ||
| package org.apache.kafka.streams.state.internals; | ||
|
|
||
| import org.apache.kafka.common.header.Headers; | ||
| import org.apache.kafka.common.header.internals.RecordHeaders; | ||
| import org.apache.kafka.common.serialization.Serdes; | ||
| import org.apache.kafka.common.serialization.Serializer; | ||
| import org.apache.kafka.common.serialization.StringSerializer; | ||
|
|
||
| import org.junit.jupiter.api.Test; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.is; | ||
| import static org.hamcrest.Matchers.notNullValue; | ||
|
Comment on lines
27
to
29
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. @mjsax Do we use |
||
| import static org.junit.jupiter.api.Assertions.assertThrows; | ||
| import static org.mockito.Mockito.mock; | ||
| import static org.mockito.Mockito.never; | ||
| import static org.mockito.Mockito.verify; | ||
|
|
||
| public class LeftOrRightValueSerializerTest { | ||
| private static final String TOPIC = "some-topic"; | ||
|
|
||
| private static final LeftOrRightValueSerde<String, Integer> STRING_OR_INTEGER_SERDE = | ||
| new LeftOrRightValueSerde<>(Serdes.String(), Serdes.Integer()); | ||
| private static final LeftOrRightValueSerde<String, Integer> STRING_OR_INTEGER_SERDE = new LeftOrRightValueSerde<>(Serdes.String(), Serdes.Integer()); | ||
|
|
||
| @Test | ||
| public void shouldSerializeStringValue() { | ||
| final String value = "some-string"; | ||
|
|
||
| final LeftOrRightValue<String, Integer> leftOrRightValue = LeftOrRightValue.makeLeftValue(value); | ||
|
|
||
| final byte[] serialized = | ||
| STRING_OR_INTEGER_SERDE.serializer().serialize(TOPIC, leftOrRightValue); | ||
| final byte[] serialized = STRING_OR_INTEGER_SERDE.serializer().serialize(TOPIC, leftOrRightValue); | ||
|
|
||
| assertThat(serialized, is(notNullValue())); | ||
|
|
||
| final LeftOrRightValue<String, Integer> deserialized = | ||
| STRING_OR_INTEGER_SERDE.deserializer().deserialize(TOPIC, serialized); | ||
| final LeftOrRightValue<String, Integer> deserialized = STRING_OR_INTEGER_SERDE.deserializer().deserialize(TOPIC, serialized); | ||
|
|
||
| assertThat(deserialized, is(leftOrRightValue)); | ||
| } | ||
|
|
@@ -54,13 +58,11 @@ public void shouldSerializeIntegerValue() { | |
|
|
||
| final LeftOrRightValue<String, Integer> leftOrRightValue = LeftOrRightValue.makeRightValue(value); | ||
|
|
||
| final byte[] serialized = | ||
| STRING_OR_INTEGER_SERDE.serializer().serialize(TOPIC, leftOrRightValue); | ||
| final byte[] serialized = STRING_OR_INTEGER_SERDE.serializer().serialize(TOPIC, leftOrRightValue); | ||
|
|
||
| assertThat(serialized, is(notNullValue())); | ||
|
|
||
| final LeftOrRightValue<String, Integer> deserialized = | ||
| STRING_OR_INTEGER_SERDE.deserializer().deserialize(TOPIC, serialized); | ||
| final LeftOrRightValue<String, Integer> deserialized = STRING_OR_INTEGER_SERDE.deserializer().deserialize(TOPIC, serialized); | ||
|
|
||
| assertThat(deserialized, is(leftOrRightValue)); | ||
| } | ||
|
|
@@ -76,4 +78,21 @@ public void shouldThrowIfSerializeOtherValueAsNull() { | |
| assertThrows(NullPointerException.class, | ||
| () -> STRING_OR_INTEGER_SERDE.serializer().serialize(TOPIC, LeftOrRightValue.makeRightValue(null))); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldPassHeadersToUnderlyingSerializer() { | ||
| final Serializer<String> mockSerializer = mock(StringSerializer.class); | ||
|
|
||
| final String topic = "dummy"; | ||
| final String value = "some-string"; | ||
| final Headers headers = new RecordHeaders().add("key", "value".getBytes()); | ||
| final LeftOrRightValue<String, String> data = LeftOrRightValue.makeLeftValue(value); | ||
|
|
||
| final LeftOrRightValueSerializer<String, String> testSerializer = new LeftOrRightValueSerializer<>(mockSerializer, null); | ||
|
|
||
| testSerializer.serialize(topic, headers, data); | ||
|
|
||
| verify(mockSerializer).serialize(topic, headers, value); | ||
| verify(mockSerializer, never()).serialize(topic, value); | ||
| } | ||
| } | ||
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.