[
https://issues.apache.org/jira/browse/KAFKA-15143?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17933282#comment-17933282
]
Javad Saljooghi commented on KAFKA-15143:
-----------------------------------------
I tried to find a workaround until a mock for {{FixedKeyProcessor}} is added to
{{{}test-utils{}}}. However, I need to create a new {{{}FixedKeyRecord{}}},
which does not have a public constructor and is package-private. Additionally,
it does not extend the {{Record}} class, so I couldn't mock it directly.
Do you have any ideas on how to handle this? By the way, I also have a state
store (stateful punctuator) in {{{}processValues{}}}. Here's what I tried:
{code:java}
public static class MockFixedKeyProcessorContext<KForward, VForward> extends
MockProcessorContext<KForward, VForward> implements
FixedKeyProcessorContext<KForward, VForward> {
public MockFixedKeyProcessorContext(KafkaStreamsApplicationConfig
config) {super(config);}
@Override
public <K extends KForward, V extends VForward> void
forward(FixedKeyRecord<K, V> record) {
super.forward(new Record<>(record.key(), record.value(),
record.timestamp(), record.headers()));}
@Override
public <K extends KForward, V extends VForward> void
forward(FixedKeyRecord<K, V> record, String childName) {
super.forward(new Record<>(record.key(), record.value(),
record.timestamp(), record.headers()), childName);}
}
this.context = new MockFixedKeyProcessorContext<>(properties);
this.myStateStore.init(((MockProcessorContext)
this.context).getStateStoreContext(), myStateStore);
((MockProcessorContext)this.context).addStateStore(myStateStore);
Package-private constructor. Users must not construct this class directly, but
only modify records they were handed by the framework.
new FixedKeyRecord<>("key", NotificationData.newBuilder().build(), ts, new
RecordHeaders());
((MockProcessorContext) this.context).forwarded(); {code}
> MockFixedKeyProcessorContext is missing from test-utils
> -------------------------------------------------------
>
> Key: KAFKA-15143
> URL: https://issues.apache.org/jira/browse/KAFKA-15143
> Project: Kafka
> Issue Type: Bug
> Components: streams-test-utils
> Affects Versions: 3.5.0
> Reporter: Tomasz Kaszuba
> Assignee: Shashwat Pandey
> Priority: Major
> Labels: needs-kip
>
> I am trying to test a ContextualFixedKeyProcessor but it is not possible to
> call the init method from within a unit test since the MockProcessorContext
> doesn't implement
> {code:java}
> FixedKeyProcessorContext<KForward, VForward> {code}
> but only
> {code:java}
> ProcessorContext<KForward, VForward>
> {code}
> Shouldn't there also be a *MockFixedKeyProcessorContext* in the test utils?
--
This message was sent by Atlassian Jira
(v8.20.10#820010)