-
Notifications
You must be signed in to change notification settings - Fork 15.4k
HOTFIX: Fix wrong setting of Serde in MeteredTimestampWindowStore
#6808
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 all commits
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 |
|---|---|---|
|
|
@@ -24,7 +24,9 @@ | |
| import org.apache.kafka.common.utils.LogContext; | ||
| import org.apache.kafka.common.utils.MockTime; | ||
| import org.apache.kafka.streams.StreamsConfig; | ||
| import org.apache.kafka.streams.errors.StreamsException; | ||
| import org.apache.kafka.streams.processor.internals.metrics.StreamsMetricsImpl; | ||
| import org.apache.kafka.streams.state.ValueAndTimestamp; | ||
| import org.apache.kafka.streams.state.WindowStore; | ||
| import org.apache.kafka.test.InternalMockProcessorContext; | ||
| import org.apache.kafka.test.NoOpRecordCollector; | ||
|
|
@@ -35,6 +37,7 @@ | |
| import org.junit.Test; | ||
|
|
||
| import static org.junit.Assert.assertNull; | ||
| import static org.junit.Assert.fail; | ||
|
|
||
| public class MeteredTimestampWindowStoreTest { | ||
| private InternalMockProcessorContext context; | ||
|
|
@@ -89,4 +92,51 @@ public void shouldNotExceptionIfFetchReturnsNull() { | |
| assertNull(store.fetch("a", 0)); | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotThrowExceptionIfSerdesCorrectlySetFromProcessorContext() { | ||
| EasyMock.expect(innerStoreMock.name()).andStubReturn("mocked-store"); | ||
| EasyMock.replay(innerStoreMock); | ||
| final MeteredTimestampedWindowStore<String, Long> store = new MeteredTimestampedWindowStore<>( | ||
| innerStoreMock, | ||
| 10L, // any size | ||
| "scope", | ||
| new MockTime(), | ||
| null, | ||
| null | ||
| ); | ||
| store.init(context, innerStoreMock); | ||
|
|
||
| try { | ||
| store.put("key", ValueAndTimestamp.make(42L, 60000)); | ||
| } catch (final StreamsException exception) { | ||
|
Member
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. I don't understand this ? Why do we catch
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. To distinguish between a test failure and a test that is terminated by an exception. If a |
||
| if (exception.getCause() instanceof ClassCastException) { | ||
|
Member
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. nit: IMHO we should just get rid of the
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. I will add an
Member
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. I agree with @bbejeck (compare my other comment about "why we catch
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. OK, I see that the tests fail in any case when an exception is thrown. However, I still think that catching If you both still do not agree, I will remove the |
||
| fail("Serdes are not correctly set from processor context."); | ||
| } | ||
| throw exception; | ||
| } | ||
| } | ||
|
|
||
| @Test | ||
| public void shouldNotThrowExceptionIfSerdesCorrectlySetFromConstructorParameters() { | ||
| EasyMock.expect(innerStoreMock.name()).andStubReturn("mocked-store"); | ||
| EasyMock.replay(innerStoreMock); | ||
| final MeteredTimestampedWindowStore<String, Long> store = new MeteredTimestampedWindowStore<>( | ||
| innerStoreMock, | ||
| 10L, // any size | ||
| "scope", | ||
| new MockTime(), | ||
| Serdes.String(), | ||
| new ValueAndTimestampSerde<>(Serdes.Long()) | ||
| ); | ||
| store.init(context, innerStoreMock); | ||
|
|
||
| try { | ||
| store.put("key", ValueAndTimestamp.make(42L, 60000)); | ||
| } catch (final StreamsException exception) { | ||
|
Member
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. As above |
||
| if (exception.getCause() instanceof ClassCastException) { | ||
|
Member
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. same as above |
||
| fail("Serdes are not correctly set from constructor parameters."); | ||
| } | ||
| throw exception; | ||
| } | ||
| } | ||
| } | ||
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.
Can we add those test for
MeteredTimestampedKeyValueStoreTest, too. We had the same bug inMeteredTimestampedKeyValueStoreand fixed it "on the side" but never added a test...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.
Will open a separate PR for that.