[ 
https://issues.apache.org/jira/browse/KAFKA-10503?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17454673#comment-17454673
 ] 

Dennis Hunziker edited comment on KAFKA-10503 at 12/8/21, 2:58 AM:
-------------------------------------------------------------------

[~gmunozfe] This change did break our tests. When using the no-arg constructor 
the serializers are null but now that they're referenced in any case we'll just 
get an NPE. Was that on purpose? Shouldn't the change made here only be applied 
if the serializers aren't null?

Happy to create a separate ticket and fix if you agree.


was (Author: JIRAUSER281343):
This change did break our tests. When using the no-arg constructor the 
serializers are null but now that they're referenced in any case we'll just get 
an NPE. Was that on purpose? Shouldn't the change made here only be applied if 
the serializers aren't null?

Happy to create a separate ticket and fix if you agree.

> MockProducer doesn't throw ClassCastException when no partition for topic
> -------------------------------------------------------------------------
>
>                 Key: KAFKA-10503
>                 URL: https://issues.apache.org/jira/browse/KAFKA-10503
>             Project: Kafka
>          Issue Type: Improvement
>          Components: clients, producer 
>    Affects Versions: 2.6.0
>            Reporter: Gonzalo Muñoz Fernández
>            Assignee: Gonzalo Muñoz Fernández
>            Priority: Minor
>              Labels: mock, producer
>             Fix For: 2.7.0
>
>   Original Estimate: 1h
>  Remaining Estimate: 1h
>
> Though {{MockProducer}} admits serializers in its constructors, it doesn't 
> check during {{send}} method that those serializers are the proper ones to 
> serialize key/value included into the {{ProducerRecord}}.
> [This 
> check|https://github.com/apache/kafka/blob/trunk/clients/src/main/java/org/apache/kafka/clients/producer/MockProducer.java#L499-L500]
>  is only done if there is a partition assigned for that topic.
> It would be an enhancement if these serialize methods were also invoked in 
> simple scenarios, where no partition is assigned to a topic.
> eg:
> {code:java}
>     @Test
>     public void shouldThrowClassCastException() {
>         MockProducer<Integer, String> producer = new MockProducer<>(true, new 
> IntegerSerializer(), new StringSerializer());
>         ProducerRecord record = new ProducerRecord(TOPIC, "key1", "value1");
>         try {
>             producer.send(record);
>             fail("Should have thrown ClassCastException because record cannot 
> be casted with serializers");
>         } catch (ClassCastException e) {}
>     }
> {code}
> Currently, for obtaining the ClassCastException is needed to define the topic 
> into a partition:
> {code:java}
> PartitionInfo partitionInfo = new PartitionInfo(TOPIC, 0, null, null, null);
> Cluster cluster = new Cluster(null, emptyList(), asList(partitionInfo),
>                                   emptySet(), emptySet());
>  producer = new MockProducer(cluster, 
>                                 true, 
>                                 new DefaultPartitioner(), 
>                                 new IntegerSerializer(), 
>                                 new StringSerializer());
> {code}



--
This message was sent by Atlassian Jira
(v8.20.1#820001)

Reply via email to