Details
Description
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 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:
@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) {} }
Currently, for obtaining the ClassCastException is needed to define the topic into a partition:
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());
Attachments
Issue Links
- links to