Uploaded image for project: 'Kafka'
  1. Kafka
  2. KAFKA-12297

Implementation of MockProducer contradicts documentation of Callback for async send

    XMLWordPrintableJSON

Details

    • Bug
    • Status: Resolved
    • Major
    • Resolution: Fixed
    • 2.7.0
    • 3.0.0
    • producer , unit tests
    • None

    Description

      In Unit tests, a MockProducer is used to imitate a real producer.

      Using the errorNext(RuntimeException e) method, it is possible to indicate failures.

      BUT: the asynchronous send method with a callback has a clear documentation of that callback interface, stating that Metadata will always be set, and never null.

      The metadata for the record that was sent (i.e. the partition and offset). An empty metadata with -1 value for all fields except for topicPartition will be returned if an error occurred.

       

      The bug is, that in MockProducer's Completion implementation the following happens:

      if (e == null)
          callback.onCompletion(metadata, null);
      else
          callback.onCompletion(null, e);

       

      Behaving against the own documentation leads to very subtle bugs: tests that implement the error condition checking metadata != null will be fine, but in real life fail horribly.

       

      A MockProducer should at all times behave exactly like the real thing and adhere to the documentation of the Callback!

      Attachments

        Issue Links

          Activity

            People

              Unassigned Unassigned
              Zordid Olaf Gottschalk
              Manikumar Manikumar
              Votes:
              0 Vote for this issue
              Watchers:
              1 Start watching this issue

              Dates

                Created:
                Updated:
                Resolved: