[ 
https://issues.apache.org/jira/browse/KAFKA-10503?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Matthias J. Sax reassigned KAFKA-10503:
---------------------------------------

    Assignee: Gonzalo Muñoz Fernández

> 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
>   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.3.4#803005)

Reply via email to