-
Notifications
You must be signed in to change notification settings - Fork 15.4k
MINOR: improve error message for Serde type miss match #6801
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
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -19,11 +19,16 @@ | |
| import org.apache.kafka.common.serialization.Serdes; | ||
| import org.apache.kafka.common.utils.Bytes; | ||
| import org.apache.kafka.streams.errors.StreamsException; | ||
| import org.apache.kafka.streams.state.internals.ValueAndTimestampSerde; | ||
| import org.junit.Assert; | ||
| import org.junit.Test; | ||
|
|
||
| import java.nio.ByteBuffer; | ||
|
|
||
| import static org.hamcrest.MatcherAssert.assertThat; | ||
| import static org.hamcrest.Matchers.equalTo; | ||
| import static org.junit.Assert.assertThrows; | ||
|
|
||
| @SuppressWarnings("unchecked") | ||
| public class StateSerdesTest { | ||
|
|
||
|
|
@@ -88,20 +93,47 @@ public void shouldThrowIfValueClassIsNull() { | |
| new StateSerdes<>("anyName", Serdes.ByteArray(), null); | ||
| } | ||
|
|
||
| @Test(expected = StreamsException.class) | ||
| @Test | ||
| public void shouldThrowIfIncompatibleSerdeForValue() throws ClassNotFoundException { | ||
| final Class myClass = Class.forName("java.lang.String"); | ||
| final StateSerdes<Object, Object> stateSerdes = new StateSerdes<Object, Object>("anyName", Serdes.serdeFrom(myClass), Serdes.serdeFrom(myClass)); | ||
| final Integer myInt = 123; | ||
| stateSerdes.rawValue(myInt); | ||
| final Exception e = assertThrows(StreamsException.class, () -> stateSerdes.rawValue(myInt)); | ||
| assertThat( | ||
| e.getMessage(), | ||
| equalTo( | ||
| "A serializer (value: org.apache.kafka.common.serialization.StringSerializer) " + | ||
|
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. Could we reuse the error message or the entire template?
Member
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. We could reuse for this and the second "value" test, but not for the "key" test. Don't see big value is sharing though. |
||
| "is not compatible to the actual value type (value type: java.lang.Integer). " + | ||
| "Change the default Serdes in StreamConfig or provide correct Serdes via method parameters.")); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldSkipValueAndTimestampeInformationForErrorOnTimestampAndValueSerialization() throws ClassNotFoundException { | ||
| final Class myClass = Class.forName("java.lang.String"); | ||
| final StateSerdes<Object, Object> stateSerdes = | ||
| new StateSerdes<Object, Object>("anyName", Serdes.serdeFrom(myClass), new ValueAndTimestampSerde(Serdes.serdeFrom(myClass))); | ||
| final Integer myInt = 123; | ||
| final Exception e = assertThrows(StreamsException.class, () -> stateSerdes.rawValue(ValueAndTimestamp.make(myInt, 0L))); | ||
| assertThat( | ||
| e.getMessage(), | ||
| equalTo( | ||
| "A serializer (value: org.apache.kafka.common.serialization.StringSerializer) " + | ||
| "is not compatible to the actual value type (value type: java.lang.Integer). " + | ||
| "Change the default Serdes in StreamConfig or provide correct Serdes via method parameters.")); | ||
| } | ||
|
|
||
| @Test(expected = StreamsException.class) | ||
| @Test | ||
| public void shouldThrowIfIncompatibleSerdeForKey() throws ClassNotFoundException { | ||
| final Class myClass = Class.forName("java.lang.String"); | ||
| final StateSerdes<Object, Object> stateSerdes = new StateSerdes<Object, Object>("anyName", Serdes.serdeFrom(myClass), Serdes.serdeFrom(myClass)); | ||
| final Integer myInt = 123; | ||
| stateSerdes.rawKey(myInt); | ||
| final Exception e = assertThrows(StreamsException.class, () -> stateSerdes.rawKey(myInt)); | ||
| assertThat( | ||
| e.getMessage(), | ||
| equalTo( | ||
| "A serializer (key: org.apache.kafka.common.serialization.StringSerializer) " + | ||
| "is not compatible to the actual key type (key type: java.lang.Integer). " + | ||
| "Change the default Serdes in StreamConfig or provide correct Serdes via method parameters.")); | ||
| } | ||
|
|
||
| } | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
nit: I felt we can remove the
valuein(value: %s)below?